// main menu x positioning See also xAxisPos below
 var navXOffset = 124;
// main menu height
 var tabHeight = 26;
 var activeTabHeight = 26;
// sub-menu y positioning
 var tabYOffset = 101;
 var itemHeight = 21;
 var itemYOffsetActive = tabYOffset + tabHeight + 3;
 var itemYOffsetInActive = tabYOffset + tabHeight + 3;
 var itemsMenuWidth = 780;
 var tabs = new Array();
 var activeItemClickable;
 var chanLength;
 
// Global variables
var timeout ;
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);

function updateMenu(number) {
   clearTimeout(timeout);
   if (number == activeTab) {
      for (var i=0; i<tabs.length; i++) {
         if ((i+1) == number) {
            myLayer = "activeRefreshTab" + i;
            hide(myLayer);
            myLayer = "items" + i;
            show(myLayer);
         } else {
            myLayer = "browseTab" + i;
            hide(myLayer);
            myLayer = "items" + i;
            hide(myLayer);
         }
      }
   } else {
      for (var i=0; i<tabs.length; i++) {
         if ((i+1) == activeTab) {
            myLayer = "activeRefreshTab" + i;
            show(myLayer);
            myLayer = "items" + i;
            hide(myLayer);
         } else if ((i+1) == number) {
            myLayer = "browseTab" + i;
            show(myLayer);
            myLayer = "items" + i;
            show(myLayer);
         } else {
            myLayer = "browseTab" + i;
            hide(myLayer);
            myLayer = "items" + i;
            hide(myLayer);
         }
      }
   }
}

function resetMenu() {
   timeout = setTimeout('updateMenu(' + activeTab + ')', 1750);
}

function selectNav(number) {
   activeTab = number;
   updateMenu(number);
}

function show(id) {
if (ie4) {
  document.all[id].style.visibility = "visible";
 }
 else if (ie5 || ns6) {
  if (document.getElementById(id))
    document.getElementById(id).style.visibility = "visible";
 }
}

function hide(id) {
if (ie4) {
  document.all[id].style.visibility = "hidden";
 }
 else if (ie5 || ns6) {
  if (document.getElementById(id))
    document.getElementById(id).style.visibility = "hidden";
 }
}

