﻿//declare some variables
var scrollY = 0, scrollX = 0, lastScrollY = 0, infoLowered, initialInfoY, currentPosition, ydifference, working, glowStep, glowDirection;

function initInfoLowered(){
    infoLowered = 2;        // lowered = 1, moving down = 2, moving up = 3, raised = 4
    initialInfoY = document.getElementById('infoTable').offsetTop;
    ydifference = 70;
    if(navigator.appName=="Netscape"){
        initialInfoY = document.getElementById('infoTable').offsetTop - 50;
        ydifference = -20;
        }
    if(navigator.appName=="Microsoft Internet Explorer"){
        initialInfoY = document.getElementById('infoTable').offsetTop + 50;
        ydifference = 65;
        }
        
    currentPosition = 0;
    setInterval("animateInfoBar();",3);
    
    glowStep = 0;
    glowDirection = 1;
    setInterval("glow();",5);
    }
    
//this function makes whatever element is passed to it visibe
function showElement(ele){
    hideNavs();
    centerNav(ele);
    infoLowered = 3;    
    document.getElementById(ele).style.visibility = 'visible';
    }
    
//this function hides every sub nav
function hideNavs(){
    for(i=1;i<=6;i+=1){
        eval("document.getElementById('panelsubnav" + i + "').style.visibility = 'hidden';");
        }
    }
    
//this function runs every step checking if a nav needs to be closed
function closeSubNav(ev){
    //document.getElementById('javaDebug').innerHTML = "X: " + ev.clientX + " Y: " + ev.clientY;
    //javaDebug.innerHTML = "InfoLowered: " + infoLowered + " initialInfoY: " + initialInfoY + " CurrentPosition: " + currentPosition + "<br />TOP: " + document.getElementById('infoTable').style.top + " working: " + working;
    //document.getElementById('javaDebug').innerHTML = "Height: " + document.getElementById('headerTable').offsetHeight;
    var headerHeight = document.getElementById('headerTable').offsetHeight;
    //if(navigator.appName=="Netscape"){
    //    if ((ev.clientY + scrollY < headerHeight)||(ev.clientY + scrollY > document.getElementById('headerTable').offsetHeight + 150)){
    //        hideNavs();
    //        }
    //}else{
    //    if ((ev.clientY + scrollY < document.getElementById('headerTable').offsetHeight)||(ev.clientY + scrollY > document.getElementById('headerTable').offsetHeight + 130)){
    //        hideNavs();
    //        }
    //    }
    if(navigator.appName=="Netscape"){
        if ((ev.clientY < headerHeight)||(ev.clientY > document.getElementById('headerTable').offsetHeight + 150)){
            hideNavs();
            }
    }else{
        if ((ev.clientY < document.getElementById('headerTable').offsetHeight)||(ev.clientY > document.getElementById('headerTable').offsetHeight + 130)){
            hideNavs();
            }
        }
    }
    
//this function records the scrollbars movement
function recordScroll(ev){
    if((lastScrollY != 0)){
        scrollY += ev.clientY - lastScrollY;
        }
    lastScrollY = ev.clientY;                
    }
    
//this function resets a piece of code evereytime the cursor moves away from the scrollbar
function resetScroll(){
    lastScrollY = 0;
    }

//this function centers any item on the page
function centerNav(ele){
    var pgWidth;
    var eleWidth;
    
    pgWidth = document.body.offsetWidth;
    eleWidth = document.getElementById(ele).clientWidth;
    
    document.getElementById(ele).style.left = eval(pgWidth/2 - eleWidth/2 + 10) + "px"; 
    }
    
function animateInfoBar(){
    if(document.body != null){    
        if(infoLowered==2){     //moving down
            if(document.getElementById('infoTable').style.top.replace("px","") < initialInfoY - ydifference){//it still needs to be moved down
                infoLowered = 4;                       //it has been raised
            }else{
                currentPosition += 2;
                }
            }      
              
        if(infoLowered==3){     // moving up
            if(document.getElementById('infoTable').style.top.replace("px","") > initialInfoY){     //it still needs to move up
                infoLowered = 1; 
            }else{
                currentPosition -= 2;
                }
            }
        
        if (navigator.appName == "Netscape") {
            document.getElementById('infoTable').style.pixelTop = initialInfoY - currentPosition + "px";
        } else {
            document.getElementById('infoTable').style.top = initialInfoY - currentPosition + "px";
            }
        }
    }
    
function d2h(d) {return d.toString(16);}
function h2d(h) {return parseInt(h,16);} 
function form2(num){
    if(num < 10)return "0"+num;
    }
function glow(){
    if(document.getElementById('subGlobalHeading') == NaN){           
        document.getElementById('subGlobalHeading').style.color = "#" + form2(d2h(glowStep)) + form2(d2h(glowStep)) + form2(d2h(glowStep));
        if(glowDirection==1){
            glowStep += 2; 
        }else{
            glowStep -= 1;
            }
        if(glowStep > 160)glowDirection = 0;
        if(glowStep < 40)glowDirection = 1;
        }
    }

//the body text fade colour and the change in height 
var initCol, stopCol, inc, initHeight, ratio;
    
function initDiv(ele){
    //document.getElementById(ele).style.backgroundColor = "White";
    document.getElementById(ele).style.backgroundColor="Black";
    initCol = 40;
    inc = 0;
    stopCol = 220;
    
    initHeight = document.getElementById(ele).offsetHeight;
    document.getElementById(ele).style.height = "0px";
    ratio = Math.abs(stopCol - initCol);
    
    setInterval("fiag('" + ele.toString() + "');",5);
    }
    
function fiag(ele){
    if(inc <= ratio){
        document.getElementById(ele).style.height = inc/ratio*initHeight + "px";
        inc += 5;
        //document.getElementById(ele).style.backgroundColor = "#" + d2h(inc) + d2h(inc) + d2h(inc);
        }
    }
//end of the effect
