	/*
		Links.js - Gets links by Ajax for the new HBCF menu bar.

		Author: Andrew Dent.
	*/

 var oldOnload;
 var linksArray = new Array();
 var thisTab;
 var nowDisplaying;
 var linksList = new String();
 var oldAjaxFunc;

 oldOnload = window.onload;
 window.onload = setUpLinks;

 function setUpLinks()
  {
   // First, call the original Onload that we replaced with this one.
   if (oldOnload != undefined)
    {
     oldOnload();
    }
   // Works in Safari and Firefox. Untested in IE.

   docPart('topbar').onmouseout = oldLinks;
   var temp;
   temp = document.getElementsByTagName('a');
   for (i in temp)
    {
     if (temp[i].className == 'tab')
      {
       if (!(temp[i].id))
        {
         alert(temp[i].innerHTML);
        }
       docPart(temp[i].id).onmouseover = getLinks;
       temp.onmouseover = getLinks;
       linksList += '|' + temp[i].id;
      }
     if (temp[i].className == 'thistab')
      {
       docPart(temp[i].id).onmouseover = getLinks;
       thistab = temp[i].id;
       linksList += '|' + temp[i].id;
      }
    }
   linksList = linksList.substr(1);
  }

 function getLinks()
  {
   if (linksArray[this.id.substr(2)] == undefined)
    {
     doAjax('/?m=' + this.id.substr(2) + '&getAjax=getAjax', null, processLinks);
    }
   else
    {
     docPart('topbar2').style.height = '0px';
     docPart('topbar2').innerHTML = linksArray[this.id.substr(2)];
     linksAnimation();
    }
   docPart(this.id).className = 'thistab';
   nowDisplaying = this.id.substr(2);
   window.setTimeout('oldLinks(\'' + this.id.substr(2) + '\')', 10000);
   var temp = linksList.split('|');
   for (i in temp)
    {
     if (temp[i] != this.id)
      {
       docPart(temp[i]).className = 'tab';
      }
    }
  }

 function oldLinks(page)
  {
   if (page == nowDisplaying)
    {
     if (linksArray[getGET('m')] == undefined)
      {
       doAjax('/?m=' + getGET('m') + '&getAjax=getAjax', null, processLinks);
      }
     else
      {
       docPart('topbar2').style.height = '0px';
       docPart('topbar2').innerHTML = linksArray[getGET('m')];
       linksAnimation();
      }
     docPart(thistab).className = 'thistab';
     var temp = linksList.split('|');
     for (i in temp)
      {
       if (temp[i] != thistab)
        {
         docPart(temp[i]).className = 'tab';
        }
      }
    }
  }

 function linksAnimation()
  {
   var temp = docPart('topbar2').style.height.substr(0, (docPart('topbar2').style.height.length - 2));
   temp++;
   temp++;
   temp++;
   if (temp > 18)
    {
     docPart('topbar').innerHTML = docPart('topbar2').innerHTML;
     docPart('topbar2').style.height = '0px';
    }
   else
    {
     docPart('topbar2').style.height = temp + 'px';
     window.setTimeout('linksAnimation()', 60);
    }
  }

 function processLinks()
  {
   if (req.readyState == 4)
    {
     if (req.status == 200)
      {
       linksArray[req.getResponseHeader('Custom-Module')] = req.responseText;
       docPart('topbar2').style.height = '0px';
       docPart('topbar2').innerHTML = req.responseText;
       linksAnimation();
      }
    }
  }
