$(document).ready(function()
{
	var t;
	var hover;
	var active;
	
	$('#content-left ul > li > a, #content-left ul > li > ul > li > a').click
	(
		function()
		{
			if($(this).attr('href') == '#')
			{
				$(this).toggleClass('active-open');
				$($($(this).parent('li')).children('ul')).slideToggle('normal');
				return false;
			}
		}
	);
	
	// main items hover
	$('#navigation ul > li > a.head').hover(
	function()
	{
		$('#navigation ul li a').removeClass('hover');
		var ul_items = $($($($(this).parent('li')).children('ul')));
		if (ul_items.length > 0) {
			if (hover != $("a.head").index(this)) {
				$('#navigation ul li ul').hide();
				hover = $("a.head").index(this);
				$(this).addClass('hover');
				//ul_items.slideDown('normal');
				ul_items.show();
			}
		}
		else{
			$('#navigation ul li ul').hide();
			hover = undefined;
		}
		
		clearTimeout(t);
	}, 
	function()
	{
		t = setTimeout
		(
			function()
			{
				
				hideNav();
				$('a.head').eq(hover).removeClass('hover');
				hover = undefined;
			},
			500
		);
	});	
	
	// sub items hover
	$('#navigation ul > li > ul > li a').hover(
	function()
	{
		$($($($(this).parent('li')).children('ul'))).slideDown('normal');
		clearTimeout(t);
	}, 
	function()
	{
		t = setTimeout
		(
			function()
			{
				
				hideNav();
				$('a.head').eq(hover).removeClass('hover');
				hover = undefined;
			},
			500
		);
	});	
	
});

function hideNav() {
	$('#navigation ul li ul').slideUp('fast', function()
	{
		$(this).hide();
	});
}
