// JavaScript Document

function sb_popup(vFile,vWidth,vHeight) {

	if (vWidth <= 0) vWidth = 600;
	if (vHeight <= 0) vHeight = 600;

	new_win = window.open (vFile, 'sbPopup', 'status=1,width=' + vWidth + ',height=' + vHeight + ',scrollbars=1,resizable=1,status=0');
	new_win.focus();

}



var preload_imgs = new Array();



function initUI() {

	initHoverButtons();

	preloadImgs();
	
	//initNav();

}

function preloadImgs() {

	var args = preload_imgs;

	document.imageArray = new Array(args.length);

	for(var i=0; i<args.length; i++) {

		document.imageArray[i] = new Image;

		document.imageArray[i].src = args[i];

	}

}

document.getElementsByClassName = function(cl) {

	var retnode = [];

	var myclass = new RegExp('\\b'+cl+'\\b');

	var elem = this.getElementsByTagName('*');

	for (var i = 0; i < elem.length; i++) {

	var classes = elem[i].className;

	if (myclass.test(classes)) retnode.push(elem[i]);}

	return retnode;

};


function initHoverButtons() {

	var butElements = document.getElementsByClassName('hoverbutton');
	// run through all elements with 'hoverbutton' class:

	for (var i = 0; i < butElements.length; i++) {

		var elem = butElements[i];		
		preload_imgs.push(genHoverSrc(elem.src,2));
		elem.onmouseover = function() {
			this.src = genHoverSrc(this.src,2);
		}

		elem.onmouseout = function() {
			this.src = genHoverSrc(this.src,1);
		}
	}
}



function genHoverSrc(img_src,state) {

	var ext = img_src.substring(img_src.length-4,img_src.length);

	var pre_ext = img_src.substring(0,img_src.length-5);

	return(pre_ext + state.toString() + ext);

}


var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height, scrollbars) {
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }

	// center window
	w = screen.availWidth;
	h = screen.availHeight;

	var popW = width, popH = height;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	// end center window
  
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrollbars+',resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+leftPos+', top='+topPos+',screenX='+leftPos+',screenY='+topPos+'');
}

function popUpVid(vid_url) {
	popUpWindow(vid_url, 100, 100, 620, 400, "no","no");
}



// sets up a fillin text input - eg: search boxes where text "Enter your search query here" is inserted when nothing is contained in field.
function inputFillInText(form_name,field_name,fillin_str) {
	var input = document.forms[form_name].elements[field_name]; 
	
	input.value = fillin_str;
	input.fillin_str = fillin_str
	input.onfocus = function() {
		if (this.value == this.fillin_str) {
			this.value = "";
		}
	}
	input.onblur = function() {
		if (this.value == "") {
			this.value = this.fillin_str;
		}
	}
	
}