/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:10,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 p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){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.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

$(function () {
	$('.level1').each(function () {
		$(this).find("li:first-child").css("border-top", "none");
		$(this).find("li:last-child").css("border-bottom", "none");
        
		$(this).parent().eq(0).hoverIntent({
			timeout: 500,
			over: function () {
				var current = $('.level1:eq(0)', this);
				$("ul#menu-left li").removeClass("active");
				$(".level1").fadeOut();
                //alert(current.attr("id"));
                if(current.attr("id")!="noresize"){
				    current.width(current.parent().width() -36); // 36 = level1.padding-left + level1.pading-right + 1 border od 1px top level menu
                }else{
                    current.width(current.parent().width() +10  ); // 36 = level1.padding-left + level1.pading-right + 1 border od 1px top level menu
                }
				current.slideDown(100);
				$(this).addClass("active");
				Cufon.refresh();
			},
			out: function () {
				var current = $('.level1:eq(0)', this);
				current.fadeOut(200);
				$(this).removeClass("active");
				Cufon.refresh();
			}
		});
	});
	
	$('.level2').each(function () {
	   
        
		$(this).find("li:first-child").css("border-top", "none");
		$(this).find("li:last-child").css("border-bottom", "none");
	
    	$(this).parent().eq(0).hoverIntent({
			timeout: 200,
			over: function () {
				var current = $('.level2:eq(0)', this);
				$(".level2").fadeOut();
                current.css("left", $(this).parent().parent().width()-18);//-22 25
				current.slideDown(100);
			},
			out: function () {
				var current = $('.level2:eq(0)', this);
				current.fadeOut(200);
			}
		});
	});
    
    $('.level3').each(function () {
	
    	$(this).find("li:first-child").css("border-top", "none");
		$(this).find("li:last-child").css("border-bottom", "none");
	   
    	$(this).parent().eq(0).hoverIntent({
			timeout: 200,
			over: function () {
			// alert($(this).parent()[0].tagName)
                $(".level3").fadeOut();
				var current = $('.level3:eq(0)', this);
				
                //alert($(this).parent().parent().width());
                //$(this).parent().css("background-color","red");
                current.css("left", $(this).parent().width()+18);//-22 25
				current.slideDown(100);
			},
			out: function () {
			// $(".level3").fadeOut();
             
				var current = $('.level3:eq(0)', this);
				current.fadeOut(200);
			}
		});
    
	});
});
