
//BgxMenu class

function BgxMenu()
{
	this["menuList"] = new Object();
}


BgxMenu.prototype.Add = function(pPath,pTitle,pPage)
{
	var menuItem = new Object();
	menuItem.title = pTitle;
	menuItem.page =  pPage;
	menuItem.children = new Object();
	if (pPath.indexOf("/") == -1)
	{
		this.menuList[stripWhite(pPath)] = menuItem;
	}
	else
	{
		var path = pPath.split("/");
		var parent = this.menuList[stripWhite(path[0])];
		for (var i = 1; i < path.length - 1; ++i)
		{	
			parent = parent.children[stripWhite(path[i])]
		}		
		parent.children[path[path.length - 1]] = menuItem;
	}
}

function stripWhite(stringVal)
{
	return stringVal.split(" ").join("");
}

//menu instance
var bgxMenu = new BgxMenu();
var thisPage;
var thisPageChildren;
var thisPageSiblings = new Object();
var menuHtml;
var breadCrumbs;
var pageMenu;
var titlePage;
var pageTitle;
var hasChildren = false;

function writeTopMenu()
{
	menuHtml = '<table border="0" cellspacing="0" cellpadding="0"><tr class="zz_mainmenuTR">';
	
	for (var mItem in bgxMenu.menuList)
	{
	
		menuHtml += '<td class="zz_mainMenuTD" ><a class="zz_menuItem" href="' + bgxMenu.menuList[mItem].page + '">' + bgxMenu.menuList[mItem].title + 't</a></td>';
	}
	menuHtml += '</tr></table>';
}

function writeTopMenuPullDown()
{
	var pullDowns = "";
	menuHtml = '<DIV ID="ddMenuLayer" STYLE="position:relative; left:0px; top: 0px;  width:100%; z-index:1">'; 
  	menuHtml += '<DIV ID="divMenuBar" ONMOUSEOVER="if (document.all) MenuBar_over();" ONMOUSEOUT="if (document.all) MenuBar_out();" ONSELECTSTART="return false;">';
	
	menuHtml += '<table border="0" cellspacing="0" cellpadding="0" id="tblMenuBar"><tr class="zz_mainmenuTD">';
	
	for (var mItem in bgxMenu.menuList)
	{
		menuHtml += '<td nowrap class="clsMenuBarItem" id="tdMenuBarItem' + mItem  + '"><a href="' + bgxMenu.menuList[mItem].page + '">' + bgxMenu.menuList[mItem].title + getDropDownImage(bgxMenu.menuList[mItem]) +'</a></td>';
		pullDowns += getPullDown(bgxMenu.menuList[mItem],mItem);

	}
	menuHtml += '<td width="100%" id="tdMenuBarItemSpacer">&nbsp;</td>';
	menuHtml += '</tr></table>';
	menuHtml += '</DIV>';
	menuHtml += pullDowns;
	menuHtml += '</DIV>';		
	
}

function getDropDownImage(pItem)
{
	if (!document.all) return "&nbsp;&nbsp;";
	for (var pdItem in pItem.children)
	{
		return '<img src="images/dropDown.gif" border="0"/>' ;
	}
	return "";
}

function getPullDown(pItem,pId)
{
	var pullDown = "";
	var headerCreated = false;
	for (var pdItem in pItem.children)
	{
		if (!headerCreated)
		{
			pullDown = '<DIV CLASS="clsMenu" ONMOUSEOUT="Menu_out();" ID="divMenu' + pId + '">';
    			//pullDown += '<DIV CLASS="clsMenuSpacer"></DIV>';
			headerCreated = true;
		}
    		pullDown += '<DIV nowrap CLASS="clsMenuItem" ><A HREF="' + pItem.children[pdItem].page  + '">' + pItem.children[pdItem].title  + '</A> </DIV>';
  	}
	if (headerCreated) pullDown += '</DIV>';	
	return pullDown ;
}

