// JavaScript Document

	var preload_imgs = new Array();
	
	// define hover images here
	preload_imgs.push('images_site/b_hpinr_logo2.gif')
	preload_imgs.push('images_site/bg_hpinr_pet_disactivetab2.gif')
	//preload_imgs.push('/images_site/bg_hpinr_pet_disactivetab2.gif')
	//preload_imgs.push('/images_site/bg_hpinr_pet_disactivetab2.gif')
	
	
	
	/////////////////////////////////
	//	Function: Initialise UI
	/////////////////////////////////
	function initUI() {
		initHoverDivs();
		initHoverButtons();
		preloadImgs();
	}

	/////////////////////////////////
	//	Function: Preload Images (
	/////////////////////////////////
	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 initHoverDivs() {
		var divElements = document.getElementsByClassName('hvr');
		
		// run through all elements with 'hoverbutton' class:
		for (var i = 0; i < divElements.length; i++) {
			var elem = divElements[i];		
			
			elem.onclick = function() {
				// find first A element
				var elem_children = elem.childNodes;
				var elem_link;
				for (var i=0; i<elem_children.length;i++) {
					if (elem_children[i].nodeName=="A") {
						elem_children[i].onclick=function(){return false;} // cancel a click
						if(elem_children[i].target=="_blank") {
							// open link in window	
							window.open (elem_children[i],"newwindow","location=1,status=1,scrollbars=1,width=640,height=480"); 					
						} else {
							// open link in same window
							document.location.href = elem_children[i];
						}
						break;
					}
				}
												
			}
			
			elem.onmouseover = function() {
				this.className += " hover"
			}
			
			elem.onmouseout = function() {
				this.className = this.className.substring(0, this.className.length - 5);
			}

		}
	}
	
	
	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 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();

}




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;

		}

	}

	

}
