/*** SET BUTTON'S FOLDER HERE ***/
var buttonFolder = "media/Buttons/";

/*** SET BUTTONS' FILENAMES HERE ***/
upSources = new Array("button1up.png","button2up.png","button3up.png","button4up.png","button5up.png","button6up.png","button7up.png","button8up.png","button9up.png");

overSources = new Array("button1over.png","button2over.png","button3over.png","button4over.png","button5over.png","button6over.png","button7over.png","button8over.png","button9over.png");

// SUB MENUS DECLARATION, YOU DONT NEED TO EDIT THIS
subInfo = new Array();
subInfo[1] = new Array();
subInfo[2] = new Array();
subInfo[3] = new Array();
subInfo[4] = new Array();
subInfo[5] = new Array();
subInfo[6] = new Array();
subInfo[7] = new Array();
subInfo[8] = new Array();
subInfo[9] = new Array();


//*** SET SUB MENUS TEXT LINKS AND TARGETS HERE ***//
subInfo[1][1] = new Array("Home","index.html","_blank");
subInfo[1][2] = new Array("Contact","contact.html","_blank");

subInfo[2][1] = new Array("Kitchen A","phpslideshow.php?directory=media/works/Kitchen A&auto=1","_blank");
subInfo[2][2] = new Array("Kitchen AA","phpslideshow.php?directory=media/works/Kitchen AA&auto=1","_blank");
subInfo[2][3] = new Array("Kitchen B","phpslideshow.php?directory=media/works/Kitchen B&auto=1","_blank");
subInfo[2][4] = new Array("Kitchen C","phpslideshow.php?directory=media/works/Kitchen C&auto=1","_blank");
subInfo[2][5] = new Array("Kitchen D","phpslideshow.php?directory=media/works/Kitchen D&auto=1","_blank");
subInfo[2][6] = new Array("Kitchen E","phpslideshow.php?directory=media/works/Kitchen E&auto=1","_blank");
subInfo[2][7] = new Array("Kitchen F","phpslideshow.php?directory=media/works/Kitchen F&auto=1","_blank");
subInfo[2][8] = new Array("Kitchen G","phpslideshow.php?directory=media/works/Kitchen G&auto=1","_blank");
subInfo[2][9] = new Array("Kitchen H","phpslideshow.php?directory=media/works/Kitchen H&auto=1","_blank");
subInfo[2][10] = new Array("Kitchen I","phpslideshow.php?directory=media/works/Kitchen I&auto=1","_blank");
subInfo[2][11] = new Array("Kitchen J","phpslideshow.php?directory=media/works/Kitchen J&auto=1","_blank");
subInfo[2][12] = new Array("Kitchen K","phpslideshow.php?directory=media/works/Kitchen K&auto=1","_blank");
subInfo[2][13] = new Array("Kitchen L","phpslideshow.php?directory=media/works/Kitchen L&auto=1","_blank");
subInfo[2][14] = new Array("Kitchen M","phpslideshow.php?directory=media/works/Kitchen M&auto=1","_blank");
subInfo[2][15] = new Array("Kitchen N","phpslideshow.php?directory=media/works/Kitchen N&auto=1","_blank");
subInfo[2][16] = new Array("Kitchen O","phpslideshow.php?directory=media/works/Kitchen O&auto=1","_blank");
subInfo[2][17] = new Array("Kitchen P","phpslideshow.php?directory=media/works/Kitchen P&auto=1","_blank");

subInfo[3][1] = new Array("Bathroom A","phpslideshow.php?directory=media/works/Bathroom A&auto=1","_blank");
subInfo[3][2] = new Array("Bathroom B","phpslideshow.php?directory=media/works/Bathroom B&auto=1","_blank");
subInfo[3][3] = new Array("Bathroom C","phpslideshow.php?directory=media/works/Bathroom C&auto=1","_blank");

subInfo[4][1] = new Array("Laundry Room A","phpslideshow.php?directory=media/works/Laundry Room A&auto=1","_blank");
subInfo[4][2] = new Array("Laundry Room B","phpslideshow.php?directory=media/works/Laundry Room B&auto=1","_blank");
subInfo[4][3] = new Array("Laundry Room C","phpslideshow.php?directory=media/works/Laundry Room C&auto=1","_blank");

subInfo[5][1] = new Array("Living Room A","phpslideshow.php?directory=media/works/Living Room A&auto=1","_blank");
subInfo[5][2] = new Array("Living Room B","phpslideshow.php?directory=media/works/Living Room B&auto=1","_blank");
subInfo[5][3] = new Array("Living Room C","phpslideshow.php?directory=media/works/Living Room C&auto=1","_blank");
subInfo[5][4] = new Array("Living Room D","phpslideshow.php?directory=media/works/Living Room D&auto=1","_blank");
subInfo[5][5] = new Array("Living Room E","phpslideshow.php?directory=media/works/Living Room E&auto=1","_blank");
subInfo[5][6] = new Array("Living Room F","phpslideshow.php?directory=media/works/Living Room F&auto=1","_blank");
subInfo[5][7] = new Array("Living Room G","phpslideshow.php?directory=media/works/Living Room G&auto=1","_blank");
subInfo[5][8] = new Array("Living Room H","phpslideshow.php?directory=media/works/Living Room H&auto=1","_blank");

