/* 
   Popup Windows
*/

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 + 28, height + 60);
}

// 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);
}


// homepage slideshow

$(function() {
	var slideshow = $('#home_slideshow');

	if(slideshow.length) {
		var items = $('#home_slideshow .home_slideshow_item');
		var length = items.length;
		var active = 0;

		$(items[active]).show();
		
		function homeSlideshowTick() {
			$(items[active]).hide();
			active++;
			
			if(active >= length)
				active = 0;
			
			$(items[active]).show();
		}

		setInterval(homeSlideshowTick, homeSlideInterval*1000);
	}
});