jQuery.fn.extend({
	scrollTo : function(speed, easing,cbFunc){
    	return this.each(function() {
      		var targetOffset = $(this).offset().top||0;
      		$('HTML,BODY').animate({scrollTop: targetOffset}, speed, easing, cbFunc);
    	});
  	}
});
$(function(){//console.log('LOADING '+new Date().getTime());
	$('#menu>LI>UL').parent().hover(function(){
		$(this).addClass('hover');
		$(this).children('UL:first').stop(true,true).slideDown(200);		
	},function(){
		$(this).removeClass('hover');
		$(this).children('UL:first').stop(true).slideUp(200,function(){$(this).height('auto')});
	});
	var currentMenu=$('A.current').next('UL.subMenu').get(0);
	if(currentMenu){
		var content=document.getElementById('content');
		content.insertBefore(currentMenu.cloneNode(true),content.firstChild);
		var page=location.pathname.split('/').reverse()[0];
		$('A[href*='+page+']').click(function(event){
			var urlHash=(this.hash=='#')?'':this.hash;//For Safari
			$(urlHash||'BODY').scrollTo(500,'',function(){
				if(urlHash==location.hash){
					return false;
				}
				if(urlHash.indexOf('#')<0){
					urlHash='#top';
				}
				location.hash=urlHash;
			});
			return false;
		});
	}
	$('UL.subMenu>LI').hover(function(){
		$(this).addClass('hover');
	},function(){
		$(this).removeClass('hover');
	});
	if(location.hash){
		$(location.hash).scrollTo(500);
	}
});