// VARS

var MENU_FADEIN_DELAY = 50;
var MENU_FADEOUT_DELAY = 100;
var MENU_FADE_DURATION = 500;

// FUNCTIONS

function hideSubs()
{
	$("#menu ul#main_menu > li ul").css('opacity','0').css('display','none');
}

function addArrows()
{
	$('#menu ul#main_menu > li > ul li').each(function(index) 
	{
		if ($(this).children("ul").size() > 0)
		{
			$(this).children("a:first").append('<span class="arrow">></span>');
		}
  	});
}

function showChildList()
{
	$(this).children("ul:first").css('display','block');
	
	$(this).children("ul:first").stop(true);
	$(this).children("ul:first").delay(MENU_FADEIN_DELAY).animate({
		opacity: 1
	}, MENU_FADE_DURATION);
	
//	$(this).children("ul:first").fadeIn(200);
}

function hideChildList()
{	
	$(this).children("ul:first").stop(true);
	$(this).children("ul:first").delay(MENU_FADEOUT_DELAY).animate({
		opacity: 0
	}, MENU_FADE_DURATION, hideComplete);
	
//	$(this).children("ul:first").fadeOut(200);
}

function hideComplete()
{$(this).css('display','none');}

function checkHeights()
{
	if ($('div.right').height() > $('div.left').height())
	{
		$('div.left').css('height', $('div.right').height())
	}
}

/* INIT */

$(document).ready( function() {

	hideSubs();
	
	addArrows();
	
	checkHeights();
	
	$('#menu ul#main_menu li').mouseover(showChildList);
	$('#menu ul#main_menu li').mouseout(hideChildList);
	
	$('#menu ul.sub_menu li').mouseover(showChildList);
	$('#menu ul.sub_menu li').mouseout(hideChildList);

} );

$(window).load( function() {checkHeights();} );

$(window).resize( function() {checkHeights();} );
