$(function(){

$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}

//nav
var url = location.href;

//test server
//var path = "http://localhost/PicoCal/public_html/";

var path = "http://www.picocal.com/";

if(url == path + "index.php" || url == path){	//home
	$("#home").css('border-top', 'solid 2px #dc611b');
	$("#home").css('margin-top', '-1px');
}
else if(url == path + "prod_serv.php" || url == path + "thermal_probes.php" || url == path + "high_speed_probes.php" || url == path + "frictional_probes.php" || url == path + "modules.php" || url == path + "speciality_probes.php" || url == path + "services.php"){								//products/services
	$("#prod").css('border-top', 'solid 2px #dc611b');
	$("#prod").css('margin-top', '-1px');
}
else if(url == path + "press.php" || url == path + "patent.php" || url == path + "audio_video.php" || url == path + "tech_notes.php"){		//tech notes
	
	if(url == path + "press.php"){
		$("#press").css('border-left', 'solid 2px #dc611b');
		$("#press").css('margin-left', '-1px');
	}
	else if(url == path + "audio_video.php"){
		$("#audio_video").css('border-left', 'solid 2px #dc611b');
		$("#audio_video").css('margin-left', '-1px');
	}
	else if(url == path + "tech_notes.php"){
		$("#tech_notes").css('border-left', 'solid 2px #dc611b');
		$("#tech_notes").css('margin-left', '-1px');
	}
	else if(url == path + "patent.php"){
		$("#patent").css('border-left', 'solid 2px #dc611b');
		$("#patent").css('margin-left', '-1px');
	}
	
	$("#news").css('border-top', 'solid 2px #dc611b');
	$("#news").css('margin-top', '-1px');
}
else if(url == path + "about.php"){				//about us
	$("#abt").css('border-top', 'solid 2px #dc611b');
	$("#abt").css('margin-top', '-1px');
} 
else if(url == path + "contact.php" || url == path + "contact.php?msg=yes"){			//contact us
	$("#contact").css('border-top', 'solid 2px #dc611b');
	$("#contact").css('margin-top', '-1px');
}

$("#news").click(function(event) { 
	event.preventDefault(); 
});

var config = {
    sensitivity: 4,		// how much mouse can more till interval called
    interval: 120,	 	// over 
    timeout: 0, 		// out
    over: function() {
        $(this).parent().find("ul.subnav").slideDown('fast').show();
		$(this).addClass("subhover"); 
    },
    out: function() { 
		$(this).parent().find("ul.subnav").slideUp('slow'); 
    	$(this).removeClass("subhover"); 
	}     
}
$("#news_li").hoverIntent(config);  


});//end jquery
