/*********************************************************************************
 Global variables
*********************************************************************************/
//Default browsercheck
function browsercheck(){
    this.ver=navigator.appVersion
    this.agent=navigator.userAgent
    this.dom=document.getElementById?1:0
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
    this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
    this.ie4=(document.all && !this.dom)?1:0;
    this.ie=this.ie4||this.ie5||this.ie6
    this.mac=this.agent.indexOf("Mac")>-1
    this.opera5=this.agent.indexOf("Opera 5")>-1
    this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
    this.ns4=(document.layers && !this.dom)?1:0;
    this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5 || this.dom)
    return this
}
var bw=browsercheck()
var PageImages = new Array();
var PageAltImages = new Array();

if(!bw.bw){
        alert("I'm sorry some of the scripts on this page may not work with\n" +
              "your browser.  Please update your browser and visit again.\n");
}

//set the length of the timeout, in milliseconds
speed = 100;

//image preload
		
function LoadActiveImages() {
	var num = document.images.length;
	for (var i = 0; i < num; i++) {
		var thisImage = document.images[i];
		var thisImageSrc = thisImage.src;
		var imageName = thisImageSrc.substring(0,thisImageSrc.lastIndexOf("_o"));
		//document.write(imageName + "<BR>");
		if (thisImageSrc.lastIndexOf("_off") != -1) {
			PageImages[i] = new Image(thisImage.width, thisImage.height);
      	    PageImages[i].src = imageName + "_on.gif";
		} else if (thisImage.src.lastIndexOf("_on") != -1) {
			PageAltImages[i] = new Image(thisImage.width, thisImage.height);
      	    PageAltImages[i].src = imageName + "_off.gif";
		}
    }
}

function init(){
	//initialize the timer array
	timer_array = new Array();
	timer_array["res"] =new Object({isOver:false,timer:null});
	timer_array["lib"] =new Object({isOver:false,timer:null});
	timer_array["liq"] =new Object({isOver:false,timer:null});
	timer_array["new"] =new Object({isOver:false,timer:null});
	timer_array["hel"] =new Object({isOver:false,timer:null});
}


function printPage() {
	if (window.print){
   		window.print()
  	} else {
    	alert("Sorry, your browser doesn't support this feature. \nUse the print option on your browser to print this page"); }
}


// Setting the visibility of an object to visible
function show(obj) {
	//get a convenient reference to the object
	var theObj = document.getElementById(obj);
	if (theObj.style.visibility != "visible") {
		theObj.style.visibility="visible"
	}
	//set this.isOver
	timer_array[obj].isOver = true;
	//cancel the timer, and set the isOver to false
	window.clearTimeout(timer_array[obj].timer);
	timer_array[obj].timer = "";
}

// Setting the visibility of an object to hidden
function hide(obj,img) {
//get a convenient reference to the object
	var theObj = document.getElementById(obj);
	//hide the object now, is the mouse is not over it
	if(!timer_array[obj].isOver){
		if (theObj.style.visibility != "hidden") {
			theObj.style.visibility = "hidden";
			//alert("get image"+document.getElementById(img).src + "\nimg=" + img);
			//alert("timer_array[obj] "+timer_array[obj].showImage);
			if(timer_array[obj].showImage!=true){
				var imageName = document.getElementById(img).src.substring(0,document.getElementById(img).src.lastIndexOf("_o"));
				//alert("get image"+imageName);
				document.getElementById(img).setAttribute("src",imageName + "_off.gif");
			}
			timer_array[obj].showImage = false;
		}
	}
}

// Setting the timeout for hiding this item
function hideSlow(obj,showImage) {
	//set a timer for this menu item, and set this.isOver to false, so that the setTimeout will execute
	if(!showImage){""}else{timer_array[obj].showImage = true};
	
	timer_array[obj].timer = window.setTimeout("hide(" + "\'" + obj + "\',\'tnav-"+obj+ "\')", speed);
	timer_array[obj].isOver = false;
}	

function imageSwap(which, state) {
     
	//which - required input of image name
	//state - required input of image rollover state (1 for on, 0 for off)
	//div1,div2,... - optional input layer hierarchy for Netscape 4.0 browsers
	//get the element obj reference
 bw.dom?thisImage=document.getElementById(which):bw.ie4?document.all[which]:thisImage=document[which];
	
	//find the image src name
	var imageName = thisImage.src.substring(0,thisImage.src.lastIndexOf("_o"));
	//toggle the src name based on state
	state == 0?endString = "_off.gif":endString = "_on.gif";
	//alert(layerOver);
	//set the image src to the new src
	bw.dom?thisImage.setAttribute("src",imageName + endString):thisImage.src=imageName + endString;
}

function imageSwapSlow(obj, state) {
	//clear any timeouts for imageSwapSlow
	//timer2=(!timer2) ? '':window.clearTimeout(timer2);
	
	//set the new timeout
	timer2 = window.setTimeout("imageSwap(" + "\'" + obj + "\'," + state + ")", speed)	
}


/*

Function that lets us hide or show a div/element. 

*/
function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}


/* 

*/

function removeDefaultText(ob)
{
	var active_color = '#000'; // Colour of user provided text

	if(ob.value == 'Search Library Catalogue...') {
		ob.value = '';
		ob.style.color = active_color;

	}
	
}

function restoreDefaultText(ob)
{

	var inactive_color = '#666';

	if(ob.value == '') {
		ob.value = 'Search Library Catalogue...';
		ob.style.color = inactive_color;


	}
}


init();

