// <!--
// Copyright 2006-2007 javascript-array.com
// Modified with Scriptaculous by Josh @ CCG
// Rebuilt by Mike @ CT (Dec 2009)

var SubMoving=0;
var TimerShowMain=0;
var TimerSlideUp=0;
var prevsec=0;
var RenderingMain=0;

function watchevent() {
	var submenu = document.getElementById("submenu");
//	xb.addEvent(submenu,'mouseleave',RollOutSub,false);
	ShowMain();
}

function WaitIfMoving() {
/*	while (SubMoving>0)
	{
//null
	}
	*/
}

function SubMovingDone() {
	SubMoving=0;
}

function SlideUp(sec) {
	WaitIfMoving();
	if ($('submenu').visible())
	{
		if (sec)
		{
			command="SlideUpNow('"+sec+"')";
			TimerSlideUp=window.setTimeout(command,300);
		} else {
			TimerSlideUp=window.setTimeout("SlideUpNow()",300);
		}
	}
}

function SlideUpNow(sec) {
	SubMoving=1;
	Effect.SlideUp('submenu', {duration:0.2});
	window.setTimeout("SubMovingDone()",250);
	if (sec)
	{
		if (document.getElementById(sec))
		{
					document.getElementById(sec).style.background="url(/images/bg-menu.png) repeat-x";
		}
		sec=sec+'-sub';
		if (document.getElementById(sec))
		{
			command="document.getElementById('"+sec+"').style.display='none'";
			window.setTimeout(command,150);
		}
	}
}

function SlideDown() {
	window.clearTimeout(TimerSlideUp);
	WaitIfMoving();
	if (!$('submenu').visible())
	{
		SubMoving=1;
		Effect.SlideDown('submenu', {duration:0.2});
		window.setTimeout("SubMovingDone()",250);
	}

}

function RollOver(sec) {
	if (!RenderingMain)
	{
		window.clearTimeout(TimerShowMain);
		document.getElementById(sec).style.background="url(/images/bg-menu-hover.png) repeat-x";
	// change others to normal?
		if (document.getElementById(sec+'-sub'))
		{
			SlideDown();
			document.getElementById(sec+'-sub').style.display="block";
		} else {
				SlideUp(prevsec);
		}
		if (prevsec)
		{
			if (prevsec!=sec) {
				document.getElementById(prevsec).style.background="url(/images/bg-menu.png) repeat-x";
				if (document.getElementById(prevsec+'-sub'))
				{
					WaitIfMoving();
					if (document.getElementById(sec+'-sub'))
					{
						document.getElementById(prevsec+'-sub').style.display="none";
					}
				}
			}
		}
		prevsec=sec;
	}
}

function RollOut(sec) {
/*	document.getElementById(sec).style.background="url(/images/bg-menu.png) repeat-x";
	if (document.getElementById(sec+'-sub'))
	{
		SlideUp();
		document.getElementById(sec+'-sub').style.dispay="none";
	}
*/
	RollOutSub();
}

function ShowMain() {
	if (document.getElementById(currentpage+'-sub')) {
		if ($('submenu').visible() && document.getElementById(currentpage+'-sub').style.display!="none")
		{
			// already displaying
		} else {
			RenderingMain=1;
			if ($('submenu').visible())
			{
				SlideUpNow(prevsec);
			}
			if (document.getElementById(prevsec))
			{
				document.getElementById(prevsec).style.background="url(/images/bg-menu.png) repeat-x";
			}
			window.setTimeout("ShowMainNow()",400);
		}
	} else {
		if ($('submenu').visible())
		{
			SlideUpNow(prevsec);
		}
		if (document.getElementById(prevsec))
		{
			document.getElementById(prevsec).style.background="url(/images/bg-menu.png) repeat-x";
		}
		document.getElementById(currentpage).style.background="url(/images/bg-menu-hover.png) repeat-x";
		prevsec=currentpage;
	}
}

function ShowMainNow() {
	document.getElementById(currentpage).style.background="url(/images/bg-menu-hover.png) repeat-x";
	if (document.getElementById(currentpage+'-sub'))
	{
		document.getElementById(currentpage+'-sub').style.display="block";
		SlideDown();
	}
	prevsec=currentpage;
	RenderingMain=0;
}

function RollOverSub() {
	window.clearTimeout(TimerSlideUp);
	window.clearTimeout(TimerShowMain);
}

function RollOutSub() {
	TimerShowMain=window.setTimeout("ShowMain()",1000);
}

// -->
