//	SWG Menu Code
//	SWG Content Mangement System 3.0
//	Copyright © 2006 Super Web Group.  All Rights Reserved.
//	info@superwebgroup.com

var bFadeIn = true;
var iMenuHoldCount = 300;
var bMenuOver;
var bMenuItemOver;
var bScroll;
var iTopNavMenuYOffset = 0;
var iTopNavMenuXOffset = 0;
var iMenuYOffset = 2;
var iMenuXOffset = 10;
var iMenuDivWidth = 120;
var bUseExternalLinkWindow = false;
var iNavType = 0; // 0 = top, 1 = left, 2 = right
var iMenuRoot = 0;
var MenuArrayCount = 0;
var MenuArray = new Array(99);

window.onresize = HideAllMenus;

function BuildMenus(iRootID){
    var itemlink
    var i 
    document.write('<div id="navTopNavHolder" class="navTopNavHolder" width="100%">'); 
    if (iNavType == 0){
        document.write('<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr valign="top">');
    }
    for(i=0; i<iMenuPageCount; i++){     
        if (MenuPages[i][1] == iRootID){
            itemlink = "";
            if (MenuPages[i][3].substr(0,4).toLowerCase() == "http"){
                if (bUseExternalLinkWindow == true) {
                    itemlink = "external_site(\'"+MenuPages[i][3]+"\');";
                } else {
                    itemlink = "pop(\'"+MenuPages[i][3]+"\',950,750);";
                }
            }
            if (MenuPages[i][3] != "" && itemlink == "") {
                itemlink = "location.href=\'"+MenuPages[i][3]+"\';";
            }
            if (itemlink == "#") {
                itemlink = "";
            }
            if (iNavType == 0){
                document.write('<td id="navTopNav_Item'+MenuPages[i][0]+'" class="navTopNavItem" onmouseover="this.className=\'navTopNavItemOver\';HideAllMenus();ShowPulldownMenu('+MenuPages[i][0]+');" onmouseout="this.className=\'navTopNavItem\';MenuOut('+MenuPages[i][0]+');" onclick="HideAllMenus();'+itemlink+'"><div id="Anchor'+MenuPages[i][0]+'" name="Anchor'+MenuPages[i][0]+'" class="navTopNavItemAnchor"></div><div class="navTopNavItemPadding">'+MenuPages[i][2]+'</div></td>');
            }
            if (iNavType == 1){
                document.write('<div id="navLeftNav_Item'+MenuPages[i][0]+'" class="navLeftNavItem" onmouseover="this.className=\'navLeftNavItemOver\';HideAllMenus();ShowPulldownMenu('+MenuPages[i][0]+');" onmouseout="this.className=\'navLeftNavItem\';MenuOut('+MenuPages[i][0]+');" onclick="HideAllMenus();'+itemlink+'"><div id="Anchor'+MenuPages[i][0]+'" name="Anchor'+MenuPages[i][0]+'" class="navLeftNavItemAnchor"></div><div class="navLeftNavItemPadding">'+MenuPages[i][2]+'</div></div>');
            }
            if (iNavType == 2){
                document.write('<div id="navRightNav_Item'+MenuPages[i][0]+'" class="navRightNavItem" onmouseover="this.className=\'navRightNavItemOver\';HideAllMenus();ShowPulldownMenu('+MenuPages[i][0]+');" onmouseout="this.className=\'navRightNavItem\';MenuOut('+MenuPages[i][0]+');" onclick="HideAllMenus();'+itemlink+'"><div id="Anchor'+MenuPages[i][0]+'" name="Anchor'+MenuPages[i][0]+'" class="navRightNavItemAnchor"></div><div class="navRightNavItemPadding">'+MenuPages[i][2]+'</div></div>');                
            }
        }        
    }
    if (iNavType == 0){
        document.write('</tr></table>');
    }   
    document.write('</div>'); 
    BuildPopupMenus();
}

