/*
	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();
		InitRolloverInputs();
		
		// 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"); 
	});
}

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 InitRolloverInputs()
{
	if (_jQueryLoaded)
	{
		$(".rollover-input").each(function()
		{
			var imageSrc = $(this).attr("src");
			var imageName = imageSrc.substring(imageSrc.lastIndexOf("swap_") + 5, imageSrc.lastIndexOf("_"));
			
			for (var preloadLoop=0; preloadLoop < 3; preloadLoop++)
			{
				if (eval("typeof(b" + imageName + preloadLoop + ")") != "object")
				{
					eval("b" + imageName + preloadLoop + " = new Image()");
					eval("b" + imageName + preloadLoop + ".src = 'assets/swap_" + imageName + "_" + preloadLoop + ".gif'");
				}
			}
			
			$(this).mouseover(function()
			{
				$(this).attr("src", eval("b" + imageName + "1.src"));
			});
			
			$(this).mouseout(function()
			{
				$(this).attr("src", eval("b" + imageName + "0.src"));
			});

			$(this).mousedown(function() {
				$(this).attr("src", eval("b" + imageName + "2.src"));
			});

		});
	}
}

