// library of functions

function initPage(){
	// setup variables

	var leftPos = null;
	var topPos = null;

	allOff();	
	positionSubLinkDivs();		
	onResize = function() { positionSubLinkDivs(); } 
	
	var randomNumber = Math.floor(Math.random()*4) + 1;
	var divName = "subLinks"+ randomNumber;
	//alert(divName);
	show(divName);
		
}

	// center all subLinks divs on page
function positionSubLinkDivs(){
	
	var topPos = null;
	getScreenSize();
	
	// add some space for mac browsers, all execept for Mac IE.
	//if (navigator.appVersion.indexOf('Mac') != -1 && navigator.appName.indexOf("Microsoft")==-1) leftPos += 8;
	
	if (navigator.appName=="Microsoft Internet Explorer" && document.documentElement.clientHeight){		// IE 6 
		// drop div down for IE 6
		topPos += 14;
	} 
	
	moveDivTo('subLinks1', leftPos, topPos);
	moveDivTo('subLinks2', leftPos, topPos);
	moveDivTo('subLinks3', leftPos, topPos);
	moveDivTo('subLinks4', leftPos, topPos);
	moveDivTo('subLinks5', leftPos, topPos);
}

function getScreenSize(){
		width =	windowWidth();
		if(width > 880){
			leftPos = width / 2 -666;
		} else {
			leftPos = -266;
		}
}

function windowWidth(){

    if (window.innerWidth){
        if (document.body.offsetWidth){
            if (window.innerWidth!=document.body.offsetWidth)
                return document.body.offsetWidth;
            }
        return (window.innerWidth);                     // Mozilla
    }


    if (document.documentElement.clientWidth)
        return document.documentElement.clientWidth - 20;    // IE6


    if (document.body.clientWidth)
        return document.body.clientWidth;               // IE DHTML-compliant any other
}

function moveDivTo(moveDiv, x, y) {
	myReference = getRefToDiv(moveDiv);
	if( !myReference ) { return; }
	if( myReference.style ) { myReference = myReference.style; }
	var noPx = document.childNodes ? 'px' : 0;
	var posLeft =  x + noPx;
	var posTop = y + noPx;
	
	//alert("moving div top: " + posTop + " and left: " + posLeft);
	
	myReference.left = posLeft ;
	myReference.top = posTop ;
}

function show(divName){
	allOff();
	document.getElementById(divName).style.visibility='visible';
}

function getRefToDiv(divID,oDoc) {
   if( !oDoc ) { oDoc = document; }
   if( document.layers ) {
       if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {
           //repeatedly run through all child layers
           for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
               //on success, return that layer, else return nothing
               y = getRefToDiv(divID,oDoc.layers[x].document); }
           return y; } }
   if( document.getElementById ) {
       return document.getElementById(divID); }
   if( document.all ) {
       return document.all[divID]; }
   return false;
}

function visibilityToggle(){
	if(toggle) allOff();
	document.getElementById(divName).style.visibility=toggle;
}

function allOff(){
	document.getElementById('subLinks1').style.visibility='hidden';
	document.getElementById('subLinks2').style.visibility='hidden';
	document.getElementById('subLinks3').style.visibility='hidden';
	document.getElementById('subLinks4').style.visibility='hidden';
	document.getElementById('subLinks5').style.visibility='hidden';
}
