document.write('<link href="css/javascript.css" rel="stylesheet" type="text/css" media="all" />');

var productThumbClicked = false;
var bIsRunning = false;
var timerID = 0;

startList = function() {
	navRoot = document.getElementById("main_menu");
	for (i=0; i<navRoot.childNodes.length; i++) {
		node = navRoot.childNodes[i];
		if (document.all&&document.getElementById) {
			if (node.nodeName == "LI") {
				node.onmouseover = function() {
					this.className += " over";
				}
				node.onmouseout = function() {
					this.className = this.className.replace(" over", "");
				}
			}
		}
		for (j=0; j<node.childNodes.length; j++)
		{
			DivNode = node.childNodes[j];
			if (DivNode.nodeName == "DIV") {
				DivNode.style.width = node.offsetWidth + 'px';
			}
		}
	}
}
window.onload = startList;
mainPanelId = null;
function DisplayMainPanelClick(GroupID, CategoryID, mouseover) {
	//productThumbClicked = (!mouseover) ? true : false;
	mainPanelId = GroupID;
	try
	{
		showMainPanel(GroupID,document.getElementById(GroupID).innerHTML);		
	}
	catch (err)
	{
		var url="remote/rem_GetFeaturedProduct.asp"
		var sValue = "groupid=" + GroupID + "&CategoryId=" + CategoryID
		var myConn = new XHConn()
		if (!myConn) alert("XMLHTTP not available. Please upgrade your browser.")

		var fnWhenDone = function (oXML) {
			response = oXML.responseXML.documentElement;
			thisResult = response.getElementsByTagName("listhtml")[0].firstChild.data;
            showMainPanel(GroupID, thisResult );
		}
		myConn.connect(url, "POST", sValue, fnWhenDone)

		return false;
	}
}

function showDetails ( contentId, content, divToUpdateId ) {
    createCachedElement(contentId, content);		
    if ( mainPanelId == contentId ) {
        document.getElementById(divToUpdateId).innerHTML = content;
    }
}

function showMainPanel ( contentId, content ) {
    showDetails(contentId, content, "topprodmiddlecont");		
}

function showMainProduct ( contentId, content ) {
    showDetails(contentId, content,"topprodmiddleitem");
}

function createCachedElement ( divId, content ) {
    if ( document.getElementById(divId) ) return;
    var cached = document.createElement ( 'div' );
    cached.id = divId;
	cached.innerHTML = thisResult;
	cached.style.display = 'none';
	document.body.appendChild(cached);	
}

function DisplayMainPanel(GroupID, CategoryID, callback) {
    
	try
	{
		if (!productThumbClicked)
		{
		    if ( !callback ) mainPanelId = GroupID;
			showMainPanel(GroupID,document.getElementById(GroupID).innerHTML);
		}
	}
	catch (err)
	{
		if (!bIsRunning)
		{
			bIsRunning = true
			var url="remote/rem_GetFeaturedProduct.asp"
			var sValue = "groupid=" + GroupID + "&CategoryId=" + CategoryID;
			var myConn = new XHConn();
			if (!myConn) alert("XMLHTTP not available. Please upgrade your browser.")

			var fnWhenDone = function (oXML) {
				//alert(oXML.responseText)
				response = oXML.responseXML.documentElement;

				thisResult = response.getElementsByTagName("listhtml")[0].firstChild.data;
				
				showMainPanel(GroupID,thisResult);
				
				bIsRunning = false;
			}
			myConn.connect(url, "POST", sValue, fnWhenDone)
		} else {
			setTimeout('DisplayMainPanel('+GroupID+','+ CategoryID+',true)', 500);
		}
		return false;
	}
}

