$(document).ready(function() {
	
	function megaHoverOver(){
		$(this).addClass("megamenu-itemactive").find(".megamenu-content").slideDown();
	}
	
	function megaHoverOut(){ 
	  $(this).removeClass("megamenu-itemactive").find(".megamenu-content").slideUp('fast', function(){
		$(this).hide();
	  });
	}

	var config = {    
		 sensitivity: 7,   
		 interval: 150,   
		 over: megaHoverOver, 
		 timeout: 10,   
		 out: megaHoverOut 
	};

	$("ul#megamenu-list li.megamenu-item").hoverIntent(config);
	
	$(".megamenu-content").each(function(){
		var nbelt = $(".megamenu-block", this).size();
		var $banner = $(".banner", this);
		if(nbelt <= 6){
			$(this).find(".megamenu-contentinner").addClass("bg2");
		}

		if($banner.length != 0){
			
			if((nbelt+1) % 3 == 0){
				$banner.insertAfter($(".megamenu-block", this).get(nbelt - 4))
						.css({"float":"right", "height":"205px"});
			}else if((nbelt+1) % 3 == 2){
				$banner.css({"width":"976px"});
			}
			
		}
		
		$(".megamenu-block", this).each(function(i){
			var $this = $(this);
			$this.find("img.mmimg").click(function(){
				window.location = $this.find("h3 a").attr("href");
			}).css({"cursor":"pointer"});
			
			if(((i + 1) % 3) == 2) {
				$this.css({"margin":"3px 3px 2px 3px"});
			}
		});
		
	});

});