function writeBreadcrumbs()
{
	thisPage = window.location.toString();
	if (thisPage.indexOf("/") > -1)
	{
		
		thisPage = thisPage.substring(thisPage.lastIndexOf("/") +1,thisPage.length);
	}
	else
	{
		
		thisPage = thisPage.substring(thisPage.lastIndexOf("\\") +1,thisPage.length);
	}
	thisPage = thisPage.split("#")[0];
	breadCrumbs = ""; 
	for (var mItem in bgxMenu.menuList)
	{
		titlePage = bgxMenu.menuList[mItem];
		if (thisPage == "") thisPage = bgxMenu.menuList[mItem].page;
		//write homepage
		if (breadCrumbs == "")
		{
			breadCrumbs += '<a href="' + bgxMenu.menuList[mItem].page + '">' + bgxMenu.menuList[mItem].title + '</a>';
			
			if (thisPage == bgxMenu.menuList[mItem].page)
			{
				thisPageChildren = bgxMenu.menuList[mItem].children;
				titlePage = bgxMenu.menuList[mItem];
				break;
			} 
		}
		var childFound  = checkChildren(bgxMenu.menuList[mItem]);
		if (typeof childFound == "string")
		{
			breadCrumbs = breadCrumbs + childFound;
			break;
		}
	}
	var indicatorImg = (thisPage == titlePage.page) ? '<img src="images/indicator.gif" border=0/>' : '<img src="images/spacer.gif" border=0 width=6/>';
	
	pageTitle = '<table><tr><td>' + indicatorImg + '</td><td>';
	pageTitle += "<a href='" + titlePage.page + "' class='zz_pageTitleA'>" + titlePage.title + "</a>";
	pageTitle += '</td></tr></table>';
	if(thisPage == titlePage.page) 
	{
		thisPageTitle = titlePage.title;
	}
	
	//pageTitle = titlePage.title;
}

function checkChildren(pItem)
{
	if (thisPage == pItem.page)
	{			
		//update thisPageChildren only when this page has children
		for  (var child in pItem.children)
		{
			titlePage = pItem;
			thisPageChildren = pItem.children;
			hasChildren = true;
			break;
		}	
		return ' > <a  href="' + pItem.page + '">' + pItem.title + '</a>';
		
	}
	
	for (var xItem in pItem.children)
	{		
		thisPageChildren = pItem.children;
		titlePage = pItem;
		var childFound  = checkChildren(pItem.children[xItem]);
		if (typeof childFound == "string")
		{
			return ' > <a href="' + pItem.page + '">' + pItem.title + '</a>' + childFound;
		}		
	}
	return false;
}

function writePageMenu()
{
	
	pageMenu = '<table width="100%" border="0" cellspacing="0" cellpadding="4" class="zz_menuTopSpacer">';
	//pageMenu += '<tr><td>&nbsp;</td><td ></td></tr>';
	//for (var mItem in thisPageChildren)
	for (var mItem in titlePage.children)
	{
		var indicatorImg = (!hasChildren && thisPage == thisPageChildren[mItem].page) ? '<img src="images/indicator.gif" border=0/>' : '<img src="images/spacer.gif" border=0 width=6/>';
		if(thisPage == thisPageChildren[mItem].page) 
		{
			thisPageTitle = thisPageChildren[mItem].title;
		}
		pageMenu += '<tr><td>' + indicatorImg + '</td><td>';
		pageMenu += '<a class="zz_menuItem" href="' + thisPageChildren[mItem].page + '">' + thisPageChildren[mItem].title + '</a></td></tr>';
	}
	pageMenu += '</table>';
	
}

function createMenu()
{
	//writeTopMenu();
	writeTopMenuPullDown()
	writeBreadcrumbs();
	writePageMenu();
}

function writeMenu()
{
	document.all.topMenu.innerHTML = menuHtml;
	document.all.breadCrumbs.innerHTML = breadCrumbs;
	document.all.pageMenu.innerHTML = pageMenu;
}
//window.onload = writeMenu;


// DDMenu -----------------------------------------------------------------------

  var eOpenMenu = null;
  function OpenMenu(eSrc,eMenu){
    eMenu.style.left = eSrc.parentElement.offsetLeft + divMenuBar.offsetLeft + 1;
    eMenu.style.top = divMenuBar.offsetHeight + divMenuBar.offsetTop;
    eMenu.style.visibility = "visible";
    eOpenMenu = eMenu;
  }

  function CloseMenu(eMenu){
    eMenu.style.visibility = "hidden";
    eOpenMenu = null;
  }

  function MenuBar_over(){
    var eSrc = window.event.srcElement;
    if ("A" == eSrc.tagName.toUpperCase()){
      var eMenu = document.all[eSrc.parentElement.id.replace("tdMenuBarItem","divMenu")];
      if (eOpenMenu && eOpenMenu != eMenu){
        CloseMenu(eOpenMenu);}
      if (eMenu){
		  OpenMenu(eSrc,eMenu);}
    }
  }

  function MenuBar_out(){
    var eTo = window.event.toElement;
    if (eOpenMenu && eTo && !eOpenMenu.contains(eTo) && "tblMenuBar" != eTo.id){
      CloseMenu(eOpenMenu)}
	}

  function Menu_out(){
    var eSrc = window.event.toElement;
    if (eOpenMenu && !eOpenMenu.contains(eSrc) && !divMenuBar.contains(eSrc)){
      CloseMenu(eOpenMenu)}
	}