function Tab(number, width, text, url, itemsXOffset, webroot) {
   this.number = number;
   this.url = url;
   this.width = width;
   this.text = text;
   this.webroot = webroot;
   var temp = navXOffset;
   if (number > 0 ) {
      for (var i=0; i<number; i++) {
         temp += (tabs[i].width)+1;
      }
   }
   this.XPos = temp;
   this.itemsXOffset = itemsXOffset;
   this.items = new Array();
   
   // toggle the visibility based on whether there is a secondary nav
   	if (this.number == activeTab-1) {
		var visibilityState = "visible";
	} else {
	 	var visibilityState = "hidden";
	}
   
	 var ntabYOffset = (tabYOffset + 1);
   // html for activeTab
   this.activeTab = '<div id="activeTab' + this.number + '" class="activeTab" style="position:absolute; z-index:50; top:' + tabYOffset + 'px; left:' + this.XPos + 'px; width:' + this.width + 'px; height:' + tabHeight + 'px">';
   this.activeTab += '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="activeTab" height="' + activeTabHeight + '" width="' + this.width +'">';
   this.activeTab += '<img src="' + this.webroot + 'images/aatab_' + this.number + '_on.gif" alt="' + this.text + '" border="0" width="' + (this.width+1) + '" height="26">';
   this.activeTab += '</td></tr></table>';
   this.activeTab += '</div>';

   // html for activeRefreshTab
   this.activeRefreshTab = '<div id="activeRefreshTab' + this.number + '" class="activeRefreshTab" style="position:absolute; top:' + ntabYOffset + 'px; left:' + this.XPos + 'px; z-index:100; visibility:hidden; width:' + this.width + 'px; height:' + tabHeight + 'px;">';
   this.activeRefreshTab += '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="activeRefreshTab" height="' + tabHeight + '" width="' + this.width +'">';
   this.activeRefreshTab += '<a onMouseOver="updateMenu(' + ((this.number)+1) + '); return false;" onMouseOut="resetMenu(); return false; " href="' + this.url + '" target="_top"><img src="' + this.webroot + 'images/aatab_' + (this.number+1) + '_on.gif" alt="' + this.text + '" border="0" width="' + (this.width+1) + '" height="26"></a>';
   this.activeRefreshTab += '</td></tr></table>';
   this.activeRefreshTab += '</div>';

   // html for inactiveTab
   this.inactiveTab = '<div id="inactiveTab' + eval(this.number) + '" class="inactiveTab" style="position:absolute; z-index:50; top:' + tabYOffset + 'px; left:' + this.XPos + 'px; height:' + tabHeight + 'px; width:' + this.width + 'px">';
   this.inactiveTab += '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="inactiveTab" height="' + tabHeight + '" width="' + this.width +'">';
   this.inactiveTab += '<a onMouseOver="updateMenu(' + ((this.number)+1) + '); return false;" onMouseOut="resetMenu(); return false; " href="' + this.url + '" class="inactiveTabLink" target="_top"><img src="' + this.webroot + 'images/aatab_' + (this.number+1) + '_off.gif" alt="' + this.text + '" border="0" width="' + (this.width+1) + '" height="26"></a>';
   this.inactiveTab += '</td></tr></table>';
   this.inactiveTab += '</div>';

   // html for browseTab
   this.browseTab = '<div id="browseTab' + this.number + '" class="browseTab" style="position:absolute; top:' + tabYOffset + 'px; left:' + this.XPos + 'px; visibility:hidden; z-index:100; width:' + this.width + 'px; height:' + tabHeight + 'px;">';
   this.browseTab += '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="browseTab" height="' + activeTabHeight + '" width="' + this.width +'">';
   this.browseTab += '<a class="inactiveTabLink" href="'+this.url +'" onClick="selectNav(' + (this.number+1) + '); return true;" onMouseOver="clearTimeout(timeout); return false;" onMouseOut="resetMenu(); return false;"  target="_top"><img src="' + this.webroot + 'images/aatab_' + (this.number+1) + '_on.gif" alt="' + this.text + '" border="0" width="' + (this.width+1) + '" height="26"></a>';
   this.browseTab += '</td></tr></table>';
   this.browseTab += '</div>';
}

function Item(tab, number, text, url, webroot, itemsXOffset) {
   this.tab = tab;
   this.number = number;
   this.url = url;
   this.text = text;
   this.webroot = webroot;
   this.itemsXOffset = itemsXOffset;
	 
   // html for browseItem
   this.browseItem = '<td class="browseItems" position: absolute; left:' + itemsXOffset + 'NOWRAP><img src="' + this.webroot + 'images/shim.gif" width="10" height="1"><a href="' + this.url + '" target="_top" class="browseItemsLink" onClick="selectNav(' + (this.tab+1) + '); return true;" onMouseOver="clearTimeout(timeout); return false;" onMouseOut="resetMenu(); return false;">' + this.text + '</a><img src="' + this.webroot + 'images/shim.gif" width="10" height="1"></td>';

   // html for activeItem
   this.activeItem = '<td class="activeItems" position: absolute; left:' + itemsXOffset + 'NOWRAP><img src="' + this.webroot + 'images/shim.gif" width="10" height="1"><a href="' + this.url + '" target="_top" class="activeItemsLink" onMouseOver="clearTimeout(timeout); return false;" onMouseOut="resetMenu(); return false;">' + this.text + '</a><img src="' + this.webroot + 'images/shim.gif" width="10" height="1"></td>';


   // html for activeItemCurrent
   this.activeItemCurrent = '<td class="activeItemsCurrent" position: absolute; left:' + itemsXOffset + 'NOWRAP><a href="' + this.url + '" target="_top" class="activeRefreshLink" onMouseOver="clearTimeout(timeout); return false;" onMouseOut="resetMenu(); return false;">' + this.text + '</a><img src="' + this.webroot + 'images/shim.gif" width="10" height="1"></td>';
}

