//*** SET SUB MENU POSITION ( RELATIVE TO BUTTON ) ***//
var xSubOffset = 1;
var ySubOffset = 20;


//*** NO MORE SETTINGS BEYOND THIS POINT ***//
var overSub = false;
var delay = 1000;
totalMenus = upSources.length;
for(i=1; i<=totalMenus-1; i++)
{
	totalButtons = upSources[i].length;
	// GENERATE SUB MENUS
	for ( x=0; x<totalButtons; x++) {
		// SET EMPTY DIV FOR BUTTONS WITHOUT SUBMENU
		if ( SubInfo[i][x+1].length < 1 ) { 
			document.write('<div id="submenu' + i + (x+1) + '">');
		// SET DIV FOR BUTTONS WITH SUBMENU
		} else {
			document.write('<div id="submenu' + i + (x+1) + '" class="dropmenu" ');
			document.write('onMouseOver="overSub=true;"');
			document.write('onMouseOut="overSub=false;');
			document.write('setTimeout(\'hideSubMenu(\\\'submenu' + i + (x+1) + '\\\')\',delay);">');

			document.write('<ul>');
			for ( k=0; k<SubInfo[i][x+1].length-1; k++ ) {
				document.write('<li>');
				document.write('<a href="' + SubInfo[i][x+1][k+1][1] + '" ');
				document.write('target="' + SubInfo[i][x+1][k+1][2] + '">');
				document.write( SubInfo[i][x+1][k+1][0] + '</a>');
				document.write('</li>');
			}
			document.write('</ul>');
		}
		document.write('</div>');
	}

	// PRELOAD MAIN MENU BUTTON IMAGES
	for ( x=0; x<totalButtons; x++ ) {
		buttonUp = new Image();
		buttonUp.src = buttonFolder + upSources[i][x];
		buttonOver = new Image();
		buttonOver.src = buttonFolder + overSources[i][x];
	}
}

//*** MAIN MENU FUNCTIONS ***//
// SET MOUSEOVER BUTTON
function setOverImg(Men, But) {
	document.getElementById('button' + Men + But).src = buttonFolder + overSources[Men][But-1];
}

// SET MOUSEOUT BUTTON
function setOutImg(Men, But) {
	document.getElementById('button' + Men + But).src = buttonFolder + upSources[Men][But-1];
}

//*** SUB MENU FUNCTIONS ***//
// GET ELEMENT ID MULTI BROWSER
function getElement(id) {
	return document.getElementById ? document.getElementById(id) : document.all ? document.all(id) : null; 
}

// GET X COORDINATE
function getRealLeft(id) { 
	var el = getElement(id);
	if (el) { 
		xPos = el.offsetLeft;
		tempEl = el.offsetParent;
		while (tempEl != null) {
			xPos += tempEl.offsetLeft;
			tempEl = tempEl.offsetParent;
		} 
		return xPos;
	} 
} 

// GET Y COORDINATE
function getRealTop(id) {
	var el = getElement(id);
	if (el) { 
		yPos = el.offsetTop;
		tempEl = el.offsetParent;
		while (tempEl != null) {
			yPos += tempEl.offsetTop;
			tempEl = tempEl.offsetParent;
		}
		return yPos;
	}
}

// MOVE OBJECT TO COORDINATE
function moveObjectTo (objectID,x,y) {
	var el = getElement(objectID);
	el.style.left = x;
	el.style.top = y;
}

// MOVE SUBMENU TO CORRESPONDING BUTTON
function showSubMenu(subID, buttonID) {
	hideAllSubMenus();
	butX = getRealLeft(buttonID);
	butY = getRealTop(buttonID);
	moveObjectTo(subID,butX+xSubOffset, butY+ySubOffset);
}

// HIDE ALL SUB MENUS
function hideAllSubMenus() 
{
	for(i=1; i<=totalMenus-1; i++)
	{
		totalButtons = upSources[i].length;
		for ( x=0; x<totalButtons; x++) 
		{
			moveObjectTo("submenu" + i + (x+1),-400, 100 );
		}
	}
}

// HIDE ONE SUB MENU
function hideSubMenu(subID) {
	if ( overSub == false ) {
		moveObjectTo(subID,-400, 100);
	}
}