function BuildPopupMenus(){
    var itemlink
    for(i=0; i<iMenuPageCount; i++){     
        if (MenuPages[i][4] > 0){
            // add to menu array
            MenuArray[MenuArrayCount] = new Array(4);
            MenuArray[MenuArrayCount][0] = MenuPages[i][0];
            MenuArray[MenuArrayCount][1] = MenuPages[i][1];
            MenuArray[MenuArrayCount][2] = 0;
            MenuArray[MenuArrayCount][3] = 0;
            MenuArrayCount = MenuArrayCount + 1
            document.write('<div id="Menu'+MenuPages[i][0]+'" class="navMenuHolder" style="z-index:200'+MenuArrayCount+';position:absolute; visibility:hidden;">');
            for(j=0; j<iMenuPageCount; j++){ 
               if (MenuPages[j][1] == MenuPages[i][0]){
                    itemlink = "";
                    if (MenuPages[j][3].substr(0,4).toLowerCase() == "http"){
                        if (bUseExternalLinkWindow == true) {
                            itemlink = "external_site(\'"+MenuPages[j][3]+"\');";
                        } else {
                            itemlink = "pop(\'"+MenuPages[j][3]+"\',950,750);";
                        }
                    }
                    if (MenuPages[j][3] != "" && itemlink == "") {
                        itemlink = "location.href=\'"+MenuPages[j][3]+"\';";
                    }
                    if (itemlink == "#") {
                        itemlink = "";
                    }
            	    document.write('<div id="Menu'+MenuPages[i][0]+'_Item'+MenuPages[j][0]+'" class="navMenuItem" onmouseover="this.className=\'navMenuItemOver\';MenuItemOver('+MenuPages[i][0]+','+MenuPages[j][0]+');" onmouseout="this.className=\'navMenuItem\';MenuOut('+MenuPages[i][0]+');" onclick="HideAllMenus();'+itemlink+'">');
            	    if (MenuPages[j][4] > 0){
        	            document.write('<div id="Anchor'+MenuPages[j][0]+'" name="Anchor'+MenuPages[j][0]+'" class="navMenuItemAnchor"></div>');
        	        }
            	    document.write('<div class="navMenuItemPadding">'+MenuPages[j][2]+'</div>');
             	    document.write('</div>');
           	        document.write('<div class="navMenuItemBorder" onmouseover="MenuItemOver('+MenuPages[i][0]+','+MenuPages[j][0]+');" onmouseout="MenuOut('+MenuPages[i][0]+');"><img src="images/1x1trans.gif" height="1"></div>');
        	    }
        	}
            document.write('</div>');
            document.write('<iframe id="ShimMenu'+MenuPages[i][0]+'" src="javascript:false;" scrolling="no" frameborder="0" style="position:absolute; top:0px; left:0px; display:none;"></iframe>');
        }        
    }
}

function InitializeMenu(){
    BuildMenus(iMenuRoot);
    var Menu = new getObj('navTopNavHolder');
    Menu.style.visibility = 'visible';
    Menu.style.display = "block";	
}

function MenuOut(MenuID) {
	clearInterval(bMenuOver);
	bMenuOver = setTimeout('HideMenu('+MenuID+')',iMenuHoldCount);
	clearInterval(bScroll);
}

function MenuOver(MenuID) {
	clearInterval(bMenuOver);
	for(i=0; i<MenuArrayCount; i++){
		if (MenuID == MenuArray[i][0])
		{
			MenuArray[i][2] = 1;
			clearInterval(MenuArray[i][3]);
			for(j=0; j<MenuArrayCount; j++){
				if (MenuArray[i][1] == MenuArray[j][0]){
					MenuOver(MenuArray[j][0]); //recursive check for parents
				}						
			}			
		}
	}
	MenuStates();	
}			

function MenuItemOver(MenuID,ItemID) {
	clearInterval(bMenuItemOver);
	bMenuItemOver = setTimeout('HideSubMenus('+MenuID+')',iMenuHoldCount);	
	MenuOver(MenuID);	
	for(p=0; p<MenuArrayCount; p++){
		if (MenuArray[p][0] == ItemID){
		    clearInterval(bMenuItemOver);
		    HideSubMenus(MenuID);
			ShowPulloutMenu(ItemID); //recursive check for children
			p = MenuArrayCount; // only first child menu
		}		
	}
	clearInterval(bScroll);
    ScrollWindow('Menu'+MenuID+'_Item'+ItemID);		  
}

function ShowPulldownMenu(MenuID) {
	for(i=0; i<MenuArrayCount; i++){
		if (MenuID == MenuArray[i][0] && MenuArray[i][2] == 0)
		{	
			var anchorobj = new getObj('Anchor'+MenuArray[i][0]);
			MenuPosition(anchorobj.obj,'Menu'+MenuArray[i][0],iTopNavMenuYOffset,iTopNavMenuXOffset);
			MenuOver(MenuID);
		}
	}
}

function ShowPulloutMenu(MenuID) {
	for(i=0; i<MenuArrayCount; i++){
		if (MenuID == MenuArray[i][0] && MenuArray[i][2] == 0)
		{	
			var anchorobj = new getObj('Anchor'+MenuArray[i][0]);
			MenuPosition(anchorobj.obj,'Menu'+MenuArray[i][0],iMenuYOffset,iMenuXOffset);
			MenuOver(MenuID);
		}
	}
}


