
var height = 0; //initial height
var step = 5; //increment step
var t;
var currentState = 1; //how many menus are showing
var xmlhttp;
var parent;
var menuNumber; //current level of menu (1-3)
var docUrl;
var menu1Clicked = 0; //id of last top level clicked menu item for arrows
var menu2Clicked = 0; //id of last 2nd level clicked menu item for arrows
var menu3Clicked = 0; //id of last 3rd level clicked menu item for arrows

/******************************
 * checks xml can be read and *
 *          parses it         *
 ******************************/

function loadXMLDoc(url, menuNo, pId)
{
docUrl = url;
menuNumber = menuNo;
parent = pId;
xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for IE7, Firefox, Mozilla, etc.
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE5, IE6
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=onResponse;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}

function onResponse()
{
if(xmlhttp.readyState!=4) return;
if(xmlhttp.status!=200)
  {
  alert("Problem retrieving XML data");
  return;
  }
txt="";
x=xmlhttp.responseXML.documentElement.getElementsByTagName("ITEM");
for (i=0;i<x.length;i++){
    if(x[i].getElementsByTagName("PARENT")[0].childNodes[0].nodeValue==parent){
            if(x[i].getElementsByTagName("TYPE")[0].childNodes[0].nodeValue=="menu"){
                nextmenu = menuNumber+1;
                menuId = x[i].getElementsByTagName('ID')[0].childNodes[0].nodeValue ;
                txt = txt + "<span class='menu'><img class='arrow_main1' src='pics/arrow"+menuNumber+".png' id ='" + menuId + "arrow1'><img class='arrow_main2' src='pics/arrow"+menuNumber+".png' id ='" + menuId + "arrow2'><a href='javascript:void(0)' onMouseOver='wipe();arrowVisibility(\"over\", " + menuId + "," + menuNumber+");return true;' onMouseOut='arrowVisibility(\"out\", " + menuId + "," + menuNumber+");return true;' onClick='loadXMLDoc(\"" + docUrl + "\", " + nextmenu + ", " + menuId+");moveMenu(" + menuNumber + ");arrowVisibility(\"click\", " + menuId + "," + menuNumber+");'></span>\n";
            }else{
                txt = txt + "<span class='menu'><a href='#"+ x[i].getElementsByTagName('SHORTNAME')[0].childNodes[0].nodeValue +"' onClick='location.hash=\""+ x[i].getElementsByTagName('SHORTNAME')[0].childNodes[0].nodeValue+"\";javascript:getText();'></span>\n";
            } 
            txt = txt + x[i].getElementsByTagName("NAME")[0].childNodes[0].nodeValue + "&nbsp;&nbsp;&nbsp;&nbsp;</a>";
    }

}
menu = "menu" + menuNumber;  
document.getElementById(menu).innerHTML=txt;
}

/******************************
 *     calls the php page     *
 *         for content        *
 ******************************/
 
function getText(){
    shortName = location.hash;
    shortName=shortName.substr(1);
    //document.getElementById('maincontent').innerHTML=shortName;
    var ajaxRequest;
    
    try{    //set up indivdual browsers
        ajaxRequest = new XMLHttpRequest(); //Opera 8.0+, Firefox, Safari
    }catch(e){
        try{    //set up IE
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
            try{
                ajaxRequest=new ActiveXObject("Microsoft.XMLHTTP");
            }catch(e){  //out of browsers
                alert("Your browser is out of date");
                return false;
            }
        }
    }
    
    ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){
            var ajaxDisplay = document.getElementById('maincontent');// Prepare DIV for text
            ajaxDisplay.innerHTML = ajaxRequest.responseText;// Actually put text
        }
    }
// Server Side stuff now!
    var queryString = "?name=" + shortName ;// Create a URL for the PHP
    ajaxRequest.open("GET", "includes/content.php" + queryString, true);  // Run PHP to execute query
    ajaxRequest.send(null);
}


/******************************
 *    moves the menu bit      *
 ******************************/
            
function moveMenu(downMenuNumber){
    if(currentState<=downMenuNumber){ //move down
        switch (downMenuNumber){
            case 1:
                if(height>29){height = 0; currentState++; return;}
                height = height + step;
                document.getElementById("main").style.height = height + 55 + 'px';
                document.getElementById("menu2").style.top = height + 15 + 'px';
                document.getElementById("menu3").style.top = height + 15 + 'px';
                document.getElementById("links").style.top = height + 192 + 'px';
                document.getElementById("innerbody").style.top = height + 296  + 'px';
                t = setTimeout("moveMenu(1);",0);
                break;
            case 2:
                if(height>29){height = 0; currentState++; return;}
                height = height + step;
                document.getElementById("main").style.height = height + 85 + 'px';
                document.getElementById("menu3").style.top = height + 45 + 'px';
                document.getElementById("links").style.top = height + 222 + 'px';
                document.getElementById("innerbody").style.top = height + 326  + 'px';
                t = setTimeout("moveMenu(2);",0);
                break;
        }
    }else if(currentState>downMenuNumber+1){ //move menu3 up
        if(height<-29){height = 0; currentState--;  return;}
        height = height - step;
        document.getElementById("main").style.height = height + 115 + 'px';
        document.getElementById("menu3").style.top = height + 75 + 'px';
        document.getElementById("links").style.top = height + 252 + 'px';
        document.getElementById("innerbody").style.top = height + 356  + 'px';
        t = setTimeout("moveMenu(1);",0);
    }
    
}

/******************************
 *    sorts out visibility    *
 *          of arrows         *
 ******************************/
 
function arrowVisibility(type, id, menuNo){
    if(type == "over"){
        document.getElementById(id+"arrow1").style.visibility = 'visible';
    }else if(type == "out"){
        document.getElementById(id+"arrow1").style.visibility = 'hidden';
    }else if(type == "click"){
        if(menuNo==1){
            if(menu1Clicked!=0 && menu2Clicked==0 && menu3Clicked==0){
                document.getElementById(menu1Clicked+"arrow2").style.visibility = 'hidden';
            }else if(menu2Clicked!=0 && menu3Clicked==0){
                document.getElementById(menu1Clicked+"arrow2").style.visibility = 'hidden';
                document.getElementById(menu2Clicked+"arrow2").style.visibility = 'hidden';
            }else if(menu3Clicked!=0){
                document.getElementById(menu1Clicked+"arrow2").style.visibility = 'hidden';
                document.getElementById(menu2Clicked+"arrow2").style.visibility = 'hidden';
                document.getElementById(menu3Clicked+"arrow2").style.visibility = 'hidden';
            }
            menu1Clicked = id;
            menu2Clicked = 0;
            menu3Clicked = 0;
        }else if(menuNo==2){
            if(menu2Clicked!=0 && menu3Clicked==0){
                document.getElementById(menu2Clicked+"arrow2").style.visibility = 'hidden';
            }else if(menu3Clicked!=0){
                document.getElementById(menu2Clicked+"arrow2").style.visibility = 'hidden';
                document.getElementById(menu3Clicked+"arrow2").style.visibility = 'hidden';
            }
            menu2Clicked = id;
            menu3Clicked = 0;
        }else{
            if(menu3Clicked!=0){
                document.getElementById(menu3Clicked+"arrow2").style.visibility = 'hidden';
            }
            menu3Clicked = id;
        }
        document.getElementById(id+"arrow2").style.visibility = 'visible';
    }
}


/******************************
 *   clears the status bar    *
 ******************************/

function wipe(){window.status= " ";}
