// Image rollover definition

var imgs = new Array(
{suffix: '.gif', 
 prefix: 'img/', 
 states: ['', '_on'], 
 filenames: []}
);

// swap image function

var imgObjs = [];
for(j = 0; j < imgs.length; j++){
  i = imgs[j];
  for(k = 0; k < i.filenames.length; k++){
    file = i.filenames[k];
    for(state in i.states){
      name = file + i.states[state];
      imgObjs[name] = new Image();
      imgObjs[name].src = i.prefix + name + i.suffix;
    }
  }
}
delete imgs;

function swap(img, val){

  if(!document.images) return;
  document.images[img].src = imgObjs[val].src;
}

// popup window

var forcedRefresh = true;
var alreadyopen = new Array();
var newwin = new Array();

function openCenteredWindow(theURL, winName, features, w, h){
  var winl = parseInt((screen.width - w - 10) / 2);
  var wint = parseInt((screen.height - h - 29) / 2);
  openWindow(theURL, winName, features + ',height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl);
}

function openWindow(theURL, winName, features){
  if(forcedRefresh == false && alreadyopen[winName] && !newwin[winName].closed){
    newwin[winName].focus();
  }
  else{
    alreadyopen[winName] = 1;	
    newwin[winName] = window.open(theURL, winName, features);
    newwin[winName].focus();
  }
}

function openImage(src, width, height){
  openCenteredWindow('/include/display_image.html?src=' + src + '&width=' + width + '&height=' + height,'imgwin','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no', width + 40, height + 75);
}


// class manipulation

function setClassname(id, classname){ document.getElementById(id).className = classname; }
function getClassname(id){ return document.getElementById(id).className; }
function replaceClassname(id, find, replace){ setClassname(id, getClassname(id).replace(new RegExp(find), replace)); }

/* show hide drop down menus */

var old_menu = null, hide = null;
function hide_menu(id){
	if(id == null) return;
	obj = document.getElementById('dropnav-' + id);
	navobj = 'nav-' + id;
	if(obj) obj.style.visibility = 'hidden';
    if(navobj) replaceClassname(navobj, 'nav_mouseon', 'nav_mouseoff');
	clear_timeout();
}

function show_menu(id){
	if(old_menu) hide_menu(old_menu);
	obj = document.getElementById('dropnav-' + id);
	navobj = 'nav-' + id;
	if(obj){
		obj.style.visibility = 'visible';
	    obj.className = 'menu_navigation';
	}
	if(navobj){
	    replaceClassname(navobj, 'nav_mouseoff', 'nav_mouseon');
	}
	old_menu = id;
	clear_timeout();
}

function set_timeout(){
	hide = setTimeout("hide_menu('" + old_menu + "')",700);
}

function clear_timeout(){
	clearTimeout(hide);
}
