//finalsiteCf global.js
//v. 1.2

// swapImage() & imgRestore()

//Time before menus auto-hide
var menu_pause = 250; 

//Show sub-menus for current section( 0=no, 1=yes)
var section_subs = 0;

//Use auto position find for the menus( 0=no, 1=yes)
//Used for relatively positioned/centered layouts
//This option can be turned on for individual layouts by setting it in the <head> tag
var pos_find = 1;

// Set offsets for the menus
    // x/y offset from top left corner of parent button
    var pos_x = 0; 
    var pos_y = 0;
    
    // browser specific offsets(added to offsets above) for netscape
    // base browser is IE
    var ns6_xoffset = 0;
    var ns6_yoffset = 0;

var sectionId = "";
var sectionBtn = "";
var thisMenu = "";
var wait;

// Browser Check
var isIE = (document.all) ? true : false;
var isNS4 = (document.layers) ? true : false;
var isNS6 = (document.getElementById && !isIE) ? true : false;

//Browser Specific CSS Code

if(isIE){ document.write( "<style>#ql_menu a, #sitetools_menu a{ width:100%; }</style>" ); }


// Button Object Constructor
function btnObj(btnName,menuName,pageId,offSrc,onSrc,selectSrc) {
				 this.btnName = btnName;
				 this.menuName = menuName;
				 this.pageId = pageId;
				 this.offSrc = offSrc;
				 this.onSrc = onSrc;
				 this.selectSrc = selectSrc;
}


function pageLoad() { preLoad(); }

function preLoad(){ //preLoad loops through the buttons array and loads all of the onSrc's
										//Also defines sectionID & sectionBtn & turns on section button
        if(document.images){
														var myImages = new Array();
														var i = 0;
														for(this.btnName in buttons){
															myImages[i] = new Image(); myImages[i].src = buttons[this.btnName].onSrc;
  														i++;
                              var n=0;
															for(n in pagearray){
  															if( pagearray[n] == buttons[this.btnName].pageId){
																	document.images[this.btnName].src = buttons[this.btnName].selectSrc ? buttons[this.btnName].selectSrc : buttons[this.btnName].onSrc;
																	sectionId = buttons[this.btnName].pageId;
                                  sectionBtn = buttons[this.btnName].btnName;
																}
															n++;
															}
														}
				}
}

function swapImage(btn){ //swapImage creates a roll-over effect from onSrc when passed the name of the button
				 								 //Also shows sub-menus if specified
				if(buttons[btn].pageId != sectionId){
         	document.images[btn].src = buttons[btn].onSrc; //Turn button on
        }
         
         //check btnID against sectionId and section_menu variable before turning on sub menus
         if( buttons[btn].menuName ){ //Turn on menus if section sub option is on or the button pageId does not equal the sectionId
						 showSubs(btn);
				 }
}

function imgRestore(btn){ // turns button off unless it is the section button or has a menu
         if(buttons[btn].menuName){ // && section_subs == 1
				 	mnuOut(btn);
         }else if(buttons[btn].pageId != sectionId){
         			document.images[btn].src = buttons[btn].offSrc;
				 }
}


//Sub Menus
function showSubs(btn){
      if((thisMenu.length>0) && (thisMenu != buttons[btn].btnName)){
      	clearSubs(thisMenu);
			}
				 // set offsets based on browser			 
				 var x_offset = (isNS6) ? ns6_xoffset : 0;
				 var y_offset = (isNS6) ? ns6_yoffset : 0;
				 

				  if(section_subs == 1 || (buttons[btn].pageId != sectionId)){ //Test for section subs option and section ID
				 			if(pos_find==1){
									document.getElementById(buttons[btn].menuName).style.left = findPosX(document.getElementById(buttons[btn].btnName)) + (pos_x - x_offset);
				 					document.getElementById(buttons[btn].menuName).style.top = findPosY(document.getElementById(buttons[btn].btnName)) + (pos_y - y_offset);				 			 
				 			}
				 			document.getElementById(buttons[btn].menuName).style.visibility = 'visible';
              thisMenu = buttons[btn].btnName; //add menu to close later
				 }
         
         clearTimeout(wait);
}

function mnuOut(btn){
         wait = setTimeout("clearSubs('"+ btn +"')", menu_pause);
}

function clearSubs(btn) { //clears open menu
				 if(buttons[btn].menuName){
				 document.getElementById(buttons[btn].menuName).style.visibility='hidden';
         thisMenu="";
				 }
         if(buttons[btn].pageId != sectionId){
				 	document.images[btn].src = buttons[btn].offSrc; //turn button back off
		 }else if(buttons[btn].selectSrc){
				 	document.images[btn].src = buttons[btn].selectSrc;
				 }
}


//Automatically find x,y positions of objects
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
//end Sub Menus


