// Integer used to track the total number of menu groups.
var iGroupCount=0;
var iGroupOnCount=0;
var iGroupTop = 167;
var iMenuTop = 50;
var iMenuWidth = 365;
var sInnerHTML = "";

// Integer used to track the total number of menu items.
var iItemCount=0;

// Object placeholder for the srcElement of an event.
var oWorkItem="";

// Boolean used to monitor the overall status of the menu.
var bOpenMenu=false;

// Integer used to specify the location of the History group.
var iHistoryID=-1;

// Additional information for sample menu item action.
//var sScratchInclude='<div component="scratch" class=scratchx>DHTML Menu Sample #1</div>';

// When the body loads, setup intial settings.
function fnInit(){
	var oTable;
	var iMenuCount;
	// Add in menu groups and menu items.
	iMenuCount=1;
	fnAddMenuGroupEx("top_nav_about_on.gif", "top_nav_about_off.gif", 100, "'none'");
	fnAddMenuItem(iMenuCount,"Company Profile","'/corporate/GenericPage.aspx?contentid=101'", 125);
	fnAddMenuItem(iMenuCount,"Management Team","'/corporate/GenericPage.aspx?contentid=103'", 125);
	fnAddMenuItem(iMenuCount,"Employment Openings","'/corporate/GenericPage.aspx?contentid=102'", 125);

	iMenuCount ++;
	fnAddMenuGroupEx("top_nav_retail_on.gif", "top_nav_retail_off.gif", 75, "'none'");
	fnAddMenuItem(iMenuCount,"Scan Genius","'http://www.ScanGenius.com'", 125);
	fnAddMenuItem(iMenuCount,"Web Genius","'http://www.WebGeniusDemo.com'", 125);
	fnAddMenuItem(iMenuCount,"POS Systems","'http://www.LoyaltyGenius.com'", 125);


	iMenuCount ++;
	fnAddMenuGroupEx("top_nav_supplier_on.gif", "top_nav_supplier_off.gif", 75, "'none'");
	fnAddMenuItem(iMenuCount,"Electronic Ordering","'http://www.livingnaturally.com/corporate/factsheet/OrderSubmission_featuresheet.pdf'", 150);
	fnAddMenuItem(iMenuCount,"Sales Genius","'http://www.SalesGeniusDemo.com'", 150);
	fnAddMenuItem(iMenuCount,"Promo Genius","'http://www.PromoGeniusDemo.com'", 150);
	fnAddMenuItem(iMenuCount,"Data Genius","'/corporate/GenericPage.aspx?contentid=304'", 150);

	iMenuCount ++;
	fnAddMenuGroupEx("top_nav_testimonial_on.gif", "top_nav_testimonial_off.gif", 75, "'none'");
	fnAddMenuItem(iMenuCount,"Living Naturally","'/corporate/GenericPage.aspx?contentid=401'", 125);
	fnAddMenuItem(iMenuCount,"Scan Genius","'/corporate/GenericPage.aspx?contentid=402'", 125);
	fnAddMenuItem(iMenuCount,"Web Genius","'/corporate/GenericPage.aspx?contentid=403'", 125);

	iMenuCount ++;
	fnAddMenuGroupEx("top_nav_news_on.gif", "top_nav_news_off.gif", 75, "'none'");
	fnAddMenuItem(iMenuCount,"Press Releases","'/corporate/GenericPage.aspx?contentid=501'", 125);
	fnAddMenuItem(iMenuCount,"Industry News","'/corporate/GenericPage.aspx?contentid=503'", 125);

	iMenuCount ++;
	fnAddMenuGroupEx("top_nav_partners_on.gif", "top_nav_partners_off.gif", 75, "'none'");
	fnAddMenuItem(iMenuCount,"Strategic Alliances","'/corporate/GenericPage.aspx?contentid=601'", 125);
	fnAddMenuItem(iMenuCount,"Retail Customers","'/corporate/GenericPage.aspx?contentid=602'", 125);
	fnAddMenuItem(iMenuCount,"Supplier Customers","'/corporate/GenericPage.aspx?contentid=603'", 125);


	fnAddMenuGroupEx("top_nav_contact_on.gif", "top_nav_contact_off.gif", 75, "'/corporate/GenericPage.aspx?contentid=700'");

}

function fnAddMenuGroupEx(sImageOn, sImageOff, iWidth, sMenuAction)
{
	iGroupCount++;
	// Add the new menu group (label and drop down menu) to the menu contained
			document.getElementById('oMenuContainer').innerHTML +=  '<span groupid=' 
													  + iGroupCount 
														+ ' component="menuimagespan" id=oLabel' 
														+ iGroupCount 
														+ ' onclick="fnMouseClick(' + sMenuAction + ')"'
														+ ' >' 
														+ '<img id=oImage' + iGroupCount 
														+ ' groupid=' + iGroupCount 
														+ ' height="24 px"'
														+ ' component=image'
														+ ' onmouseover="fnMouseOverImage(this,'+ iGroupCount +  ')"'
														+ ' onmouseout="fnMouseOutImage()"'
														+ ' src="/corporate/graphics/' + sImageOff + '">' 
														+ '</span>'
	
	
			document.getElementById('oMenuDropDown').innerHTML +='<div id=oGroup' + iGroupCount 
										+ ' component=groupdiv' 
										+ ' onmouseout="fnMouseOutBackDiv()"</div>';
										//+ ' onmouseout="fnMouseOutBackDiv()"'
										//+ ' style="BACKGROUND-COLOR: blue;"</div>';

//#729783


	// Refer to the new label and group using the iGroupCount.

	var sID = 'oLabel' + iGroupCount
	var oNewLabel=document.getElementById(sID);


	sID = 'oGroup' + iGroupCount
	var oNewGroup=document.getElementById(sID);

	// Align the label and group with the rest of the menu labels and groups.
	fnAlign(oNewLabel,oNewGroup, iWidth);

}


