// JavaScript Document
var $j = jQuery.noConflict();

var timeoutId;

$j(document).ready(function(){	
	
	$j('#navigation a').each(function(){		
		var url = location.pathname.substring(location.pathname.lastIndexOf('/'),location.pathname.length);
		if(url == $j(this).attr('href')){			
			$j(this).addClass('page-highlight');
		} 
	});	
	$j('#navigation li ul').hide();	
	$j('.main-menu-item').mouseover(function(){											 
		$j(this).parent().children('ul').addClass('active-item');		
		clearTimeout(timeoutId);		
		
		/* these items should not be executed on the current item*/
		$j('a.main-menu-item:not(.page-highlight)').css('background-position','0 0');
		$j('#navigation li ul:not(.active-item)').slideUp('fast');
		
		$j(this).css('background-position','0 -30px');
		$j(this).parent('li').children('ul').slideDown('fast');
	});	
	$j('.main-menu-item').mouseout(function(){									
		$j('a.main-menu-item:not(.page-highlight):not(.has-sub-menu)').css('background-position','0 0');
		$j(this).parent().children('ul').removeClass('active-item');
		var element = $j(this).parent('li').children('ul');
		var element2 = $j(this);
		timeoutId = setTimeout(function(){
			$j('a.main-menu-item:not(.page-highlight)').css('background-position','0 0');
			element.slideUp('fast');
		},2000);
	});
	$j('.sub-menu-item').mouseover(function(){
		clearTimeout(timeoutId);
		$j(this).parent().parent().parent().children('a.main-menu-item').css('background-position','0 -30px');
		$j(this).parent().parent().children('ul').addClass('active-item');
		
	});
	$j('.sub-menu-item').mouseout(function(){
		var element = $j(this).parent().parent();
		timeoutId = setTimeout(function(){
			element.children('ul').removeClass('active-item');							
			element.slideUp('fast');
			element.parent().children('a.main-menu-item:not(.page-highlight)').css('background-position','0 0');
		},2000);
	});	
});
