

var handler;
var handlers;

var openMenu = 0;
var openSubMenu = 0;

function showInfoMenu( menuID, elements ) {
	hideMenu( openMenu );
	showMenu( menuID, elements );
	clearTimeout( handler );
}

function showInfoSubMenu( menuID, elements ) {
	hideSubMenu( openSubMenu );
	showSubMenu( menuID, elements );
	clearTimeout( handlers );
}



function hideMenu( menuID ) {
	if( document.getElementById('o_'+menuID) ) {
		$('#o_'+menuID).css( "display", "none" );
		$('#m_'+menuID).removeClass( "hover" );
	}
	hideSubMenu(openSubMenu);
}
function showMenu( menuID, elements ) {
	if( document.getElementById('o_'+menuID) ) {
		setMarginLeft( menuID );
		setWidth( menuID );
		$('#o_'+menuID).css( "display", "block" );
		$('#m_'+menuID).addClass( "hover" );
		openMenu = menuID;
	}
}


function hideSubMenu( menuID ) {
	if( document.getElementById('s_'+menuID) ) {
		$('#s_'+menuID).css( "display", "none" );
	}
}
function showSubMenu( menuID, elements ) {
	if( document.getElementById('s_'+menuID) ) {
		setMarginLeftSub( menuID );
		setWidthSub( menuID, elements );
		$('#s_'+menuID).css( "display", "block" );
		openSubMenu = menuID;
	}
}



var marginInfo = new Array( 0, 74, 142, 262, 377, 458, 542, 644, 726, 840 );
var widthInfo = new Array( 125, 125, 125, 125, 125, 125, 125, 125, 160, 125);

var marginInfoSub = new Array();
var widthInfoSub = new Array();

function setMarginLeft( menuID ) {
	$('#o_'+menuID).css( "margin", "0 0 0 "+marginInfo[menuID]+"px" );
}
function setMarginLeftSub( menuID ) {
	var overallLeft = marginInfo[openMenu]+widthInfo[openMenu];
	$('#s_'+menuID).css( "margin", marginInfoSub[menuID]+"px 0 0 "+overallLeft+"px" );
}


function setWidth( menuID, elements ) {
		$('#o_'+menuID).css( "width", widthInfo[menuID] + "px" );
}

function setWidthSub( menuID, elements ) {
	for(i=1; i <= elements; i++){
		$('#x_'+menuID+'_'+i).css( "width", widthInfoSub[menuID] + "px" );
	}
}



function closeMenuAfterAWhile() {
	handler = setTimeout( "closeWindowNowStupid()", 500 );
}


function closeWindowNowStupid() {
	hideMenu( openMenu );
}

function stopShuttingDown() {
	clearTimeout( handler );
}

$(document).ready(function(){
	$("ul.hidden li a").bind("click", function(e){
		closeWindowNowStupid();
	});
});