subInfo[6][1] = new Array("Bedroom A","phpslideshow.php?directory=media/works/Bedroom A&auto=1","_blank");
subInfo[6][2] = new Array("Bedroom B","phpslideshow.php?directory=media/works/Bedroom B&auto=1","_blank");
subInfo[6][3] = new Array("Bedroom C","phpslideshow.php?directory=media/works/Bedroom C&auto=1","_blank");
subInfo[6][4] = new Array("Bedroom D","phpslideshow.php?directory=media/works/Bedroom D&auto=1","_blank");
subInfo[6][5] = new Array("Bedroom E","phpslideshow.php?directory=media/works/Bedroom E&auto=1","_blank");

subInfo[7][1] = new Array("Furniture A","phpslideshow.php?directory=media/works/Furniture A&auto=1","_blank");
subInfo[7][2] = new Array("Furniture B","phpslideshow.php?directory=media/works/Furniture B&auto=1","_blank");
subInfo[7][3] = new Array("Furniture C","phpslideshow.php?directory=media/works/Furniture C&auto=1","_blank");
subInfo[7][4] = new Array("Furniture D","phpslideshow.php?directory=media/works/Furniture D&auto=1","_blank");
subInfo[7][5] = new Array("Furniture E","phpslideshow.php?directory=media/works/Furniture E&auto=1","_blank");
subInfo[7][6] = new Array("Furniture F","phpslideshow.php?directory=media/works/Furniture F&auto=1","_blank");
subInfo[7][7] = new Array("Furniture G","phpslideshow.php?directory=media/works/Furniture G&auto=1","_blank");

subInfo[8][1] = new Array("Freedom Double Unit","phpslideshow.php?directory=media/works/Freedom Double Unit&auto=1","_blank");
subInfo[8][2] = new Array("Freedom Triple Unit","phpslideshow.php?directory=media/works/Freedom Triple Unit BSH&auto=1","_blank");
subInfo[8][3] = new Array("Metro Thermadore Display","phpslideshow.php?directory=media/works/Metro Thermadore Display&auto=1","_blank");
subInfo[8][4] = new Array("Katy Display","phpslideshow.php?directory=media/works/Katy Display&auto=1","_blank");
subInfo[8][5] = new Array("Sara Display","phpslideshow.php?directory=media/works/Sara Display&auto=1","_blank");
subInfo[8][6] = new Array("Ferguson Display","phpslideshow.php?directory=media/works/Ferguson Display&auto=1","_blank");


//*** SET SUB MENU POSITION ( RELATIVE TO BUTTON ) ***//
var xSubOffset = 4;
var ySubOffset = 37;



//*** NO MORE SETTINGS BEYOND THIS POINT ***//
var overSub = false;
var delay = 500;
totalButtons = upSources.length;

// GENERATE SUB MENUS
for ( x=0; x<totalButtons; x++) {
	// SET EMPTY DIV FOR BUTTONS WITHOUT SUBMENU
	if ( subInfo[x+1].length < 1 ) { 
		document.write('<div id="submenu' + (x+1) + '">');
	// SET DIV FOR BUTTONS WITH SUBMENU
	} else {
		document.write('<div id="submenu' + (x+1) + '" class="dropmenu" ');
		document.write('onMouseOver="overSub=true;');
		document.write('setOverImg(\'' + (x+1) + '\',\'\');"');
		document.write('onMouseOut="overSub=false;');
		document.write('setTimeout(\'hideSubMenu(\\\'submenu' + (x+1) + '\\\')\',delay);');
		document.write('setOutImg(\'' + (x+1) + '\',\'\');">');


		document.write('<ul>');
		for ( k=0; k<subInfo[x+1].length-1; k++ ) {
			document.write('<li>');
			document.write('<a href="' + subInfo[x+1][k+1][1] + '" ');
			document.write('target="' + subInfo[x+1][k+1][2] + '">');
			document.write( subInfo[x+1][k+1][0] + '</a>');
			document.write('</li>');
		}
		document.write('</ul>');
	}
	document.write('</div>');
}





//*** MAIN BUTTONS FUNCTIONS ***//
// PRELOAD MAIN MENU BUTTON IMAGES
function preload() {
	for ( x=0; x<totalButtons; x++ ) {
		buttonUp = new Image();
		buttonUp.src = buttonFolder + upSources[x];
		buttonOver = new Image();
		buttonOver.src = buttonFolder + overSources[x];
	}
}

// SET MOUSEOVER BUTTON
function setOverImg(But, ID) {
	document.getElementById('button' + But + ID).src = buttonFolder + overSources[But-1];
}

// SET MOUSEOUT BUTTON
function setOutImg(But, ID) {
	document.getElementById('button' + But + ID).src = buttonFolder + upSources[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 ( x=0; x<totalButtons; x++) {
		moveObjectTo("submenu" + (x+1) + "",-500, -500 );
	}
}

// HIDE ONE SUB MENU
function hideSubMenu(subID) {
	if ( overSub == false ) {
		moveObjectTo(subID,-500, -500);
	}
}



preload();

