// JavaScript Document

$(document).ready(function() {
						   
	// create automated image rollovers

	$('.mainnav img').each(function() {    // pulls all <img> tags inside div class "mainnav"
	
		var imgFile = $(this).attr('src');    // pulls each image's "src" attribute in turn
		
		var preloadImage = new Image();    // creates preload function
		
		preloadImage.src = imgFile.replace(/1.png/, '2.png');    // uses "replace" function to make, e.g., "home2.jpg" out of "home.jpg"
		
		$(this).hover(    
		
			function() {    // jQuery "hover" function takes two arguments, first "mouseover" and then "mouseout"
			
				$(this).attr('src', preloadImage.src);
				
			},
			
			function() {
			
				$(this).attr('src', imgFile);
		
			}
		
		); // end "hover"
	
	}); // end "each"
	
	
	
	$('#same_as_personal').toggle(
		function () {
			
			$('#billing_name').val($('#name').val());
			$('#billing_address').val($('#address').val());
			$('#billing_city').val($('#city').val());
			$('#billing_state').val($('#state').val());
			$('#billing_zip').val($('#zip').val());
			$('#billing_phone1').val($('#phone1').val());
			$('#billing_phone2').val($('#phone2').val());
			$('#billing_email').val($('#email').val());
			$('#billing_fax').val($('#fax').val());
			return true;
		},
		
		function() {
			$('#billing_name').val('');
			$('#billing_address').val('');
			$('#billing_city').val('');
			$('#billing_state').val('');
			$('#billing_zip').val('');
			$('#billing_phone1').val('');
			$('#billing_phone2').val('');
			$('#billing_email').val('');
			$('#billing_fax').val('');
			return true;
		}); // end "toggle"
	
	$('#select_piano_form').hide();
	
	$('#select_piano').toggle(
		function() {
			$('#select_piano_form').slideDown();
			$('#select_piano').hide();
		},
		
		function() {
			$('#select_piano_form').slideUp();
			$('#select_piano').show();
		}); // end "toggle"
	


	
		
	
	
	// validate 'terms and conditions
	
	$('#piano_form').submit(function() {
		
		if($('#read_terms').val() == '') {
				
			alert('You must agree to the Terms and Conditions to continue.');
			
			return false;
			
		}
		
	}); // end 'submit'
	
	

}); // end "ready"