// JavaScript Document
$(document).ready(function() {
	$("#topmenu a").click(function() {
		if($(this).html()=="Services") {
			if($("#topmenuwrapper").css("margin-top")=="-35px") { return true; }
			$(".mlnk").css("color","");
			$(this).css("color","#FFFFFF");
			chgSubmen("Services");
			$("#topmenuwrapper").animate({ marginTop:"-35px" }, {
						 duration: 500,
						 complete: function() { window.location="/Services/"; }
			});  
			return false;
		} else if($(this).html()=="Contact") {
			if($("#topmenuwrapper").css("margin-top")=="-35px") { return true; }
			$(".mlnk").css("color","");
			$(this).css("color","#FFFFFF");
			chgSubmen("Contact");
			$("#topmenuwrapper").animate({ marginTop:"-35px" }, {
						 duration: 500,
						 complete: function() { window.location="/Contact/"; }
			});   
			return false;
		} else if($(this).html()=="Home") {
			if($("#topmenuwrapper").css("margin-top")=="-10px") { return true; }
			$(".mlnk").css("color","");
			$("#topmenuwrapper").animate({ marginTop: "-10px" }, { 
						duration: 500, 
						complete: function(){ window.location="/"; }
            }); 
			return false;
		} else if($(this).html()=="Cars") {
			if($("#topmenuwrapper").css("margin-top")=="-10px") { return true; }
			$(".mlnk").css("color","");
			$("#topmenuwrapper").animate({ marginTop: "-10px" }, { 
						duration: 500, 
						complete: function(){ window.location="/Cars"; }
            }); 
			return false;
		}
	});
	
	$("#topmenu a:contains('Services'),#topmenu a:contains('Contact')").hoverIntent({
		sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
     	interval: 100, // number = milliseconds for onMouseOver polling interval    
    	over: showSubMen, // function = onMouseOver callback (REQUIRED)    
     	timeout: 1000, // number = milliseconds delay before onMouseOut    
     	out: dummy // function = onMouseOut callback (REQUIRED)    						
	});

	//$("#topmenu a:contains('Home'),#topmenu a:contains('Cars'), #madhatter, #smadhatter.carsh").hoverIntent({
	$("#madhatter, #smadhatter.carsh").hoverIntent({																										  
		sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
     	interval: 100, // number = milliseconds for onMouseOver polling interval    
    	over: hideSubMen, // function = onMouseOver callback (REQUIRED)    
     	timeout: 1000, // number = milliseconds delay before onMouseOut    
     	out: dummy // function = onMouseOut callback (REQUIRED)    						
	});
	
	function showSubMen() {
			$(".mlnk").css("color","");
			$(this).css("color","#FFFFFF");
			chgSubmen($(this).text());
			if($("#topmenuwrapper").css("margin-top")!="-35px") {
				$("#topmenuwrapper").animate({ marginTop:"-35px" }, 500);
			}
	}
	
	function hideSubMen() {
			$(".mlnk").css("color","");
			if($("#topmenuwrapper").css("margin-top")!="-10px") {
				$("#topmenuwrapper").animate({ marginTop: "-10px" }, 500);	
			}
	}
	
	function dummy() {
		//dummy
	} 
	
	function chgSubmen(pg) {
		if(pg=="Services") {
			if($("#SMServices").css("display")=="none") {
				$("#SMContact").css("display","none");
				$("#SMServices").fadeIn("normal");
			}
		} else if(pg=="Contact") {
			if($("#SMContact").css("display")=="none") {
				$("#SMServices").css("display","none");
				$("#SMContact").fadeIn("normal");
			}			
		}
		
	}
});