//rollovers

// preload(imagename string, [imagename string], [imagename string], etc...)
// Use this function to precache rollover images
// this could be modified to use a image file name pattern so only a short image identifier needs to be passed in
// for example: preloaded[i].src = 'images/nav_' + args[i] + '_over.gif';

function preload() {
	var preloaded = new Array();
	for (i=0;i<arguments.length;i++) {
		preloaded[i] = new Image();
		preloaded[i].src = arguments[i];
	}
}

// swap(image string, on boolean)
//  name pattern based on/off state swap function
//  requires oldswapsrc

var oldswapsrc = new Array();  //required for swap()

function swap(image, on) {
    var img = document.images[image];
	if (on) {
        if (img.src != img.src.replace(/_off/gi, '_on')) {oldswapsrc[image] = img.src;}
		img.src = img.src.replace(/_off/gi, '_on');
	} else {
		if (oldswapsrc[image]) img.src = oldswapsrc[image];
	}
}


function swap2(image, over) {
	if (over) {
		document.images[image].src = document.images[image].src.replace(/_off/gi, '_on');
	} else {
		document.images[image].src = document.images[image].src.replace(/_on/gi, '_off');
	}
}

// swapAnother(image string, src string)
//  use for swapping any named image with any other image
function swapAnother(image, src) {
	document.images[image].src = src;
}

// rollon and rollout are used together and require oldrollsrc to be defined.
//  rollon swaps the image 'imagename' with the 'newimage' and remembers the original state in the 'oldrollsrc' variable.
//  rollout restores the image 'imagename' to the 'oldrollsrc'
//  this function is useful in topnav applications where images may have an 
//  'On' state (for the section you are currently in, for example) as well as an 'Over' and 'Off' state.

var oldrollsrc = '';  // required for rollon()/rollout()

function rollon(imagename, newimage) {
    var img = document.images[imagename];
    oldrollsrc = img.src;
    img.src = '/img/' + newimage;
    }

function rollout(imagename) {
    var img = document.images[imagename];
    img.src = oldrollsrc;
    }
//
    
// changeBG(item string, color string-hexvalue)
//  Use this function to change the background color of a table cell on rollover
//  To use, the <td> tag needs to have 'id' and 'name' attributes defined specific to the cell.
//  <td id="aboutsection_leftnav" name="aboutsection_leftnav" onMouseover="changeBg('aboutsection_leftnav', '#ededed');" onMouseout="changeBg('aboutsection_leftnav', '#ffffff');"></td>
//  
function changeClass(item, newclass) {
	var cell = document.getElementById(item);
	cell.className = newclass;
}


// navover and navout are used together and require oldnavcolor to be defined.
//  navover changes the bgcolor style of the 'item' to 'color' and remembers the original color in the 'oldnavcolor' variable.
//  navout restores the bgcolor of 'tem' to the 'oldnavcolor'
//  this function is useful in leftnav applications where nav cells may have an 
//  'On' state (for the section you are currently in, for example) as well as an 'Over' and 'Off' state.

var oldnavcolor = '';
					
function navover(item, color) {
    var navitem = document[item];
    oldnavcolor = navitem.style.backgroundColor;
    navitem.style.backgroundColor = color;
}

function navout(item) {
    var navitem = document[item];
    navitem.style.backgroundColor = oldnavcolor;
}

// swapBG(rowid string, on boolean)
//  name pattern based on/off state swapBG function
//  requires oldswapBG

var oldswapBG = new Array();  //required for swapBG()

function swapBG(row, overcolor) {
    var navitem = document.getElementById(row);
	if (overcolor) {
        if (navitem.style.backgroundColor != overcolor) {oldswapBG[row] = navitem.style.backgroundColor;}
		navitem.style.backgroundColor = overcolor;
        navitem.style.cursor='hand';
	} else {
		if (oldswapBG[row]) 
         {
         navitem.style.backgroundColor = oldswapBG[row];
         navitem.style.cursor='default';
         }
	}
}