// Copyright 2005 Michael Udaltsov, DVC Multimedia



// prevent old browsers from having errors

get_null = function() { return null; }

if (!document.getElementById) {

	document.getElementById = get_null;

}



// menu titles, links, rollover images

subMenus = [

	["Gallery Home", "Wardrobes", "Door Systems", "Wine Cellars", "Wine Cabinets", "Media &amp; Office"],

	["Features Home", "Wardrobes", "Wine Cellars", "Home Theater &amp; Office"],

	["Cabinet Designs", "Interior Design"],

	["About Us", "Contact Form" , "Privacy", "Press Room", "Showroom", "Testimonials"]

	];



subLinks = [

	["gallery.html", "gallery_wardrobes.php?cid=1&page=1", "gallery_door_systems.php?cid=2&page=1", "gallery_wine_cellars.php?cid=3&page=1", "gallery_wine_cabinets.php?cid=14&page=1", "gallery_media_office.php?cid=5&page=1"],

	["features.html", "features_wardrobes.php", "features_wine_cellars.php", "features_home_theater.php"],

	["services_cabinet_designs.html", "services_interior_design.html"],

	["about_company.html", "contact_form.php" , "about_privacy.html", "about_press_room.html" , "contact_showroom.html","about_testimonials.html"]

	];



rollOvers = [

	["images/nav/gallery.gif", "images/nav/gallery_over.gif"],

	["images/nav/features.gif", "images/nav/features_over.gif"],

 	["images/nav/services.gif", "images/nav/services_over.gif"],

 	["images/nav/aboutus.gif", "images/nav/aboutus_over.gif"],

	["images/nav/contactus.gif", "images/nav/contactus_over.gif"],

	["images/nav/home.gif", "images/nav/home_over.gif"]];





// is keep track of open menus

var menuOpen = false;

var openMenuNum = -1;

var openMenuElement = null;

var hideTimeOut = null;

var initialRollover = -1;



function startTimer(rollKeep) {

	stopTimer();

	

	// rollover that will remain selected (current section)

	keepRollNum = rollKeep;



	if (menuOpen) {

		hideTimeOut = setTimeout("hideMenu()", 200);

	}

}



function stopTimer() {

	if (hideTimeOut)

		clearTimeout(hideTimeOut);

	hideTimeOut = null;

}



function showMenu(menuNumToShow) {

	stopTimer();



	// hide current menu

	if (menuOpen && openMenuElement) {

		openMenuElement.className = "menuHide";

		rollOff(openMenuNum);

	}



	// show the new menu

	menuOpen = true;

	openMenuNum = menuNumToShow;

	openMenuElement = document.getElementById("menu" + openMenuNum)

	var img = document.getElementById("button" + openMenuNum);

	if (openMenuElement && img) {



		// if working with IE, the X and Y position has to be added from parents

		if (!img.x || !img.y) {

			img.x = 0;

			img.y = 0;

			

			var par = img;

			var lastLeft = 0, lastTop = 0;

			while (par) {

				if (lastLeft != par.offsetLeft) { // ignore duplicate offsets

					img.x += par.offsetLeft;

					lastLeft = par.offsetLeft;

				}

				if (lastTop != par.offsetTop) { // ignore duplicate offsets

					img.y += par.offsetTop;

					lastTop = par.offsetTop;

				}

				par = par.offsetParent;

			}

		}



		//alert("x: " + img.x + ", y: " + img.y);

		

		openMenuElement.style.left = (img.x + 2) + "px";

		openMenuElement.style.top = (img.y + 32) + "px";

		openMenuElement.className = "menuShow";

		rollOn(openMenuNum);

	}

}



function hideMenu() {

	hideTimeOut = null;



	if (openMenuElement) {

		rollOff(openMenuNum);

		openMenuElement.className = "menuHide";

		openMenuElement = null;

		openMenuNum = -1;

		menuOpen = false;

	}

}



function preloadRollovers() {

	if (document.images) {

		for (var i = 0; i < rollOvers.length; i++) {

			for (var j = 0; j < 2; j++) {

				var img = new Image();

				img.src = rollOvers[i][j];

			}

		}

	}

}



function rollOn(menuNum) {

	var img = document.getElementById("button" + menuNum);

	if (img) {

		img.src = rollOvers[menuNum][1];

	}

}



function rollOff(menuNum) {

	if (menuNum == initialRollover) {

		return;

	}

	var img = document.getElementById("button" + menuNum);

	if (img) {

		img.src = rollOvers[menuNum][0];

	}

}



function addMenus(initRoll) {

	// prevent old browsers from loading menus, since they don't support CSS hiding either

	if (document.getElementById == get_null) {

		return;

	}

	initialRollover = initRoll;

	

	for (var menuNum = 0; menuNum < subMenus.length; menuNum++) {

		

		// menu container

		document.write('<div id="menu' + menuNum + '" class="menuHide" style="z-index: ' + (menuNum + 10) + '" onmouseover="stopTimer();" onmouseout="startTimer();">');

		

		// menu items

		for (var i = 0; i < subLinks[menuNum].length; i++) {

			document.write('<div class="menuLine"><a href="' + subLinks[menuNum][i] + '">' + subMenus[menuNum][i] + '<\/a><\/div>');

		}

	

		// container end

		document.write('<\/div>');

	}

}


