var delayhide = null;
var DMD = null;

var topNavDMDWidth = '160px';
var sideNavDMDWidth = '200px';

var DELAY = '250';

/*
//	Not used, in favor of inline script in MainBorder.html

//	Waiting for body load could cause "DMD does not exist issues",
//		and stop the rest of the JS from functioning.

function setupDMD( )
{
	DMD = document.getElementById( 'dropMenuDiv' );
}
*/

function clearHideMenu( )
{
	if( delayhide != null )
		clearTimeout( delayhide );
}

function hideDMD( )
{
	clearHideMenu( );
	
	DMD.style.visibility = 'hidden';
	if( DMD != null && DMD.parentLink != null )
		DMD.parentLink.fn();
	
	DMD.parentLink = null;
	delayhide = null;
}

function delayHideDMD( time )
{
	delayhide = setTimeout( 'hideDMD();', time );
}

function leavingDropMenuDiv( e )
{
	if( !containsEvt( DMD.parentLink, e ) && !containsEvt( DMD, e ) )
	{
		delayHideDMD( DELAY );
	}
}

function showTopDMD( obj, DMDcontents, DMDsize, imgNum )
{
	hideDMD( );
	populateDMD( DMDcontents );
	
	var pos = findPos( obj );
	
	DMD.style.left = pos[0] + "px";
	DMD.style.top = pos[1] + obj.offsetHeight + "px";
	DMD.style.width = DMDsize;
	
	DMD.parentLink = obj;
	DMD.parentLink.fn = function() { return topNavRestoreImage( obj, imgNum ); }
	topNavSwapImage( obj, imgNum );
	
	DMD.style.visibility = "visible";
	
}

function showSideDMD( obj, DMDcontents, DMDsize )
{
	hideDMD( );
	populateDMD( DMDcontents );
	
	var pos = findPos( obj );
	
	DMD.style.left = pos[0] + obj.offsetWidth + "px";
	DMD.style.top = pos[1] + "px";
	
	DMD.parentLink = obj;
	//DMD.parentLink.fn = function() { return obj.childNodes[1].className = 'leftCategoryOff'; }
	DMD.parentLink.fn = function() { return getElementsByClassName( obj, 'leftCategoryOn' )[0].className = 'leftCategoryOff'; }
	getElementsByClassName( obj, 'leftCategoryOff' )[0].className = 'leftCategoryOn';
	//obj.childNodes[1].className = 'leftCategoryOn';
	
	DMD.style.visibility = "visible";
	
}

function populateDMD( contents )
{
	DMD.innerHTML = contents.join("\n");
}

/*  MM_swapImage replacement */

function topNavSwapImage( obj, num )
{
	if( num < 10 )
		num = '0' + num + '';
		
	var img = obj.getElementsByTagName( 'IMG' )[0];
	img.src = '/images/wt-menu-over_' + num + '.jpg';
}

function topNavRestoreImage( obj, num )
{
	if( num < 10 )
		num = '0' + num + '';
		
	var img = obj.getElementsByTagName( 'IMG' )[0];
	img.src = '/images/wt-menu-top_' + num + '.jpg';
}