(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 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 hover(){
	var toHide = lastBlock.next('.slide');
	var elt = ($(this).attr('class') == 'menuitem' ? $(this) : $("ul.slides li.selected a.menuitem"));
	
	var toShow = elt.next('.slide');

	
	if(lastBlock.parent().attr("id") != elt.parent().attr("id")){
		animated = true;
		 elt.next(".slide").animate({width: maxWidth+"px"}, { queue:false, duration:400}, null, function(){
	        	animated = false;
	        });
        $(toHide).animate({width: minWidth+"px"}, { queue:false, duration:400 });
        if(elt.attr('class') == 'menuitem'){
	        lastBlock = elt;
        }
	}
}

$(function(){
    lastBlock = $("ul.slides li.selected a.menuitem");
    maxWidth = 674;
    minWidth = 0;	
    animated = false;

    var config = {    
    	     sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
    	     interval: 50, // number = milliseconds for onMouseOver polling interval    
    	     over: hover,  
    	     timeout: 500,   
    	     out: function(){}  
    };

    $("ul.slides li a.menuitem").hoverIntent(config);
    
    $("ul.slides li.selected a.readmore").click(function(){
    	$.scrollTo("#body-container", 600);
    	return false;
    });
    
    $(".bcontent").mouseleave(function(){
    		hover();
    });
});