function HideMenu(MenuID) {
	for(k=0; k<MenuArrayCount; k++){
		if (MenuID == MenuArray[k][0])
		{
			HideSubMenus(MenuID);
			MenuOut(MenuArray[k][1]);
			MenuArray[k][2] = 0;
			clearInterval(MenuArray[k][3]);
			MenuArray[k][3] = setTimeout('MenuStates()',iMenuHoldCount);
		}
	}
}

function HideSubMenus(MenuID) {
	for(i=0; i<MenuArrayCount; i++){
		if (MenuID == MenuArray[i][0])
		{
			for(j=0; j<MenuArrayCount; j++){
				if (MenuArray[i][0] == MenuArray[j][1]){
					for(p=0; p<MenuArrayCount; p++){
						if (MenuArray[j][0] == MenuArray[p][1]){
							MenuArray[p][2] = 0;
							clearInterval(MenuArray[p][3]);
							MenuArray[p][3] = setTimeout('MenuStates()',iMenuHoldCount);	
						}			
					}				
					MenuArray[j][2] = 0;
					clearInterval(MenuArray[j][3]);
					MenuArray[j][3] = setTimeout('MenuStates()',iMenuHoldCount);	
				}			
			}
		}
	}
}

function HideAllMenus() {
	for(i=0; i<MenuArrayCount; i++){
		MenuArray[i][2] = 0;
	}
	MenuStates();
}

function MenuStates() {
	for(i=0; i<MenuArrayCount; i++){
		if (MenuArray[i][2] == 0){
			hide('Menu'+MenuArray[i][0]);
		}
		if (MenuArray[i][2] == 1){
			show('Menu'+MenuArray[i][0]);
		}
	}
}


function MenuPosition(obj,lyr,mody,modx)
{
	if (is_mac && is_ie5up) { // mac ie position bug fix
		var menuanchor = new getObj('MenuAnchor');
		var newX = modx + findPosX(obj) - findPosX(menuanchor.obj);
		var newY = mody + findPosY(obj) - findPosY(menuanchor.obj);
		var x = new getObj(lyr);
		x.style.top = newY + 'px';
		x.style.left = newX + 'px';
	} else {
		var newX = modx + findPosX(obj);
		var newY = mody + findPosY(obj);
		var x = new getObj(lyr);
		x.style.top = newY + 'px';
		x.style.left = newX + 'px';
	}
	
	if (is_win && is_ie5up) {
		var DivRef = document.getElementById(lyr);
		var IfrRef = document.getElementById('Shim'+lyr);
	    IfrRef.style.width = DivRef.offsetWidth;
	    IfrRef.style.height = DivRef.offsetHeight;
	    IfrRef.style.top = newY + 'px';
	    IfrRef.style.left = newX + 'px';
	    IfrRef.style.zIndex = DivRef.style.zIndex - 1;
	}	
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function getObj(name)
{
 if (document.getElementById)
 {
	   this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
 }
 else if (document.all)
 {
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
 }
 else if (document.layers)
 {
	   if (document.layers[name])
	   {
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	   }
 }
}

function show(obj)
{
	var x = new getObj(obj);
	x.style.visibility = 'visible';
    x.style.display = "block";
	if (is_win && is_ie5up) {
		var s = new getObj('Shim'+obj);
	    s.style.display = "block";	
		s.style.visibility = 'visible';
	}
}

function hide(obj)
{
	var x = new getObj(obj);
	x.style.visibility = 'hidden';
	if (is_win && is_ie5up) {
		var s = new getObj('Shim'+obj);
	    s.style.display = "none";	
		s.style.visibility = 'hidden';
	}	
}

function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
  return [myWidth, myHeight];
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  //window.alert( 'Y Scroll = ' + scrOfY );
  //window.alert( 'X Scroll = ' + scrOfX );
  return [scrOfX, scrOfY];
}

function ScrollWindow(ItemName){
    var itemObj = new getObj(ItemName);
    var itemY = findPosY(itemObj.obj);
    var WinScroll = getScrollXY();
    var WinSize = getWindowSize();
    if ((WinScroll[1] + WinSize[1]) <= (itemY+50)){
        SmoothScroll(50);
    }
    if (WinScroll[1] >= (itemY-50)){
        SmoothScroll(-50);
    }    
}

function SmoothScroll(direction){
    var movecount = 0;
    if(direction > 0){movecount = 1;}
    if(direction < 0){movecount = -1;}
    if(direction != 0){
        scrollBy(0,movecount); 
        clearInterval(bScroll);
        bScroll = setTimeout('SmoothScroll('+direction+')',10);
    }else{
        clearInterval(bScroll);
    }
}