	/* need to figure out which browser is being used. Some features are browser specific, 
	make sure page doesn't bomb on older browsers */
	var ns4=document.layers?1:0
	var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
	var ns6=document.getElementById&&!document.all?1:0

  var cur = new String("Main");
  var curBack;
  var lastBack;
  
  /*
   * Header transitions work the following way:
   * There are 4 possible texts: Gen, Model, Main and Deploy:
   * Users can click to view any. I.e: The transition must be from 
   * the currently viewed, to the new one: From Model to Gen for example.
   *
   * To avoid a step, (an instant where there is no image), divs are preloaded
   * with all transition gifs.
   */
  function changeHeader(elem)
  {
    var next = elem.id;
    if(next != cur)
    {
      var newimg = "curve" + cur + "To" + next;           
      var newBackGround = document.getElementById(newimg);            

      //handle first case
      if(cur == "Main")
      {
        curBack = document.getElementById('curveMain');
      }      
      
      newBackGround.style.display = "block";
      
      newBackGround.style.zindex = "2";
      
      //review if
      if(curBack)
      {
         curBack.style.zindex = "1";         
         curBack.style.display = "none";
         
         //curBack.style.zindex = "1";
         
         
         //if(lastBack)
         //  lastBack.style.display = "none";         
         //lastBack = curBack;
         
      }            
      
      //should put a timer here, to force wait, before click.      
      cur = next;
      curBack = backGround;

    }
  }
  
	
	/* hack to get a smooth delay before menu hides */
	var hide = 0;
	var hideSubMenu = 0;  
  
	function ShowMenu(menuID, parentID)
	{
    //hide all
		hideAllMenus(true);
    
    //get menu
		menu = document.getElementById(menuID);
    

    //place Menu with regards to parent, becuase window is no centered absolute positioning will not work
        var parent = document.getElementById(parentID);
        var x = findPosX( parent );
        var y = findPosY( parent );    
        menu.style.left = new String((x) + 'px');
        menu.style.top = new String((y + 20) + 'px');
        
    //Show menu Background. 
        x = findPosX( menu );
        y = findPosY( menu );    
        var w = menu.offsetWidth;		
        var h = menu.offsetHeight;
        var menuBack;
        menuBack = document.getElementById('menuBack');
        
    //place menuBack directly underneath menu, and size accordingly.
        menuBack.style.width = new String((w -2) + 'px');        
        menuBack.style.height = new String((h -2) + 'px');      
        menuBack.style.left = new String(x + 'px');
        menuBack.style.top = new String((y) + 'px');
        menuBack.style.visibility="visible";
        
		menu.style.visibility = "visible";
    
	}
	
	function showSubMenu(menuID, parent)
	{
    //hide all
		hideAllSubMenus(true);
    //get menu  
		menu = document.getElementById(menuID);
        var w = menu.offsetWidth;		
        var h = menu.offsetHeight;
        
    //place Menu with regards to parent, becuase window is now centered absolute positioning will not work
        var x = findPosX( parent );
        var y = findPosY( parent );    
        menu.style.left = new String((x + w + 14) + 'px');
        menu.style.top = new String((y - 20) + 'px');

        
    //Show menu Background. 
        x = findPosX( menu );
        y = findPosY( menu );    
        var menuBack;
        menuBack = document.getElementById('subMenuBack');
        
    //place menuBack directly underneath menu, and size accordingly.
        menuBack.style.width = new String((w -2) + 'px');        
        menuBack.style.height = new String((h -2) + 'px');      
        menuBack.style.left = new String(x + 'px');
        menuBack.style.top = new String((y) + 'px');
        menuBack.style.visibility="visible";
        
    //show menu
		menu.style.visibility = "visible";        
	}	
	
	function hideAllMenus(forceHide)
	{
		if((hide > 15) || forceHide)
		{
			/* an implementation using an array could be used,
			but is unnessesary clutter for 4 items */
			
			menu = document.getElementById('menu1');
			menu.style.visibility = "hidden";
			menu = document.getElementById('menu2');
			menu.style.visibility = "hidden";
			menu = document.getElementById('menu3');
			menu.style.visibility = "hidden";
			menu = document.getElementById('menu4');
			menu.style.visibility = "hidden";
			menu = document.getElementById('menu5');
			menu.style.visibility = "hidden";
			menu = document.getElementById('menu6');
			menu.style.visibility = "hidden";


            //hide subMenu BackGround
            var menuBack;
            menuBack = document.getElementById('menuBack');
            menuBack.style.visibility="hidden";
  
			//hide all submenus
			hideAllSubMenus(true);
			
			
	    }
	}
	
	function hideAllSubMenus(forceHide)
	{
		if(hideSubMenu > 5 || forceHide)
		{
			menu = document.getElementById('subMenu1');
			menu.style.visibility = "hidden";
			menu = document.getElementById('subMenu2');
			menu.style.visibility = "hidden";
			menu = document.getElementById('subMenu3');
			menu.style.visibility = "hidden";
			menu = document.getElementById('subMenu4');
			menu.style.visibility = "hidden";
            
            //hide subMenu BackGround
            var menuBack;
            menuBack = document.getElementById('subMenuBack');
            menuBack.style.visibility="hidden";
            
            
		}
	
	}
	
	function blurMenus()
	{
		hideAllMenus();
		hide++;
	}

	function selectMenuItem(elem)
	{
		elem.style.background = "#A0B89E";
	}

	function unselectMenuItem(elem)
	{
		elem.style.background = "transparent";
	}
	
	function menuClick(loc)
	{
		window.location = loc;
	}
