
$(document).ready(function() {
	
	$("#form").hide();


	// Bringing in the content dynamically

	$( "#nav li.ajax a" ).click( function ( event ) {
	
		event.preventDefault();   
		
		if ( !$(this).is(".current") ) 	{      
		       
			var url = $( this ).attr( "href" );
		
			$( "#nav a" ).removeClass( "current" );
		
			$( this ).addClass( "current" );
		   
			$( "#content-container" ).fadeOut( 'slow', function() {
			
				$("#content-container")
				.load( url + " .content" )
				.delay(1200)
				.fadeIn(500)
			});
			
		};
	
	});
	
	
	
	$( "#thumbs a" ).live('click', function(event) {
	
		event.preventDefault();  
		
		if ( !$(this).is(".current") ) 	{     
		       
			var url = $( this ).attr( "href" );
			
			$( "#thumbs a" ).removeClass( "current" );
			
			$( this ).addClass( "current" );
			   
			$( "#large" ).fadeOut( 'slow', function() {
			
				$("#large")
				.load( url + " #large" )
				.delay(1200)
				.fadeIn(500);
					
			});
		};
		
	});

	
	// Smoother scroll down to the locator
	
	
	$(".locator-link").live('click', function(event) {
	
		$("html, body").animate({
		
			scrollTop: $("#footer-container").offset().top
				
		}, 1000);
		
		event.preventDefault();
		
		$("#form").fadeIn();

	
	});
	
	
	// Bring in the locator results
	
	$("form#locator").submit(function(event){
 		event.preventDefault();
	 
 		$.post("/pioneer/dealer-locator.asp", {zip: $("#zip").val(),state: $("#state").val(),country: $("#country").val() }, function(data) {
 		
  			$("#results").html(data);
  			
  			$('html, body').animate({
  			
				scrollTop: $("#footer").offset().top
				
			}, 2000);
			
  			$("#results").delay(500).fadeIn();
  			
		});
		
	});
	
	
	$("textarea, input[type=text]").focus(function(){
	// Check for the change
		if(this.value == this.defaultValue){
			this.select();
		}

	});
	
});


function checkState() {
	if ($("#country").val() != "US") {
		$("#othersearch").hide();
 		$.post("/pioneer/dealer-locator.asp", {country: $("#country").val() }, function(data) {
 			$("#results").html(data);
  			$('html, body').animate({
				scrollTop: $("#footer").offset().top
			}, 2000);
  			$("#results").delay(500).fadeIn();
		});
		
	} else {
		$("#othersearch").show();
	}
}
function showState() {
	if ($("#state").val() != "") {
 		$.post("/pioneer/dealer-locator.asp", {state: $("#state").val() }, function(data) {
 			$("#results").html(data);
  			$('html, body').animate({
				scrollTop: $("#footer").offset().top
			}, 2000);
  			$("#results").delay(500).fadeIn();
		});
	}
}


