var hide = 1;
var hideEvent = 0;

function getObj(name)
{
   this.exists = false;
   if(document.getElementById)
   {
      this.obj = document.getElementById(name);
      if(this.obj != null)
      {
         this.style = document.getElementById(name).style;
         this.exists = true;
      }
   }
   else if(document.all)
   {
      this.obj = document.all[name];
      if(this.obj != null)
      {
         this.style = document.all[name].style;
         this.exists = true;
      }
   }
   else if(document.layers)
   {
      this.obj = document.layers[name];
      if(this.obj != null)
      {
         this.style = document.layers[name];
         this.exists = true;
      }
   }
}

function addEvent(oTargetElem, sOnWhat, oFunction)
{
    if (oTargetElem.attachEvent)
    {
        oTargetElem.attachEvent('on'+sOnWhat, oFunction);
    }
    else if(oTargetElem.addEventListener)
    {
        oTargetElem.addEventListener(sOnWhat, oFunction, false);
    }
    else
    {
        // Cannot attach event
    } // end-if
}

addEvent(window, 'load', initSOLARmenu);

function initSOLARmenu() {
    var x = document.getElementsByTagName('div');
    for(var i = 0; i < x.length; i++)
    {
        if(x[i].className == 'navheader')
        {
            x[i].onmousedown = clickNav;
            x[i].onmouseover = function () {this.className="navheaderselected";};
            x[i].onmouseout = function () {this.className="navheader";};
        }
    }
    closeNav();

    setNav(getPageId(), 'currentPage');
}

function closeNav()
{
    var x = document.getElementsByTagName('div');
    for(var i = 0; i < x.length; i++)
    {
        if(x[i].className == 'submenu') x[i].style.display = 'none';
    }
}

function clickNav(e)
{
		closeNav();
    if(!e)
        var e = window.event;
    if(e.target)
        var tg = e.target;
    else if(e.srcElement)
        var tg = e.srcElement;
    var nextSib = tg.nextSibling;
    while(nextSib.nodeType != 1) nextSib = nextSib.nextSibling;
    var nextSibStatus =(nextSib.style.display == 'none') ? 'block' : 'none';
    nextSib.style.display = nextSibStatus;
}

function setNav(page, newID)
{
    if (page != null && page != "")
    {
        var x = document.getElementsByTagName('a');
        var i;
        for(i = 0; i < x.length; i++)
        {
            if(x[i].id == getPageId())
            {
                x[i].id = newID;
                x[i].className = 'navitemselected';
                break;
            }
        }

        if(i < x.length && newID == 'currentPage')
        {
            var parDiv = x[i];
            while(parDiv.parentNode.tagName == 'DIV')
            {
                parDiv = parDiv.parentNode;
                parDiv.style.display = 'block';
            }
        }    
    } // end-if
}

var pageId = "";
function getPageId()
{
    return pageId;
}

function setPageId(page)
{
    pageId = page;
}