window.addEvent('domready',function() {	
	
	$$(".menu dl").each( function(el){
		var parent = el.getParent();
		if(!parent.hasClass('selected')){
			parent.addEvent('mouseenter', function() { this.addClass('selected'); });
			parent.addEvent('mouseleave', function() { this.removeClass('selected'); });
		}
	});	
});

var BlocScroll = 
{
	scrollTimer:0,
	scrollFx:0,
	
	init:function()
	{
		BlocScroll.ready = true;
		
		if ($$(".scrollable").length == 0) return;
		window.addEvent("scroll", BlocScroll.scrollLeft);
	},
	
	scrollLeft:function(e) 
	{
		if(BlocScroll.scrollTimer != 0) clearInterval(BlocScroll.scrollTimer);
		
		var footer = $$("#footer")[0];
		var bloc = $$(".scrollable")[0];
		
		if (window.getHeight() > bloc.getCoordinates().height + 200) BlocScroll.scrollTimer = setTimeout("BlocScroll.scrollStart()",300);
	},
	
	scrollStart:function() 
	{
	    var body = $$(".body")[0];
		var bloc = $$(".scrollable")[0];
		var maxTween = body.getCoordinates().height - bloc.getCoordinates().height;
		if (!bloc.style.marginTop) bloc.style.marginTop = bloc.getStyle("margin-top");
		var topLeftMargin = bloc.style.marginTop;
		
		if (BlocScroll.scrollFx != 0) BlocScroll.scrollFx.stop();
		BlocScroll.scrollFx = new Fx.Style(bloc,"marginTop").start(topLeftMargin,Math.min(window.getScrollTop(),maxTween));
	},
	
	scrollReset:function()
	{
	    if ($$(".scrollable").length == 0) return;
	    if(BlocScroll.scrollTimer != 0) clearInterval(BlocScroll.scrollTimer);
	    
	    window.removeEvent("scroll", BlocScroll.scrollLeft);
	    	    
	    var bloc = $$(".scrollable")[0];
	    if (!bloc.style.marginTop) bloc.style.marginTop = bloc.getStyle("margin-top");
	    
	    bloc.setStyle("marginTop", "0px");
	}
}
window.addEvent("domready", BlocScroll.init);

