/*
---------------------------------------------
* jQuery-Plugin "Equal Width Navigation - DropDown"
* Version: 1.0, 1.1.2011
* by Lazarev Alexsandr, regatagroup@gmail.com
* Daronet Dev Group
---------------------------------------------
*/

/*HoverIntent*/
(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)}})(jQuery);

/*Start navigation*/
Array.prototype.sum = function() {
		 return (! this.length) ? 0 : this.slice(1).sum() +
			((typeof this[0] == 'number') ? this[0] : 0);
};

function menu() {
	 var nav = $('ul.nav'),
		nav_item_height = 0,
		numMenuItems = $('> li', nav).size(),
		totalMenuItemWidth = 0,
		menuWidthRemainder = 0,
		wrapperWidth = 985,
		maxNavItemWidth = 150,
		priNavItems = new Array();
		
		//need for fast calculation render
		nav.show();
		
	 /* First, determine the total width of each item in the navigation. */
	 $('> li', nav).each(function (i) {
		  totalMenuItemWidth += $(this).width();
		  priNavItems.push(($(this).width() > maxNavItemWidth) ? maxNavItemWidth : $(this).width());
	 });

 	/* Primary navigation items (combined) are less width than the
	 wrapper. */
 	if(totalMenuItemWidth < wrapperWidth) {
		  menuWidthRemainder = wrapperWidth - totalMenuItemWidth;

		  $('> li', nav).each(function() {
			   var tmp_width = $(this).width();
			   $(this).width(tmp_width + parseInt(menuWidthRemainder / numMenuItems));
		  });																										
				
		  tmp_width = $('> li:first', nav).width();
	  	$('> li:first', nav).width(tmp_width + (menuWidthRemainder % numMenuItems));
	 }

}

$(document).ready(function(){
		menu();
		$('ul.nav li').hoverIntent({
			interval: 100, // milliseconds delay before onMouseOver
			over: drops_show, 
			timeout: 200, // milliseconds delay before onMouseOut
			out: drops_hide
		});
		  
		function drops_show(){ $(this).addClass('hover'); }
        function drops_hide(){ $(this).removeClass('hover'); } 				
});

$(window).resize(function(){
		menu();	
});		



$(document).ready(function(){
		var str=location.href.toLowerCase();
		$("ul.nav li a").each(function() {
				if (str.indexOf(this.href.toLowerCase()) > -1) {
				 $("li.active").removeClass("active");
				$(this).parent().addClass("active");
				$('li.active').parent().parent().addClass("active");
				};
		
				//alert($("ul.nav li.active").text());
					
		
		 });
})

