/*
	Copyright DTDigital         :: www.dtdigital.com.au ::
	Unauthorised modification / use is a criminal offence, and
	will be prosecuted to the fullest extent permitted by law.
	All Rights Reserved
*/

// jQuery functions that run on "dom ready"

var _jQueryLoaded = (typeof(jQuery) == "function");

if (_jQueryLoaded)
{
	$(document).ready(function() {
		InitRolloverNavigation();
		InitHoverSwaps();

		// Makes links open in new window when they have rel=external
		$("a[rel=external]").attr("target", "_blank");
		// Use below method if using thickbox, matches class rather than rel
		$("a.external-link").attr("target", "_blank");

		// Clear field default value on focus if nothing entered put default value back on blur
		ToggleDefaultValue();

		// Custom font replacements
		cufonReplacements();
	
	});
}

var _RolloverNavigationLoaded = false;
function InitRolloverNavigation()
{
	if (_jQueryLoaded && !_RolloverNavigationLoaded)
	{
		$(".rollover-navigation a").each(function()
		{
			$(this).find("img.navitem_prejs").each(function(){
				$(this).attr("class", "navitem_off");
			
				var newImage = $(this).clone();
		
				var newImageSrc = newImage.attr("src").replace("_0.gif", "_1.gif");
				newImage.attr("src", newImageSrc);
		
				newImage.attr("class", "navitem_hover");
		
				newImage.insertAfter(this);
			});
			
			$(this).focus(function(){
				$(this).toggleClass("hover");
			}).blur(function(){
				$(this).toggleClass("hover");
			});
		});

		_RolloverNavigationLoaded = true;
	}
}

function InitHoverSwaps() {
	$(".hoverswap").each(function() {
		var imageSrc = $(this).attr("src");
		var imageName = imageSrc.split("_")[1];

		for (var preloadLoop = 0; preloadLoop < 3; preloadLoop++) {
			if (eval("typeof(b" + imageName + preloadLoop + ")") != "object") {
				eval("b" + imageName + preloadLoop + " = new Image()");
				if (imageSrc.indexOf(".gif") > -1) {
					eval("b" + imageName + preloadLoop + ".src = 'Assets/swap_" + imageName + "_" + preloadLoop + ".gif'");
				} else if (imageSrc.indexOf(".jpg") > -1) {
					eval("b" + imageName + preloadLoop + ".src = 'Assets/swap_" + imageName + "_" + preloadLoop + ".jpg'");
				} else if (imageSrc.indexOf(".png") > -1) {
					eval("b" + imageName + preloadLoop + ".src = 'Assets/swap_" + imageName + "_" + preloadLoop + ".png'");
				}
			}
		}
		$(this).hover(function() {
			$(this).attr("src", eval("b" + imageName + "1.src"));
		}, function() {
			$(this).attr("src", eval("b" + imageName + "0.src"));
		});

	});
}

function ToggleDefaultValue() {
	// For forms to clear values on focus and add values on blur
	$("input.input01[type=text]").focus(function() {
		currentVal = $(this).attr("title");
		($(this).val() == currentVal) ? $(this).val("") : "";
	}).blur(function() {
		($(this).val() == "") ? $(this).val(currentVal) : "";
	});
}

function cufonReplacements() {
	Cufon.replace('h1.subtitle03, div.subtitle03, h1.subtitle04, h2.subtitle01, h2.subtitle01a, h2.subtitle03, h2.subtitle05, h2.subtitle06, h3.subtitle01, h3.subtitle02, h3.subtitle03, .intro01, #content .search label, .label03, .redbox_intro, .redbox_help, h2.subtitle07', { fontFamily: "Kievit-Medium" });
	Cufon.replace(' .redbox_intro, .bold_text', { fontFamily: "Kievit-Bold" });
	
	Cufon.replace('h1.subtitle02, h1.subtitle02a, h1.subtitle02b, h2.subtitle02, .reg_text', { fontFamily: "Kievit-Regular" });

	/* Needs to be declared seperatly to only apply text-shadow to title needed */
	Cufon.replace('h1.subtitle01, div.subtitle01', { textShadow: '#512b08 0 1px', fontFamily: "Kievit-Medium" });
}

function PrintPage() {
	window.TB_iframeContent.print();
}