// 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() {
		
		
	}
	
	function initHP() {
		
		$(document).ready(function () {
			// INPUT FILLIN DIVS INIT
			inputFillInText([
								'findvet_q_txt',
								'your_petprofile_q_txt',
								'enewsletter_email_txt',
								'username_txt',
								'password_txt'
							],
							[
								"Your postcode",
								"Your Pets' Name",
								"Your Email Address",
								"Your Email Address",
								"Your password"
							]
							);
		});

	}

	function initMyPetHP() {
		
		$(document).ready(function () {
			// INPUT FILLIN DIVS INIT
			inputFillInText([
								'username_txt',
								'password_txt'
							],
							[
								"Your Email Address",
								"Your password"
							]
							);
		});

	}
	
	function initClinicHP() {
		
		$(document).ready(function () {
			// INPUT FILLIN DIVS INIT
			inputFillInText([
								'enewsletter_email_txt',
								'mypet_username_txt',
								'mypet_password_txt'
							],
							[
								"Your Email Address",
								"Your Email Address",
								"Your password"
							]
							);
		});

	}
	
	/////////////////////////////////
	//	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 = $('div .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 = this.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).addClass("hover");
			}
			
			elem.onmouseout = function() {
				$(this).removeClass( "hover" );
			}

		}
	}
	
	
	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 + 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(field_ids,fillin_strings) {
	
	for (var i=0; i<field_ids.length; i++) {
		
		var input_id = field_ids[i];
		var input = $("#" + input_id);
		
		// insert field wrapper
		$(input).wrap("<div class=\"fillin_txt_wrapper\"></div>")
		
		// insert field text div
		
		// ensure div doesnt show if text is defined
		var fillin_style= "visibility: hidden;";
		if ( input.attr('value') == "" ) { fillin_style = "visibility: visible;" }
		
		var fillin_class = "fillin_txt"
		if ( $.browser.msie == true  ) { fillin_class += "_ie" }
		
		var fillin_div_id = "fillindiv_" + field_ids[i];
		var fillin_div_html="<div id=\"" + fillin_div_id + "\" style=\"" + fillin_style + "\" class=\"" + fillin_class + "\">" + fillin_strings[i] + "</div>";
		$(input).after(fillin_div_html);
		
		var fillin_div = $("#" + fillin_div_id);
		
		// save reference to fillin div under field
		$(input).attr("fillin_div_id", fillin_div_id );
		$(fillin_div).attr("input_id", input_id );
		
		try{
			window.setTimeout( function(input) {
			
				if ( $(input).val() != "" )
				{
					$("#" + $(input).attr("fillin_div_id")).css("visibility","hidden");
				}
			}, 500, input );
		}
		catch(e)
		{}
		
		// set events
		$(input).focus(
			function() {
				var fillin_div = $( "#" + $(this).attr("fillin_div_id") );
				//if ( this.value == "" ) {
					fillin_div.css("visibility","hidden");
				//}
			}
		)
		$(input).blur(
			function() {
				var fillin_div = $( "#" + $(this).attr("fillin_div_id") );
				if ( this.value == "" ) {
					fillin_div.css("visibility","visible");
				}
			}
		)
		$(fillin_div).bind( "focus click",
			function() {
				var input = $( "#" + $(this).attr("input_id") );
				$(input).focus();
			}
		)
	
	}
	
}


function serviceRedirect(){
	var serviceSelect = document.getElementById("service_id");
	//alert("/content.cfm?id=" + serviceSelect.value);
	document.location.href = "/content.cfm?id=" + serviceSelect.value;
	return false;
}