var timer;
var touchedName=false;
var touchedAddress=false;
var touchedSubject=false;
var touchedMessage=false;

function validateEmail(elementValue){
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	return emailPattern.test(elementValue);
}

jQuery.preloadImages = function()
{
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", arguments[i]);
	}
}

function clearSubs()
{
	$("#aboutDrop").css("display","none"); 
	$("#galleryDrop").css("display","none"); 
	
}

$(document).ready(function(){
	$("#contactForm").submit(function(e){
		if (!touchedName || !touchedAddress || !touchedSubject || !touchedMessage)
		{
			e.preventDefault();
			alert("Please fill all the contact fields before sending an email.");
		}
		if (!validateEmail($("#emailAddress").val()))
		{
			e.preventDefault();
			alert("Please enter a valid email address.");
		}
	});
	$("#emailName").focus(function(){
		if (!touchedName)
		{
			$("#emailName").val("");
			$("#emailName").css("font-style","normal");
			$("#emailName").css("color","#000000");
			touchedName = true;
		}
	});
	$("#emailAddress").focus(function(){
		if (!touchedAddress)
		{
			$("#emailAddress").val("");
			$("#emailAddress").css("font-style","normal");
			$("#emailAddress").css("color","#000000");
			touchedAddress = true;
		}
	});
	$("#emailSubject").focus(function(){
		if (!touchedSubject)
		{
			$("#emailSubject").val("");
			$("#emailSubject").css("font-style","normal");
			$("#emailSubject").css("color","#000000");
			touchedSubject = true;
		}
	});
	$("#emailMessage").focus(function(){
		if (!touchedMessage)
		{
			$("#emailMessage").val("");
			$("#emailMessage").css("font-style","normal");
			$("#emailMessage").css("color","#000000");
			touchedMessage = true;
		}
	});
	
	
	$(".leftNavRental").css("opacity","0");
    $(".leftNavRental").mouseover(function(){
    	$(this).fadeTo( 100, .5);
    });
    $(".leftNavRental").mouseout(function(){
    	$(this).fadeTo( 200, 0);
    });

	
	$("#rentalProdLink").hover(function(e){
		$("#rentalProdLink").css("backgroundColor","#8b8b8c");
	},
	function(e){
		$("#rentalProdLink").css("backgroundColor","#58595B");
	});
	$("#rentalProdLink").click(function(e){
		e.preventDefault();
		window.location='index_new.php?page=products_landing';
	});
	
	$(".leftNav").mouseover(function(e){
		$(this).css("backgroundColor","#bbbcc0");
	});
	$(".leftNav").mouseout(function(e){
		$(this).css("backgroundColor","#5b5e52");
	});
	/*$("#leftNav1").click(function(e){
		e.preventDefault();
		window.open("technology.html","Window1","width=500,height=500,location=no,scrollbars=yes");
	});*/
	$("#leftNav2").click(function(e){
		e.preventDefault();
		window.open("http://www.merlo.it/e_news/ultime.htm","NewWindow");
	});
	$("#leftNav3").click(function(e){
		window.location="index_new.php?page=safety";
	});
	$("#topAbout").mouseover(function(e){
		$(this).append("<div style='position:absolute;'>Overview<br />Awards</div>");
		alert("hi");
	});
	$("#homeLink").mouseover(function(e){
		$("#homeImage").css("display","none");
	});
	$("#homeLink").mouseout(function(e){
		$("#homeImage").css("display","");
	});
	
	/* MAIN MENU STUFF */
	$("#menu01").hover(
		function(){	clearSubs(); $("#menu01").attr("src","images/new/menu/01_h.png"); },
		function(){	$("#menu01").attr("src","images/new/menu/01.png"); }
	);
	$("#menu02").hover(
		function(){	
			clearSubs(); 
			$("#menu02").attr("src","images/new/menu/02_h.png"); 
			$("#aboutDrop").css("display",""); 
			
		},
		function(){	
			$("#menu02").attr("src","images/new/menu/02.png"); 
		}
	);
	$("#menu03").hover(
		function(){	clearSubs(); $("#menu03").attr("src","images/new/menu/03_h.png"); },
		function(){	$("#menu03").attr("src","images/new/menu/03.png"); }
	);
	$("#menu04").hover(
		function(){	clearSubs(); $("#menu04").attr("src","images/new/menu/04_h.png"); },
		function(){	$("#menu04").attr("src","images/new/menu/04.png"); }
	);
	$("#menu05").hover(
		function(){	clearSubs(); $("#menu05").attr("src","images/new/menu/05_h.png"); },
		function(){	$("#menu05").attr("src","images/new/menu/05.png"); }
	);
	$("#menuUsed").hover(
		function(){	clearSubs(); $("#menuUsed").attr("src","images/new/menu/menu_used_h.jpg"); },
		function(){	$("#menuUsed").attr("src","images/new/menu/menu_used.jpg"); }
	);
	$("#menu06").hover(
		function(){	clearSubs(); $("#menu06").attr("src","images/new/menu/06_h.png"); },
		function(){	$("#menu06").attr("src","images/new/menu/06.png"); }
	);
	$("#menu07").hover(
		function(){	
			clearSubs(); 
			$("#menu07").attr("src","images/new/menu/07_h.png"); 
			$("#galleryDrop").css("display",""); 
		},
		function(){	$("#menu07").attr("src","images/new/menu/07.png"); }
	);
	$("#menu08").hover(
		function(){	clearSubs(); $("#menu08").attr("src","images/new/menu/08_h.png"); },
		function(){	$("#menu08").attr("src","images/new/menu/08.png"); }
	);
	$("#menu09").hover(
		function(){	clearSubs(); $("#menu09").attr("src","images/new/menu/09_h.png"); },
		function(){	$("#menu09").attr("src","images/new/menu/09.png"); }
	);
	
	$("#menu0201").hover(
		function(){	$("#menu0201").attr("src","images/new/menu/02_01_h.png"); },
		function(){	$("#menu0201").attr("src","images/new/menu/02_01.png"); }
	);
	$("#menu0202").hover(
		function(){	$("#menu0202").attr("src","images/new/menu/02_02_h.png"); },
		function(){	$("#menu0202").attr("src","images/new/menu/02_02.png"); }
	);
	
	$("#menu0701").hover(
		function(){	$("#menu0701").attr("src","images/new/menu/07_01_h.png"); },
		function(){	$("#menu0701").attr("src","images/new/menu/07_01.png"); }
	);
	$("#menu0702").hover(
		function(){	$("#menu0702").attr("src","images/new/menu/07_02_h.png"); },
		function(){	$("#menu0702").attr("src","images/new/menu/07_02.png"); }
	);
	
	$.preloadImages("images/new/menu/01_h.png","images/new/menu/02_h.png","images/new/menu/03_h.png","images/new/menu/04_h.png","images/new/menu/05_h.png","images/new/menu/06_h.png","images/new/menu/07_h.png","images/new/menu/08_h.png","images/new/menu/09_h.png");
	$.preloadImages("images/new/menu/01.png","images/new/menu/02.png","images/new/menu/03.png","images/new/menu/04.png","images/new/menu/05.png","images/new/menu/06.png","images/new/menu/07.png","images/new/menu/08.png","images/new/menu/09.png");
	/* secondary buttons */
	$.preloadImages("images/new/menu/02_01.png","images/new/menu/02_01_h.png","images/new/menu/02_02.png","images/new/menu/02_02_h.png");
	$.preloadImages("images/new/menu/07_01.png","images/new/menu/07_01_h.png","images/new/menu/07_02.png","images/new/menu/07_02_h.png");
	
});
