

$(function() {
	initReportPopup();
	initExternalLinks();
	initBanners();
});

function initReportPopup() {
	$("#report-banner a").click( function() {
		window.open(
			$(this).attr('href'), 
			"ReportWindow", 
			"status = 0, height = 650, width = 690, resizable = 0, scrollbars = 1" );
		return false;
	});
}

function initBanners() {	
	$("#banner .contents > *:gt(0)").hide();
	$("#banner .contents").css({ height: $("#banner .contents").height() });
	
	if ($("#banner p").length < 2) return;
	
	
	var speed = 1000;
	var delay = 6000;
	
	$("#banner").fadeTo(delay, 1.0, next);	
	
	function next() {
		if ($("#banner p:visible").nextAll("p:first").length > 0) {
			$next = $("#banner p:visible").nextAll("p:first");
		} else {
			$next = $("#banner p:first");		
		}
		fade($next);
	}
	
	function fade($next) {
		$("#banner p:visible").fadeOut(speed);
		$next.delay(1000).fadeIn(speed);
		$("#banner").fadeTo(delay, 1.0, next);		
	}	
}

/* External Links and PDF Links
===================================================================================== */
function initExternalLinks() {
    var h = window.location.host.toLowerCase();
    $("a[href^='http']:not([href^='http://" + h + "']):not([href^='http://www." + h + "']), a[href$='.pdf']").attr("target", "_blank");
}
