/* Misc DOM Functions------------------------------*/

// this function tries three different methods to get the correct element
// using its id.  adding an else at the end could add a failure condition/flag.
function returnItem(id) {
	if (document.getElementById) { return document.getElementById(id); }
	else if (document.all) { return document.all [id]; }
	else if (document.layers) { return document.layers[id]; }
}

/* Menu Functions------------------------------*/
var timerID = null;
var timerRunning = false;
var delay = 400;
var litItem; 
var stickyItem;
var mainNavContainer="mainNav";
var currentFlag="here";

// this function returns the id of the top level <li> with class=currentFlag
function findCurrentItem() {
	menu = returnItem(mainNavContainer);
	for (i=0; i<menu.getElementsByTagName("LI").length; i++) {
		menuItem = menu.getElementsByTagName("LI")[i];
		if (menuItem.className.search(currentFlag) > -1) {
			return menuItem.id;
		}
	}
	// if we get here, we haven't found any elements flagged as current
	return false;
}

// this function sets menu items to hide by changing their class
function turnOffItem(id) {
	if (id == 'none') return; 
	e = returnItem(id);
	// if element's class is set to "on", change it to "off", otherwise append "off" to class 
	if(e!=null)
	{
		e.className.search(currentFlag) > -1 ? e.className = e.className.replace(currentFlag, "off") : e.className += " off";
	}
}

// this function makes menu items visible by changing their class
function turnOnItem(id) {
	if (id == 'none') return;
	e = returnItem(id);
	// if element's class is set to "off", change it to "on", otherwise append "on" to class 
	if(e!=null)
	{
		e.className.search("off") > -1 ? e.className = e.className.replace("off", currentFlag) : e.className += " "+currentFlag;
	}
}

// this function manages the calls to the turnOnItem and turnOffItem functions.
function setlitItem(id) {
	if (timerRunning) stopTimer();
	turnOffItem(litItem);
	litItem = id;
	turnOnItem(id);
}

// this is the function called by the onmouseover event listener; it builds in the pause before calling setLitItem
// which in turn makes submenus appear and dissapear.
function startTimer() 
{
	try
	{
		id=(typeof(arguments[0])=='object')?this.id:arguments[0]; // if call was made with id provided, use that
		if (timerRunning) stopTimer();
		if (id == litItem) return;
		timerRunning = true;
		timerID = setTimeout('setlitItem(\''+id+'\')', delay);//.replace('main', 'sub')
	}
	catch(ex)
	{
	}
}

// this function stops the timer.
function stopTimer() {
	clearTimeout(timerID);
	timerRunning = false;
}


// this function is called by the onmouseout event listener; it makes sure that we reset back to the stickyItem
// once our mouse is away from the menu
function resetItems() 
{
	try
	{
		if (timerRunning) stopTimer();
		if (litItem != stickyItem) {
			startTimer(stickyItem);
		}
	}
	catch(ex)
	{
	}
}

// sets the vars for the current top item and its sub-menu (which are 'sticky', i.e., they come
// back up after we mouse off of the menu), then sets the styles for the current items within it.
function menuInit() {
	if (findCurrentItem()) {
		litItem = stickyItem = findCurrentItem();
	}
	else {
		litItem = stickyItem = 'none';
	}
}


// Functions to deal with the wishlist and collection list logins
function jumpToWishlist()
{
	window.location.href="/myaccount/wishlist.aspx";
}
function jumpToCollections()
{
	window.location.href="/myaccount/collection.aspx";
}


function submitStoreLocator()
{
	var subobj=document.getElementById('Head1_txtAddress')
	window.location='/storelocator/mappoint.aspx?address=' + subobj.value;
}

function openStoreLocator(div)
{
	showHide('dropDownContent');
	//displayOverlay(div, 'dropDownContent');
	// set the focus on the textbox
	var subobj=document.getElementById('Head1_txtAddress')
	subobj.focus();
	//return true;
}

function showHide(d) {
	if(d.length < 1) {
		return;
		
	}
	if(document.getElementById(d).style.display == "none") {
		document.getElementById(d).style.display = "";
	}
	else {
		document.getElementById(d).style.display = "none";
	}
}