function DisplayProductPanelClick(GroupID, CategoryID, mouseover) {
	//productThumbClicked = (!mouseover) ? true : false;
	try
	{
	    mainPanelId = GroupID;
	    showMainProduct(GroupID,document.getElementById(GroupID).innerHTML);
	}
	catch (err)
	{
		var tmpArray = GroupID.split(":");
		groupID = tmpArray[1];
		origGroupId = tmpArray[0];

		var url="remote/rem_GetFeaturedProductNested.asp"
		var myConn = new XHConn()
		if (!myConn) alert("XMLHTTP not available. Please upgrade your browser.")

		var fnWhenDone = function (oXML) {
			//alert(oXML.responseText)
			response = oXML.responseXML.documentElement;

			// send the result back to the page
			thisResult = response.getElementsByTagName("listhtml")[0].firstChild.data;
			//alert (thisResult);

			showMainProduct(GroupID, thisResult);
		}
		var postData = "origgroupid="+ origGroupId +"&groupid=" + groupID + "&categoryId="+ (CategoryID || "");		
		myConn.connect(url, "POST", postData, fnWhenDone);

		return false;
	}
}

function DisplayProductPanel(GroupID, CategoryID) {
	try
	{
		if (!productThumbClicked)
		{
		    mainPanelId = GroupID;
			showMainProduct(GroupID,document.getElementById(GroupID).innerHTML);
		}
	}
	catch (err)
	{
		var tmpArray = GroupID.split(":");
		groupID = tmpArray[1];
		origGroupId = tmpArray[0];
		var url="remote/rem_GetFeaturedProductNested.asp"
		var myConn = new XHConn()
		if (!myConn) alert("XMLHTTP not available. Please upgrade your browser.")

		var fnWhenDone = function (oXML) {
			//alert(oXML.responseText)
			response = oXML.responseXML.documentElement;

			// send the result back to the page
			thisResult = response.getElementsByTagName("listhtml")[0].firstChild.data;
			//alert (thisResult);
			
			showMainProduct(GroupID,thisResult);
		}
		myConn.connect(url, "POST","origgroupid="+ origGroupId +"&groupid=" + groupID + "&categoryId="+ CategoryID, fnWhenDone)

		return false;
	}
}

function displayProduct(groupId, CategoryId, mouseover)
{
	if (!mouseover)
	{
		productThumbClicked = true;
	}

	var url="remote/rem_GetFeaturedProduct.asp"
	var myConn = new XHConn()
	if (!myConn) alert("XMLHTTP not available. Please upgrade your browser.")

	var fnWhenDone = function (oXML) {
		//alert(oXML.responseText)
		response = oXML.responseXML.documentElement;

		// send the result back to the page
		thisResult = response.getElementsByTagName("listhtml")[0].firstChild.data;
		//alert (thisResult);

		document.getElementById("lge_product").innerHTML = thisResult;
	}
	myConn.connect(url, "POST","groupid=" + groupId + "&CategoryId=" + CategoryId , fnWhenDone)

	return false;
}

function displayProductMouseOver(groupId, CategoryId)
{
	if (!productThumbClicked)
	{
		displayProduct(groupId, CategoryId, true)
	}
}

function displayNestedProduct(origGroupId, GroupId, CategoryId, mouseover)
{
	if (!mouseover)
	{
		productThumbClicked = true;
	}

	var url="remote/rem_GetFeaturedProductNested.asp"
	var myConn = new XHConn()
	if (!myConn) alert("XMLHTTP not available. Please upgrade your browser.")

	var fnWhenDone = function (oXML) {
		//alert(oXML.responseText)
		response = oXML.responseXML.documentElement;

		// send the result back to the page
		thisResult = response.getElementsByTagName("listhtml")[0].firstChild.data;
		//alert (thisResult);

		document.getElementById("lge_product").innerHTML = thisResult;
	}
	myConn.connect(url, "POST","origgroupid="+ origGroupId +"&groupid=" + GroupId + "&categoryId="+ CategoryId, fnWhenDone)

	return false;
}

function displayNestedProductMouseOver(origGroupId, GroupId, CategoryId)
{
	if (!productThumbClicked)
	{
		displayNestedProduct(origGroupId, GroupId, CategoryId, true)
	}
}