$(document).ready(function(){
	$("#snset2 a[href=http://www.sanfordhealth.org/doctors/search]").click(function () {
		doctorsWin = window.open(this.href,'doctors','height=630,width=980,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes');
		doctorsWin.focus();
		return false;
	});
	$("#snset2 a[href=http://www.sanfordhealth.org/locations]").click(function () {
		locationsWin = window.open(this.href,'locations','height=630,width=980,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes');
		locationsWin.focus();
		return false;
	});
						   
// Place "hint" labels into their items
	$("label.hint").each(function(){
		var text = $(this).text();
		var item = $(this).attr("for");
		if (item.length > 0) {
			$item = $("[name="+item+"]");
			$item
				.focus(function(){ if($(this).val() == text) { $(this).val(""); } })
				.blur(function(){ if($(this).val() == "") { $(this).val(text); } });
				
			var value = $item.val();
			if (value === "") { $item.val(text); }
		}
	}).hide();

// Produces an "Embed" button, hiding the embed options
	embedTimer = 0;
	$(".video .details .toolbar")
		.width(194)
		.children(".embed")
			.children("input")
				.click(function(){
					$(this).select();
				})
				.end()
			.children("form")
				.children("select")
					.change(function(){
						var selVideoEmbed = $(this).val()
						var embed = $(this).parent().prev("input");
						var embed_code = embed.val();
		
						embed_code = embed_code.replace(/width="\w+"/g, "width=\"" + selVideoEmbed.split("x")[0] + "\"");
						embed_code = embed_code.replace(/height="\w+"/g, "height=\"" + selVideoEmbed.split("x")[1] + "\"");
						
						embed.val(embed_code);
					})
					.end()
				.end()
			.addClass("embed_js")
			.wrapInner("<div class=\"wrap\"></div>")
			.hover(function(){
				clearTimeout(embedTimer);
				
				$(this).children(".wrap").show();
			}, function(){
				embedTimer = setTimeout("$(\".video .details .toolbar .wrap\").hide();", 2000);
			});
});

function validateSearch(theForm) {
	if ((theForm.qt.value === "") || (theForm.qt.value == "keyword search")) {return false;}
	else {return true;}
}
function deactivateSearch(theInput) {
	if (theInput.value === "") {theInput.value = "keyword search";}
}
function activateSearch(theInput) {
	theInput.value = "";
}

var enform;
var entrigger;
var eninput;
var timeout1 = 0;
addLoadEvent(function() {
		enform = document.getElementById("enewsentry");
		entrigger = document.getElementById("enewstrigger");
		entrigger.onmouseover = function() {
				toggleDisplay(enform,true);
				delayHideENews(10000);
			};
		eninput = document.getElementById("enemail");
		eninput.onfocus = function() {
				delayHideENews(10000);
				this.select();
			};
		eninput.onkeyup = function() {
				delayHideENews(15000);
			};
	});
function delayHideENews(ms) {
	window.clearInterval(timeout1);
	timeout1 = window.setInterval(hideENews,ms);
}
function hideENews() {
	toggleDisplay(enform,false);
	window.clearInterval(timeout1);
}

addLoadEvent(function () {
	/* hide repeated banners */
	var advcontainer = document.getElementById("advertising_content");
	if(advcontainer !== null) {
		var advbanners = advcontainer.getElementsByTagName("img");
		if (advbanners.length === 0) {
			toggleDisplay(advcontainer,false);
			var infcontainer = document.getElementById("information_content");
			infcontainer.style.width = "660px";
		} else {
			var uniqueflag = 1;
			var uniqueimgs = [advbanners[0].src];
			for(var i=1; i<advbanners.length; i++) {
				uniqueflag = 1;
				for(var j=0; j<uniqueimgs.length; j++) {
					if(advbanners[i].src == uniqueimgs[j]) {
						advbanners[i].style.display = "none";
						uniqueflag = 0;
						break;
					}
				}
				if(uniqueflag) {uniqueimgs.push(advbanners[i].src);}
			}
		}
	}
	/* set information_content height */
	var icontent = document.getElementById("information_content");
	if (!icontent) { icontent = document.getElementById("information_content_wide"); }
	var navcontent = document.getElementById("svmain_leftcolumn");
	var newheight = "" + navcontent.offsetHeight-icontent.offsetHeight-215;
	if (newheight > 0) {
		icontent.style.paddingBottom = newheight + "px";
	}
});
