// JavaScript Document

/*
Copyright Â© 2008 Dream Web Pages (P) Ltd.
TITLE: Javascript Menu
AUTHOR: Pankaj Tiwari
COMPANY: Dream Web Pages (P) Ltd.
DATE MODIFIED: October 04, 2008
*/

// ARRAY SEQUENCE - Welcome - Our Services - Our Office - Contact us

var menus = new Array(new Array(["vision", "index.php?task=vision"],
								["faq", "index.php?task=faq"],
								["related links", "index.php?task=related"]
								),
					/*  new Array(["family dentistry", "#"],
								["cosmetic dentistry", "#"]
								),*/
					  new Array(["about Dr. Simrat", "index.php?task=doc"]
								),
					   new Array(["dentistry &amp; orthodontics", "index.php?task=optio"],
								 ["cosmetic dentistry", "index.php?task=cosmetic"]
								),
					  new Array(["request an appointment", "index.php?task=book"],
								["directions", "index.php?task=direction"]
								)
					  );


//------------------------------------------------------------------------------------------------------------------------------\\
/*
	DO NOT MODIFY BELOW THIS UNTIL YOU KNOW WHAT YOU ARE DOING
*/

var hideDelay = 250;
var currentObj;

var ie4 = document.all;
var ns6 = document.getElementById && !document.all;

if (ie4 || ns6) {
	document.write('<div id="subMenu" onMouseover="clearhidemenu();" onMouseout="dynamichide(event);"></div>');
}

function showhide(e) {
	if (ie4 || ns6) {
		dropmenuobj.style.left = dropmenuobj.style.top = "-500px";
	}
	
	if (e.type == "click" && obj.visibility == "hidden" || e.type == "mouseover") {
		dropmenuobj.style.visibility = "visible";
	} else if (e.type == "click") {
		dropmenuobj.style.visibility = "hidden";
	}
}

function populateMenu(menuIndex) {
	var menu_str = "";
	
	menu_str += '<div class="subMenuTop"></div>';
	menu_str += '<div class="subMenuBottom">';
	menu_str += '<div class="subMenuContent">';
	
	for(var i = 0; i < menus[menuIndex].length; i++) {
		menu_str += '<a href="' + menus[menuIndex][i][1] + '">' + menus[menuIndex][i][0] + '</a>';
	}
	
	menu_str += '</div>';
	menu_str += '</div>';
	
	if (ie4 || ns6) {
		dropmenuobj.innerHTML = menu_str;
	}
}

function subMenu(obj, e, menuIndex) {
	if(currentObj != undefined) {
		currentObj.className = "";
	}
	
	obj.className = "activeLink";
	currentObj = obj;
	
	if (window.event) {
		event.cancelBubble = true;
	} else if (e.stopPropagation) {
		e.stopPropagation();
	}
	
	clearhidemenu();
	
	dropmenuobj = document.getElementById ? document.getElementById("subMenu") : subMenu;
	populateMenu(--menuIndex);

	if (ie4 || ns6) {
		showhide(e);
		
		dropmenuobj.style.left = leftPos(obj, -9) + "px";
		dropmenuobj.style.top = topPos(obj, obj.clientHeight - -17) + "px";
	}

	return clickreturnvalue();
}

function clickreturnvalue() {
	if (ie4 || ns6) {
		return false;
	} else {
		return true;
	}
}

function contains_ns6(a, b) {
	while (b.parentNode) {
		if ((b = b.parentNode) == a) {
			return true;
		}
	}
	
	return false;
}

function dynamichide(e) {
	if (ie4 && !dropmenuobj.contains(e.toElement)) {
		hideSubMenu();
	} else if (ns6 && e.currentTarget != e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget)) {
		hideSubMenu();
	}
}

function hidemenu(e) {
	if (typeof dropmenuobj != "undefined") {
		if (ie4 || ns6) {
			dropmenuobj.style.visibility = "hidden";
			if(currentObj != undefined) {
				currentObj.className = "class";
			}
		}
	}
}

function hideSubMenu() {
	if (ie4 || ns6) {
		delayhide = setTimeout("hidemenu()", hideDelay);
	}
}

function clearhidemenu() {
	if (typeof delayhide != "undefined") {
		clearTimeout(delayhide);
	}
}

document.onclick = hidemenu;

// Find absolute left position of the object in the document
function leftPos(obj, diff) {
	var leftCoord = 0;
	
	while(obj) {
	   leftCoord += obj.offsetLeft;
	   obj = obj.offsetParent;
	}
	
	return leftCoord + diff;
}

// Find absolute top position of the object in the document
function topPos(obj, diff)
{
	var topCoord = 0;
	
	while(obj) {
	   topCoord += obj.offsetTop;
	   obj = obj.offsetParent;
	}
	
	return topCoord + diff;
}