/*
	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
*/



NAVarr = new Array("home", "mysuper", "lifechanges", "whyjoin", "investments", "financialadvice", "toolsforms", "newseducation", "employers", "aboutus");

// jQuery functions that run on "dom ready"

var _jQueryLoaded = (typeof(jQuery) == "function");

if (_jQueryLoaded)
{
	$(document).ready(function()
	{
		InitRolloverNavigation();
		InitRolloverInputs();
		
		InitFilter1();
		
		// 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"); 
		
		//Stop IE6 bg flicker
		try {
		 document.execCommand('BackgroundImageCache', false, true);
		} catch(e) {}
	});
}

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 < 2; 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"));
			});

		});
	}
}

function InitFilter1()
{
	if (_jQueryLoaded)
	{
		
		var contractedNumber = 3;
		
		function MLFSectionContractAll()
		{
			$(".ml_section").each(function(){
				if ($(this).children(".ml_item").length > contractedNumber)
				{
					expandButton = $(this).find(".ml_viewtoggle a");
					textViewing = $(this).find(".ml_viewing");
					$(this).children(".ml_item:gt("+(contractedNumber-1)+")").hide();
					expandButton.addClass("ml_viewtoggle_more");
					expandButton.text("View more");
					textViewing.text("Viewing "+contractedNumber+" of "+$(this).children(".ml_item").length);
				}
			});
		}
		
		function MLFSectionToggle(section,animate)
		{
			$(section).each(function(){
				if ($(this).children(".ml_item").length > contractedNumber)
				{
					toggleButton = $(this).find(".ml_viewtoggle a");
					textViewing = $(this).find(".ml_viewing");
					toggleButton.toggleClass("ml_viewtoggle_more");
					if (toggleButton.text() == "View less") {
						toggleButton.text("View more")
					} else {
						toggleButton.text("View less")
					}
					if (textViewing.text() == "Viewing "+$(this).children(".ml_item").length+" of "+$(this).children(".ml_item").length) {
						textViewing.text("Viewing "+contractedNumber+" of "+$(this).children(".ml_item").length);
					} else {
						textViewing.text("Viewing "+$(this).children(".ml_item").length+" of "+$(this).children(".ml_item").length);
					}
					if (animate) {
						$(this).children(".ml_item:gt("+(contractedNumber-1)+")").slideToggle();
					} else {
						$(this).children(".ml_item:gt("+(contractedNumber-1)+")").toggle();
					}
				}
			});
		}
		
		MLFSectionContractAll();
		$(".ml_section").each(function(){
			if ($(this).children(".ml_item").length > contractedNumber)
			{
				$(this).find(".ml_view").html('<span class="ml_viewing">Viewing '+contractedNumber+' of '+$(this).children(".ml_item").length+'</span><span class="ml_viewtoggle"><a href="#" class="ml_viewtoggle_more">View more</a></span>');
			}
			else
			{
				$(this).find(".ml_view").html('<span class="ml_viewing">Viewing '+$(this).children(".ml_item").length+' of '+$(this).children(".ml_item").length+'</span>');
			}
		});
		$(".ml_view").show();
		
		$(".ml_viewtoggle a")
			.click(function(){
				jumpto = $(this).parents(".ml_section").attr("id");
				MLFSectionToggle("#"+jumpto,true);
				this.blur();
				return false;
			});
		
	}
}