/*** SET BUTTON'S FOLDER HERE ***/
var buttonFolder = "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","button10up.png","button11up.png","button12up.png","button13up.png","button14up.png","button15up.png","button16up.png","button17up.png","button18up.png","button19up.png","button20up.png","button21up.png","button22up.png");

overSources = new Array("button1over.png","button2over.png","button3over.png","button4over.png","button5over.png","button6over.png","button7over.png","button8over.png","button9over.png","button10over.png","button11over.png","button12over.png","button13over.png","button14over.png","button15over.png","button16over.png","button17over.png","button18over.png","button19over.png","button20over.png","button21over.png","button22over.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();
subInfo[10] = new Array();
subInfo[11] = new Array();
subInfo[12] = new Array();
subInfo[13] = new Array();
subInfo[14] = new Array();
subInfo[15] = new Array();
subInfo[16] = new Array();
subInfo[17] = new Array();
subInfo[18] = new Array();
subInfo[19] = new Array();
subInfo[20] = new Array();
subInfo[21] = new Array();
subInfo[22] = new Array();


//*** SET SUB MENUS TEXT LINKS AND TARGETS HERE ***//

subInfo[2][1] = new Array("How To Seal Air Leaks","http://www.diyhomeinsulation.com/airleak.php","");
subInfo[2][2] = new Array("How To Apply Caulk","http://www.diyhomeinsulation.com/caulk.php","");

subInfo[3][1] = new Array("How To Install Blown In Insulation","http://www.diyhomeinsulation.com/blownin.php","");
subInfo[3][2] = new Array("How To Install Fiberglass Batt Insulation","http://www.diyhomeinsulation.com/atticbatts.php","");
subInfo[3][3] = new Array("How To Insulate Attic Access Covers","http://www.diyhomeinsulation.com/atticcover.php","");
subInfo[3][4] = new Array("How To Insulate Attic Drop-Down Stairs","http://www.diyhomeinsulation.com/atticstairs.php","");
subInfo[3][5] = new Array("How To Install A Radiant Barrier In The Attic","http://www.diyhomeinsulation.com/radiantattic.php","");
subInfo[3][6] = new Array("How To Insulate A Vaulted Ceiling","http://www.diyhomeinsulation.com/vaultceiling.php","");
subInfo[3][7] = new Array("How To Add Fiberglass Batts Over Existing Insulation","http://www.diyhomeinsulation.com/existingbatts.php","");
subInfo[3][8] = new Array("Do Attic Gable End Walls Need Insulation?","http://www.diyhomeinsulation.com/gableends.php","");
subInfo[3][9] = new Array("How To Install A Attic Floor Over Insulation.","http://www.diyhomeinsulation.com/atticfloor.php","");

subInfo[4][1] = new Array("How To Remove Moisture From A Basement","http://www.diyhomeinsulation.com/basementmoisture.php","");
subInfo[4][2] = new Array("How To Prepare A Basement For Insulation","http://www.diyhomeinsulation.com/basementprep.php","");
subInfo[4][3] = new Array("How To Insulate Basement Walls","http://www.diyhomeinsulation.com/basementwallfurr.php","");
subInfo[4][4] = new Array("How To Frame And Insulate Basement Walls","http://www.diyhomeinsulation.com/basementwallframe.php","");

subInfo[5][1] = new Array("Insulating Vented Crawl Spaces","http://www.diyhomeinsulation.com/ventedcrawl.php","");
subInfo[5][2] = new Array("Insulating Unvented Crawl Spaces","http://www.diyhomeinsulation.com/unventedcrawl.php","");


subInfo[7][1] = new Array("Insulating Rectangular Ducts","http://www.diyhomeinsulation.com/duct.php","");
subInfo[7][2] = new Array("Insulating Round Or Cylindrical Ducts","http://www.diyhomeinsulation.com/roundducts.php","");

subInfo[8][1] = new Array("How To Detect Air Leaks","http://www.diyhomeinsulation.com/auditairleak.php","");
subInfo[8][2] = new Array("How To Inspect Your Lighting Systems","http://www.diyhomeinsulation.com/auditlighting.php","");
subInfo[8][3] = new Array("How To Inspect And Measure Existing Insulation","http://www.diyhomeinsulation.com/auditinsulation.php","");
subInfo[8][4] = new Array("Checking Out Your Heating And Cooling Equipment","http://www.diyhomeinsulation.com/audithvac.php","");
subInfo[8][5] = new Array("Are Your Appliances Energy Efficient?","http://www.diyhomeinsulation.com/auditappliances.php","");

subInfo[9][1] = new Array("How To Insulate A Underfloor","http://www.diyhomeinsulation.com/ventedcrawl.php","");
subInfo[9][2] = new Array("How To Insulate A New Unfinished Floor","http://www.diyhomeinsulation.com/floorjoist.php","");
subInfo[9][3] = new Array("How To Insulate A Floor Framed With Beams","http://www.diyhomeinsulation.com/floorbeams.php","");

subInfo[10][1] = new Array("How To Insulate A Garage Ceiling","http://www.diyhomeinsulation.com/garageceiling.php","");
subInfo[10][2] = new Array("How To Insulate Garage Walls","http://www.diyhomeinsulation.com/garagewalls.php","");
subInfo[10][3] = new Array("How To Insulate A Garage Door","http://www.diyhomeinsulation.com/garagedoor.php","");
subInfo[10][4] = new Array("Insulating Garage Walls With Blown In Insulation","http://www.diyhomeinsulation.com/garagewallblowin.php","");

subInfo[11][1] = new Array("How Much Insulation Do I Need?","http://www.diyhomeinsulation.com/rvalue.php","");
subInfo[11][2] = new Array("How To Insulate A Skylight","http://www.diyhomeinsulation.com/skylights.php","");
subInfo[11][3] = new Array("How To Insulate A Water Heater","http://www.diyhomeinsulation.com/waterheater.php","");
subInfo[11][4] = new Array("How To Insulate A Wall Switch Or Outlet","http://www.diyhomeinsulation.com/wallswitch.php","");
subInfo[11][5] = new Array("Can I Re-Use Or Recycle Insulation?","http://www.diyhomeinsulation.com/recycle.php","");

subInfo[12][1] = new Array("How To Measure For Attic Insulation","http://www.diyhomeinsulation.com/measureattic.php","");
subInfo[12][2] = new Array("How To Measure For Walls","http://www.diyhomeinsulation.com/measurewalls.php","");
subInfo[12][3] = new Array("How To Measure For Floors","http://www.diyhomeinsulation.com/measurefloors.php","");

subInfo[13][1] = new Array("Insulating Pipes With Fiberglass","http://www.diyhomeinsulation.com/pipesbatts.php","");
subInfo[13][2] = new Array("Insulating Pipes With Tubular Sleeves","http://www.diyhomeinsulation.com/pipesleeve.php","");

subInfo[14][1] = new Array("How To Save Energy In The Summer","http://www.diyhomeinsulation.com/summersavings.php","");
subInfo[14][2] = new Array("How To Save Energy In The Winter","http://www.diyhomeinsulation.com/wintersavings.php","");

subInfo[15][1] = new Array("Do It Yourself Solar Panels","http://www.diyhomeinsulation.com/solar.php","");

subInfo[16][1] = new Array("How To Soundproof Walls","http://www.diyhomeinsulation.com/soundwall.php","");


subInfo[18][1] = new Array("Installing A Vapor Barrier In A Crawlspace","http://www.diyhomeinsulation.com/vaporcrawl.php","");
subInfo[18][2] = new Array("Installing A Wall Vapor Barrier","http://www.diyhomeinsulation.com/vaporwalls.php","");
subInfo[18][3] = new Array("Installing A Ceiling Vapor Barrier","http://www.diyhomeinsulation.com/vaporceiling.php","");

subInfo[19][1] = new Array("How To Install Attic Ventilation Baffles","http://www.diyhomeinsulation.com/baffles.php","");
subInfo[19][2] = new Array("How To Install Gable Vents","http://www.diyhomeinsulation.com/ventgable.php","");
subInfo[19][3] = new Array("How To Install Roof Vents","http://www.diyhomeinsulation.com/ventroof.php","");
subInfo[19][4] = new Array("How To Install Soffit Vents","http://www.diyhomeinsulation.com/ventsoffit.php","");

subInfo[20][1] = new Array("Insulating Uncovered Walls Using Fiberglass Batts","http://www.diyhomeinsulation.com/wall1.php","");
subInfo[20][2] = new Array("How To Blow Insulation Into Walls","http://www.diyhomeinsulation.com/wallblowin.php","");
subInfo[20][3] = new Array("How To Insulate Concrete Walls","http://www.diyhomeinsulation.com/concretewall.php","");
subInfo[20][4] = new Array("Kneewalls","http://www.diyhomeinsulation.com/kneewall.php","");
subInfo[20][5] = new Array("How To Install Cellulose Wet Spray Insulation","http://www.diyhomeinsulation.com/wetspray.php","");
subInfo[20][6] = new Array("How To Check Walls For Existing Insulation","http://www.diyhomeinsulation.com/checkwalls.php","");
subInfo[20][7] = new Array("Add Blown In Insulation In Walls With Existing Insulation","http://www.diyhomeinsulation.com/existingwallbatts.php","");

subInfo[21][1] = new Array("Installing Weather Stripping","http://www.diyhomeinsulation.com/weatherstrip.php","");
subInfo[21][2] = new Array("How To Weatherstrip A Garage Door","http://www.diyhomeinsulation.com/weatherstripgarage.php","");



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



//*** NO MORE SETTINGS BEYOND THIS POINT ***//
var overSub = false;
var delay = 1000;
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();

