
rightOffsetCorrection = 170;

function screenSize() {
  var myWidth = 0;
//  myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;    // window.screen.availWidth may also work
//    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
//    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
//    myHeight = document.body.clientHeight;
  }
    return myWidth;
}

function linkEventHandlers(){
    if(!document.getElementsByTagName) return;
    if(!document.getElementById) return;
    var objA = document.getElementsByTagName('li');
    if(objA.length <= 0) return;
    for(var i= 0; i < objA.length; i++){
        if(objA[i].className == 'ProfileC') {
            objA[i].onmouseover = function(){
                this.click = false;
                this.style.color = '#000000';
                this.style.background = '#FFFF00';
            }
            objA[i].onmouseout = function(){
                if(!this.click){
                    this.style.color = '#FFFFFF';
                    this.style.background = '#2a7467';
                }
            }
            objA[i].onclick = function(){
                this.click = true;
                this.style.color = '#FFFFFF';
                this.style.background = '#2a7467';
                clearAllLinks();
                clearAllDivisions();
                turnOnDivision('mainText');
            }
        }
    }
    var objPA = document.getElementById('ProfileA');
    objPA.onmouseover = function(){
        clearLink('StatsL');
        clearLink('LinksL');
        turnOnLink('ProfileL');
    }
    var objPA = document.getElementById('ProfileL');
    objPA.onmouseover = function(){
        turnOnLink('ProfileL');
    }
    objPA.onmouseout = function(){
        clearAllLinks();
    }

    for(var i= 0; i < objA.length; i++){
        if(objA[i].className == 'StatsC') {
            objA[i].onmouseover = function(){
                this.click = false;
                this.style.color = '#000000';
                this.style.background = '#FFFF00';
            }
            objA[i].onmouseout = function(){
                if(!this.click){
                    this.style.color = '#FFFFFF';
                    this.style.background = '#2a7467';
                }
            }
            objA[i].onclick = function(){
                this.click = true;
                this.style.color = '#FFFFFF';
                this.style.background = '#2a7467';
                clearAllLinks();
                clearAllDivisions();
                var g = this.getAttribute('id');
                switch (g){
                    case 'Lakes':
                        turnOnDivision('rabunLakes');
                        break;
                    case 'Population':
                        turnOnDivision('rabunPopulation');
                        break;
                    case 'Weather':
                        turnOnDivision('rabunWeather');
                        break;
                    case 'Misc':
                        turnOnDivision('genInfo');
                }
            }
        }
    }
    objPA = document.getElementById('StatsA');
    objPA.onmouseover = function(){
        clearLink('LinksL');
        clearLink('ProfileL');
        turnOnLink('StatsL');
    }
    var objPA = document.getElementById('StatsL');
    objPA.onmouseover = function(){
        turnOnLink('StatsL');
    }
    objPA.onmouseout = function(){
        clearAllLinks();
    }

    for(var i= 0; i < objA.length; i++){
        if(objA[i].className == 'LinksC') {
            objA[i].onmouseover = function(){
                this.click = false;
                this.style.color = '#000000';
                this.style.background = '#FFFF00';
            }
            objA[i].onmouseout = function(){
                if(!this.click){
                    this.style.color = '#FFFFFF';
                    this.style.background = '#2a7467';
                }
            }
            objA[i].onclick = function(){
                this.click = true;
                this.style.color = '#FFFFFF';
                this.style.background = '#2a7467';
                clearAllLinks();
            }
        }
    }
    objPA = document.getElementById('LinksA');
    objPA.onmouseover = function(){
        clearLink('ProfileL');
        clearLink('StatsL');
        turnOnLink('LinksL');
    }
    var objPA = document.getElementById('LinksL');
    objPA.onmouseover = function(){
        turnOnLink('LinksL');
    }
    objPA.onmouseout = function(){
        clearAllLinks();
    }

}

function turnOnLink(s){
    var objL = document.getElementById(s);
    objL.style.visibility = 'visible';
    var ss = s.substring(0,s.length);
    objL = document.getElementById(ss);
    objL.style.color = '#FFFFFF';
    objL.lineHeight = '1.5em';
    objL.style.background = '#2a7467';
    objL.style.marginBottom = '1px';
    var objB = objL.getElementsByTagName('li');
    if(objB.length <= 0) return;
    for(var i=0; i < objB.length; i++){
        objB[i].style.borderBottom = '1px solid white';
    }
}

function clearLink(s){
    var objL = document.getElementById(s);
    objL.style.color = '#FFFFFF';
    objL.style.background = '#2a7467';
    objL.style.visibility = 'hidden';
}

function clearAllLinks(){
    clearLink('ProfileL');
    clearLink('StatsL');
    clearLink('LinksL');
//    var objL = document.getElementById('ProfileL');
//    objL.style.display = 'none';
 //   objL = document.getElementById('StatsL');
 //   objL.style.display = 'none';
 //   objL = document.getElementById('LinksL');
//    objL.style.display = 'none';
}

function clearDivision(s){
    var objD = document.getElementById(s);
    objD.style.display = 'none';
}

function turnOnDivision(s){
    var objS = document.getElementById(s);
    objS.style.display = 'block';
    objS.style.width = screenSize() - rightOffsetCorrection;
}

function clearAllDivisions(){
    clearDivision('rabunLakes');
    clearDivision('rabunPopulation');
    clearDivision('rabunWeather');
	clearDivision('mainText');
    clearDivision('genInfo');
}

function startUp(){
    if(!document.getElementsByTagName) return;
    if(!document.getElementById) return;
    clearAllLinks();
    clearAllDivisions();
    turnOnDivision('mainText');
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

WindowDoResize = function (){
var s = location.href;
    location.replace(s);
}

WindowResize = function(){
    window.onresize = WindowDoResize;
}

    addLoadEvent(linkEventHandlers);
    addLoadEvent(startUp);
//    addLoadEvent(WindowResize);

