// JScript source code

var objHyperlinkCollection;							// store a collecion of Menu Spans

function initializeTopMenu() 
{
	// Menu Span Style
	
	// get the Main Span "topMenu"
	mainSpan = document.getElementById("topMenu");

	if(mainSpan != null)
	{
		// get a collection of menus (Spans)
		objHyperlinkCollection = mainSpan.getElementsByTagName("a");
		
		// Iterate through all collected Spans i.e. objHyperlinkCollection
		for (var index = 0; index < objHyperlinkCollection.length; index++)
		{
			// objHyperlink is the current span during iteration 
			var objHyperlink = objHyperlinkCollection[index];
			
			// Assign the click event to every Menu Header
			//  objHyperlink.childNodes.item(0) = Div 1 = Menu Header
			
			objHyperlink.onclick = topMenuHandler;
			
			var spanUrl = objHyperlink.href;
			var indexOfLastDot = spanUrl.lastIndexOf(".");
			
			if(indexOfLastDot >= 0)
			{
				spanUrl = spanUrl.substring(0, indexOfLastDot);
			}
			
			var url = window.location.href.toLowerCase();
			var foundAtIndex = url.indexOf(spanUrl.toLowerCase());
	
			//alert("windows url: " + url + "   spanurl: " + objHyperlink.href + " found at" + foundAtIndex);
			if(foundAtIndex == 0)
			{
				objHyperlink.parentNode.className = "menulink1";
				objHyperlink.className = "menulink";
			}
			else if(url.indexOf('buyonline') > 0  && spanUrl.indexOf('store') > 0)
			{
				objHyperlink.parentNode.className = "menulink1";
				objHyperlink.className = "menulink";
			}
		}
		
		
	}
}

function topMenuHandler()
{
	
	for (var index = 0; index < objHyperlinkCollection.length; index++)
	{
		var objHyperlink = objHyperlinkCollection[index];
		//alert("old: " +  objHyperlink.href + " :: " +  objHyperlink.id + " :: " + objHyperlink.parentNode.className);
		objHyperlink.parentNode.className = "menulink";
		objHyperlink.className = "menulink";
		//alert("new: " +  objHyperlink.href + " :: "+ objHyperlink.parentNode.className);
	}	
	
	this.parentNode.className = "menulink1";
	this.className = "menulink";
	
}

	