// Holder for flash instances to make less agressive loading
var flashInstances = new Array();

// DOM load
$(document).ready(function() {
	homepageRollovers();
	printLink();
	newWindowLinks();
	tabbedContent();
	quizEnhance();
});

// Window loaded
$(window).load(function() {
	for(flash in flashInstances) {
		eval(flashInstances[flash]).write(flash);
	}
});

/**
 */
function homepageRollovers() {
	$("#homepageBlocks li").hover(
		function() {
			$(this).addClass("over").css({cursor:"pointer"});		
		},
		function() {
			$(this).removeClass("over");
		}
	).click(function(){
		window.location = $("a",this).attr("href");
	});
}

/**
 */
function printLink() {
	$("#bottomLinks li").removeClass("last");
	$("#bottomLinks").append('<li class="last" id="print"><a href="#" onclick="window.print();return false">'+printText+'</a></li>');
	
}

/**
 */
function quizEnhance() {
	$("#quiz p input").hide();
	$("#submitButton").remove();
	$("#quiz p span").addClass("enhanced");
	$("#quiz[class!='disable'] p span").css("cursor","pointer").click(function(){
		$("input",this).attr("checked","true");
		$("#quiz form").submit();
	});
	$("#quiz p label em").each(function() {
		var text 	= $(this).text();
		$(this).hide();
		var target  = $("#" + $(this).parent().attr("for").toString()).parent();
		target.append(text);
	});
}

/**
 * Intercept links with rel="pop" and open them in new window
 */
function newWindowLinks() {
	$("a[rel='pop']").click(function() { window.open($(this).attr("href")); return false;});	
}

/**
 */
function tabbedContent() {
	if($('.tabContent div.edit a').length == 0){
		$(".tabContent:gt(0)").hide();
		$("#tabbedContent").before("<div id=\"tabs\" class=\"cfx\"></div>");
		$(".tabContent h2").each(function(i) {
			var sel = i==0 ? ' class="selected"' : '';
			$("#tabs").append("<a href=\"#\" onclick=\"showTab(" + i + ");return false\""+sel+">" + $(this).text() + "</a>");
			$(this).remove();
		});	
	}
}
function showTab(i) {
	$(".tabContent").each(function(j) {
		if(j==i) {
			$(this).show();
		} else {
			$(this).hide();
		}
	});
	$("#tabs a").each(function(j) {
		if(j==i) {
			$(this).addClass("selected");
		} else {
			$(this).removeClass("selected");
		}
	});
}