function writeTabs() {
	
	tabHTML = '';
	xAxisPos = 124;
	
	for (var i=0; i<tabs.length; i++) {
		
		if (activeTab == (i + 1)) { //we display the tab in the 'on' state by default 
			tabHTML += '<div id="activeTab' + i + '" style="position:absolute; z-index:50; top: 102px; left: ' + xAxisPos + 'px; width: ' + (tabs[i].width+1) + 'px; height: 26px"><table border="0" cellpadding="0" cellspacing="0">';
			tabHTML += '<tr><td height="26" width="' + tabs[i].width + '"><a href="' + tabs[i].url + '" target="_top"><img src="' + tabs[i].webroot + 'images/aatab_' + (i+1) + '_on.gif" alt="' + tabs[i].text + '" border="0" width="' + (tabs[i].width+1) + '" height="26"></a>';
			tabHTML += '</td></tr></table>';
			tabHTML += '</div>';
		} else { //we display the tab in the 'off' state by default	
			tabHTML += '<div id="inactiveTab' + i + '" style="position:absolute; z-index:50; top:100px; left:' + xAxisPos + 'px; height:26px; width:' + (tabs[i].width+1) + 'px"><table border="0" cellpadding="0" cellspacing="0">';
			tabHTML += '<tr><td height="28" width="' + tabs[i].width + '"><a onMouseOver="updateMenu(' + (i+1) + '); return false;" onMouseOut="resetMenu(); return false; " href="' + tabs[i].url + '" target="_top"><img src="' + tabs[i].webroot + 'images/aatab_' + (i+1) + '_off.gif" alt="' + tabs[i].text + '" border="0" width="' + (tabs[i].width+1) + '" height="26"></a>';
			tabHTML += '</td></tr></table>'
			tabHTML += '</div>';
		}
		
		xAxisPos += tabs[i].width + 1;
	}
	
	//write out the html code
	document.write(tabHTML);
}

function writeNav(webroot) {

	Xadjust = -120;      
   var output = '<div style="position:absolute;"><img src="' + webroot + 'images/shim.gif" width="1" height="1"></div>';
   output += "\n";
   for (var i=0; i<tabs.length; i++) {
   
      if (i == (activeTab-1)) {
         // write active tab
         // write menu of items for active tab
         // write activeRefresh tab
         output += tabs[i].activeRefreshTab;
		 output += '<div id="items' + i + '" style="position:absolute; top:' + itemYOffsetInActive + 'px; left:' + (navXOffset+Xadjust) + 'px; visibility:visible; z-index:150; width:' + itemsMenuWidth+ 'px;">';
         output += '<table border="0" cellpadding="0" cellspacing="0" ><tr><td width="' + tabs[i].itemsXOffset+ '"><img src="' + webroot + 'images/shim.gif" width="1" height="1"></td>';
         for ( var j=0; j<tabs[i].items.length; j++) {
            if (j == activeTab-1) {
				output += tabs[i].items[j].browseItem;
			} else {
				output += tabs[i].items[j].browseItem;
			}
            if (j != tabs[i].items.length-1) {
               output += '<td class="activeItems">|</td>';
			}
         }
         output += '</tr></table>';
         output += '</div>';		 
      } else {
         // write inactive tab
         // write menu of items for browse tab
         output += '<div id="items' + i + '" style="position:absolute; top:' + itemYOffsetInActive + 'px; left:' + (navXOffset+Xadjust) + 'px; visibility:hidden; z-index:150; width:' + itemsMenuWidth+ 'px;">';
         output += '<table border="0" cellpadding="0" cellspacing="0" ><tr><td width="' + tabs[i].itemsXOffset+ '"><img src="' + webroot + 'images/shim.gif" width="1" height="1"></td>';
         for ( var j=0; j<tabs[i].items.length; j++) {
            output += tabs[i].items[j].browseItem;
            if (j != tabs[i].items.length-1) {
               output += '<td class="activeItems">|</td>';
			}
         }
         output += '</tr></table>';
         output += '</div>';
         // write browse tab (initially hidden)
         output += tabs[i].browseTab;
      }
   }
   document.open();
   document.writeln(output);
   document.close();
}