targets = {
	hostname: window.location.hostname.replace("www.","").toLowerCase(),
	a: document.getElementsByTagName("a"),
	check: function(obj) {
		var href = obj.href.toLowerCase();
		if ((href.indexOf("http")!=-1 && href.indexOf(this.hostname)==-1) || (obj.className.indexOf("external")!=-1)) {
			return 'offsite';
		} else if (obj.className.indexOf("popup")!=-1) {
			return 'popup';
		} else {
			return false;
		}
	},
	set: function(obj) {
		obj.target = "_blank";
		obj.className += " external";
	},
	popup: function(obj) {
		obj.className += " popup";
		obj.href = "javascript:popup('"+obj.href+"','"+obj.title+"','800','450');";
	},
	init: function() {
		for (var i=0;i<this.a.length;i++) {
			if (this.check(this.a[i]) == 'offsite') {
				this.set(this.a[i]);
			} else if (this.check(this.a[i]) == 'popup') {
				this.popup(this.a[i]);
			}
		};
	}
}

function popup(mypage,myname,w,h){
	LeftPosition = (screen.width) ? (screen.width-w)/2: 100;
	TopPosition = (screen.height) ? (screen.height-h)/2: 100;
	settings = 'width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,location=yes,directories=no,status=yes,menubar=no,toolbar=no,resizable=yes';
	win = window.open(mypage,myname,settings);
}

$(document).ready(function () {
	$('a.lightbox').each(function(){
		$(this).lightBox();
	});
	targets.init();
	if (null != document.getElementById("historical-results")) {
		setupResultsPageNav(3);
	}
});
