var swiss = new function(){
	this.onReady = function() { 
		/*
			Rollover images.
			Usage:
			1) Add class="rollover" to the anchor surrounding any rollover images
			2) Add a rollover image to the same folder as the original, named with the suffix "_on"
		*/
		// Preload
		var rolloverImages = $('.rollover');
		for(var i = 0; i < rolloverImages.length; i++){
			var pic = new Image(1,1);
			pic.src = $('img', rolloverImages[i]).attr("src").split(".gif").join("_on.gif");
			pic.src = $('img', rolloverImages[i]).attr("src").split(".jpg").join("_on.jpg");
			pic.src = $('img', rolloverImages[i]).attr("src").split(".png").join("_on.png");
		}
		
		// Add hover functions
		$(".rollover").hover(function() {
			$('img', this).attr("src", $('img', this).attr("src").split(".gif").join("_on.gif"));
			$('img', this).attr("src", $('img', this).attr("src").split(".jpg").join("_on.jpg"));
			$('img', this).attr("src", $('img', this).attr("src").split(".png").join("_on.png"));
		}, function() {
			$('img', this).attr("src", $('img', this).attr("src").split("_on.gif").join(".gif"));
			$('img', this).attr("src", $('img', this).attr("src").split("_on.jpg").join(".jpg"));
			$('img', this).attr("src", $('img', this).attr("src").split("_on.png").join(".png"));
		});
		
		
		/*
			Form value blanker and repopulater.
			Only affects inputs with the values in defaultFormValues so as to not overwrite browser saved values
		*/
		this.formValue = "";
		this.defaultFormValues = {'Username':'', 'Password':'', 'Email':'', 'Zip':'', 'Enter zip / postal':'', 'Search':''}
		$('input[type="text"]').focus(function(){
			if( $(this).attr('value') in swiss.defaultFormValues){
				swiss.formValue = $(this).attr('value');
				$(this).attr('value', "");
				$('input[type="text"]').blur(function(){
					if( $(this).attr('value') == "" ){
						$(this).attr('value', swiss.formValue);
					};
				});
			};
		});
		
		
		/*
			Map it panel.
			Initially hidden in CSS using .js class
		*/
		$('#navMapIt').click(function(){
			$('#navMapIt').attr('class', 'floatPanel');
			$('#navMapItPanel').css('display', 'block');
			$('#navMapIt img').attr("src", $('#navMapIt img').attr("src").split(".png").join("_on.png"));
			$('body').click(function(){
				$('#navMapIt').removeAttr('class');
				$('#navMapItPanel').css('display', 'none');
				$('#navMapIt img').attr("src", $('#navMapIt img').attr("src").split("_on.png").join(".png"));
			});
			return false;
		});
		$('#navMapItPanel').click(function(e){
			var event = e || window.event;
	
			if (event.stopPropagation) {
				event.stopPropagation();
			} else {
				event.cancelBubble = true;
			} 
			//return false;
		});
		
		
		/*
			Fix PNGs in IE6.
			Usage: http://jquery.andreaseberhard.de/pngFix/
		*/
		$(document).pngFix();
		
		this.setDriverPosition();
	}
	
	/*
		Remove default styling from banner and resize image to be full screen width
	*/
	this.setBannerWidth = function(){
		$('.bannerBG').css('left', 0);
		$('.bannerBG img').css('position', 'static');
		var bannerWidth = $('body').outerWidth(true);
		if( bannerWidth < 960){ bannerWidth = 960}
		$('.bannerBG img').css('width', bannerWidth);
	}
	
	/*
		Moved driver tabs based on page width
	*/
	this.setDriverPosition = function(){
		if ( $('body').outerWidth(true) < 1080 ){
			$('#section_drivers').attr('class', 'section_drivers_shifted');
			//console.log($('#section_drivers img').attr('src').match(/_small/));
			if ( !$('#section_drivers img').attr('src').match(/_small/)){
				$('#section_drivers img').attr("src", $('#section_drivers img').attr("src").split(".gif").join("_small.gif"));
			}
		} else {
			$('#section_drivers').attr('class', 'section_drivers');
			$('#section_drivers img').attr("src", $('#section_drivers img').attr("src").split("_small.gif").join(".gif"));
		}
	}
	
	/*
		Set up search panel tabs
	*/
	this.locatorInit = function(){
		$('#tabs li a').click(function(){
			//reset tab
			$('#tabs li a').removeClass('active');
			//reset content
			$('#tab-content .tab-content').hide();
			//set tab
			$(this).addClass('active');
			//set content
			var sec = $(this).attr('href');
			$('#tab-content ' + sec).show();
			Cufon.refresh();
			return false;
		});
		$('#link-online').click(function(){
			$('#tabs li#online a').click();
			return false;
		});
	}
	
	/*
		Set up results panel tabs
	*/
	this.locatorResultsInit = function(){
		$('#resultsList li a').click(function(){
			
			// Hide both tabs
			$('#resultsStores').css('display', 'none');
			$('#resultsAlso').css('display', 'none');
			
			//reset tab
			$('#resultsList li a').removeClass('active');
			//set tab
			$(this).addClass('active');
			
			// Set up newly shown tab
			var sec = $(this).attr('href');
			$(sec).show();
			Cufon.refresh();
			return false;
		});
	}
}

// "js" css class added to html element
if (typeof document.documentElement.className == "string") {
    document.documentElement.className += " js";
} else {
    document.documentElement.className = "js";
}

$(function(){
	swiss.onReady();
});

$(window).resize(function() {
	swiss.setBannerWidth();
	swiss.setDriverPosition();
});

Cufon.replace('.customFontNormal', { fontFamily: 'Archer Book' });
Cufon.replace('.customFontMedium', { fontFamily: 'Archer Medium' });

function copyToClipboard(s) {
    if( window.clipboardData && clipboardData.setData) {
        clipboardData.setData("Text", s);
    } else {
        alert("Method not supported");
    }
    return false;
}