// Align the menu labels and groups with each other.
function fnAlign(oLabel,oGroup, iWidth){

	var iLeft=0;
	var oTable;
	oGroup.style.position="absolute";
	oGroup.style.top=iGroupTop;
//	iLeft = (document.getElementById('tblHdr').offsetLeft + oLabel.offsetLeft + 2);
//	oGroup.style.left=iLeft;
	oGroup.style.display="none";
	oGroup.style.width=iWidth;
}


// Add new menu items.  The iGroupID is 1 - #Menu Labels.  The sItemName is what will be displayed.  sItemAction is a function call that will be made when the item is clicked.  sItemImage is an optional image to go with the menu item.  The source is hard coded, so will have to be changed to your favorite graphics directory.  Image extensions are hard coded as ".gif".
function fnAddMenuItem(iGroupId,sItemName,sItemAction, iWidth){
	// Increment the total number of menu items.
	iItemCount++;
	// Set the temporary image source to nothing.
	var sID = 'oGroup' + iGroupId
	var oGroup=document.getElementById(sID);
		// Add the new menu item to the menu group.
		oGroup.innerHTML= oGroup.innerHTML + '<div groupid=' + iGroupId 
												+ ' component="menuitemspan"' 
												+ ' id="oItem' + iItemCount + '"' 
												+ ' itemid=' + iItemCount 
												+ ' onclick="fnMouseClick(' + sItemAction + ')"'
												+ ' onmouseover="fnMouseOverSubMenu(this)"'
												+ ' onmouseout="fnMouseOutSubMenu(this)"'
												+ ' class="menudropdown"'
												+ ' style="width:' + iWidth + '"'
												+ ' >&nbsp;&nbsp;&nbsp;&nbsp;' + sItemName 
												+ ' </div>';
		// Assign a variable to the new menu item.

	
}


function fnMouseOverImage(oWorkItem, iGroup)
{
	var iStartLeft;
	var iLeftIncrement = 0;
	var oGroup;
	var oItem;
	var sID;

	//Need to shut down all images
	if (bOpenMenu==true)
		HideAllSubMenus();

	oWorkItem.src = oWorkItem.src.replace('_off.gif', '_on.gif');
	iStartLeft = document.getElementById('ocellMenuContainer').offsetLeft + document.getElementById('tblHdr').offsetLeft

	if (iGroup !=7 )
	{
		sID = 'oGroup' + iGroup;
		oGroup = document.getElementById(sID);


		sID = 'oLabel' + iGroup;
		oLabel = document.getElementById(sID);

		oGroup.style.position="absolute";
		oGroup.style.left=iStartLeft + oLabel.offsetLeft;
		oGroup.style.display="block";
	}
	bOpenMenu=true;
}

function fnMouseOutImage()
{
	var iGroup;
	var oGroup;

}

function fnMouseOverSubMenu(oWorkItem)
{
	//oWorkItem=event.srcElement;
	oWorkItem.style.backgroundColor = "#666666";

}

function fnMouseOutSubMenu(oWorkItem)
{
	//oWorkItem=event.srcElement;
	oWorkItem.style.backgroundColor = "#739783";
}

function fnMouseOutBackDiv()
{
	oWorkItem=event.srcElement;
}

function fnMenuClick()
{
	oWorkItem=event.srcElement;
	if (!oWorkItem.component)
	{
		HideAllSubMenus();
		//oMenuContainer.releaseCapture()
	}

}

function HideAllSubMenus()
{
	var iGroup;
	var oGroup;
	var oLabel;
	var oImage;
	var sID

	//alert("start of hide all sub");
	for (iGroup=1;iGroup < iGroupCount+1; iGroup ++)
	{
			sID = 'oGroup' + iGroup;
			oGroup = document.getElementById(sID);
			oGroup.style.display="none";
			sID = 'oLabel' + iGroup;
			oLabel = document.getElementById(sID);

			oImage = oLabel.firstChild;
			if (oImage.src.search('_on.gif') > 0)
			{
				oImage.src = oImage.src.replace('_on.gif', '_off.gif');
			
			}
	}
	bOpenMenu=false;
}

function fnBodyMouseOver()
{
	oWorkItem=event.srcElement;
	if ((!oWorkItem.component) && (bOpenMenu==true))
	{
		HideAllSubMenus();
	}
}

function fnMouseClick(sPage)
{
	if (sPage.indexOf("http://") == -1)
	{
		if (sPage!= "none")
			window.location = sPage;
	}
	else
	{
		HideAllSubMenus();
		window.open(sPage, "ChildWindow");
	}

}


