function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
	thefield.value = ""
} 
function addText(thefield){
	if(thefield.value == '') {
		thefield.value = thefield.defaultValue;
	}
}
/**
	popupPublication opens a url in a new chromeless window
	a link using this function might look something like this:
**/
function popupPublication(url /*address to launch (String)*/) 
{
	var newWindow;
	try{
		newWindow = window.open(url, "publication", "fullscreen=no,resizable=no,status=no,toolbar=no,menubar=no,location=no,top=0,left=0");
		if (newWindow == undefined || newWindow==null || typeof(newWindow)=="undefined") {
			alert("Your browser may have blocked the launch of this publication.  Please allow this site to open pop-ups and try again.");
		}
		else{
			newWindow.moveTo(0,0);
			newWindow.focus();
		}
	}catch(e){
		//access was denied for some reason
		return true;
	}
}
$(document).ready(function() {
	var t = null;
	$cur_ul = null;
	$cur_li = null;
	$('#primaryNavigation ul li.top-nav').hover(
		function() {
			clearTimeout(t);
			if($cur_ul && $cur_ul.length > 0) {
				$cur_ul.hide();
				$cur_li.removeClass('hover');
			}
			$cur_li = $(this);
			$cur_ul = $cur_li.find('ul');
			if($cur_ul && $cur_ul.length > 0) {
				$cur_ul.hide().show();
				$cur_li.addClass('hover');
			}
		},
		function() {
			t = setTimeout(function() {
				if($cur_ul && $cur_ul.length > 0) {
					$cur_ul.hide();
					$cur_li.removeClass('hover');
				}
			}, 500);
		}
	);
	$('body').click(function() {
		if($cur_ul && $cur_ul.length > 0) {
			clearTimeout(t);
			$cur_ul.hide();
			$cur_li.removeClass('hover');
		}
	});
	if($('#mapCanvas').length != 0) {
		initialize();
	}
});

//original script from dynamic drive
var ddwindowlinks={
	//1) Enter domains to be EXCLUDED from opening in new window:
	excludedomains: ["cumberlandcid.org","jacksonspalding.com"],
	//2) Target for links that should open in a new window (ie: "_blank", "secwin" etc):
	linktarget: "_blank",
	//3) Track External links and PDFs
	tracking: true,
	//4) Open external links and pdf's in new window, add google tracking code to onclick, add pdf or external class to show icons
	assigntarget:function(){
		var rexcludedomains=new RegExp(this.excludedomains.join("|"), "i")
		var all_links=document.getElementsByTagName("a")
		for (var i=0; i<=(all_links.length-1); i++){
			if ((all_links[i].hostname.search(rexcludedomains)==-1 && all_links[i].href.indexOf("http")!=-1)
									|| (all_links[i].getAttribute('rel') != null && all_links[i].rel == "external")) {
				all_links[i].target=ddwindowlinks.linktarget
				if(this.tracking && undefined == all_links[i].onclick) {
					if(all_links[i].attachEvent) {
						all_links[i].onclick = function() { pageTracker._trackPageview('/external/' + this.href); }
					} else {
						ptv = "pageTracker._trackPageview('/external/" + all_links[i].href + "')"
						all_links[i].setAttribute('onclick', ptv)
					}
				}
				if(all_links[i].getAttribute('rel') != null && all_links[i].rel == "noarrow") {
					//don't add external class
				} else {
					all_links[i].className += all_links[i].className ? ' external' : 'external'
				}
			} else if (all_links[i].href.toLowerCase().indexOf('.pdf')!=-1) {
				all_links[i].target=ddwindowlinks.linktarget
				if(this.tracking && undefined == all_links[i].onclick) {
					if(all_links[i].attachEvent) {
						all_links[i].onclick = function() { pageTracker._trackPageview('/pdf/' + this.href); }
					} else {
						ptv = "pageTracker._trackPageview('/pdf/" + all_links[i].href + "')"
						all_links[i].setAttribute('onclick', ptv)
					}
				}
				all_links[i].className += all_links[i].className ? ' pdf' : 'pdf'
			}
		}
	},
	//5) Initialize
	init:function(){
		if (window.addEventListener)
			window.addEventListener("load", function(){ddwindowlinks.assigntarget()}, false)
		else if (window.attachEvent)
			window.attachEvent("onload", function(){ddwindowlinks.assigntarget()})
	}
}
//6) Call the Initialize function
ddwindowlinks.init()
