/*
	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();
		InitInputInnerLabels();
		InitWasUseful();
		
		// 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");
		
		// IE 6 PNG fix for elements:
		// Elements to "fix" are stored in array for readability, converted back to string to feed into fix.
		var DD_fix =
			[
				".homeHero",
				".internalTabsContent .tabsMainContent",
				".playicon"
				
			].toString();

		(typeof DD_belatedPNG == "object") ? DD_belatedPNG.fix(DD_fix) : "";
		
		// Text sizing:
		$('.headerControls #textSizeUp').click(function(){
				TextResize('#content',1);
			});
		$('.headerControls #textSizeDown').click(function(){
				TextResize('#content',-1);
			});
		
		$(".printpage1").css("display","inline");
		
		// Equalise height on home tab menu:	
		InitEqualHeight($(".homeTabMenu li"));
		InitEqualHeight($(".contentTiles li"));

		// Tabs on home page functionality
		$('ul.homeTabMenu li').geeTabs();
		$('ol.internalTabs li').geeTabs({tabbedContentSelector: '.internalTabsContent li'});
		
		// Accordion functioninalty on faq pages
		$('ul.accordionList').geeAccordion({ contentSelector: 'div.accordionContent',
                                             closeOtherItems: true,
                                             speed: 450  });
	        $('ul.accordionInternal').geeAccordion({expandClass: 'expandedInternal', 
	                                                actionSelector: 'h3', 
	                                                contentSelector: 'div.accordionInternalContent',
	                                                closeOtherItems: false,
	                                                speed: 450 });
		
		// Accordion functioninalty on why join - the benefits pages
		$('ul.thumbList').geeAccordion({removeNonJsClass: 'nonJS',
										expandClass: 'expanded',
										itemSelector: 'li',
										actionSelector: 'a.readMoreLink', 
										contentSelector: 'div.readMoreContent',
										closeOtherItems: true,
										speed: 700 });
		
		// Safari fix
		if ($.browser.safari) {
			$('#navigation').addClass('safariFix');
		}
		
		$(".homeTabContent").addClass("json-01");
		$(".homeTabMenu").addClass("json-02");
		$("#flashcontent03").parent().addClass("json-03");
		
	});
}

//------------------------------------------
// JS for making labels within input boxes
// disapear when clicked
//------------------------------------------
function InitInputInnerLabels() 
{    
    if (_jQueryLoaded) 
    {
	    $('.compact input, form.compact select, form.compact textarea').focus(function(){
			    $('label[for=' + $(this).attr('id') + ']').hide();
		    });
	    $('.compact input, form.compact select, form.compact textarea').each(function(ele){
			    if($(this).val().length > 0)
				    $('label[for=' + $(this).attr('id') + ']').css({ display: "none" });
		    });
	    $('.compact input, form.compact select, form.compact textarea').blur(function(){
			    if($(this).val().length == 0)
				    $('label[for=' + $(this).attr('id') + ']').show();
		    });
	    $('.compact').removeClass('compact');
    }
}

function InitEqualHeight(group) {
	tallest = 0;
	group = group.not(".ignore_equalheight");
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
		    tallest = thisHeight;
		}
	});
	if ($.browser.msie && $.browser.version.substring(0,1) === '6'){
		group.css('height',tallest);
	}
	else {
		group.css('min-height',tallest);
	}
}

//------------------------------------------
// Text resizing
//------------------------------------------
var szs = new Array( '.6875em','.75em','.875em','1em','1.125em','1.25em','1.375em' );
var startSz = 3;
function TextResize( trgt,inc ) {
	if (!$) return;
	var sz = startSz;
	
	sz += inc;
	if ( sz < 0 ) sz = 0;
	if ( sz > 6 ) sz = 6;
	startSz = sz;

	$(trgt).css("font-size", szs[sz]);
}


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 InitWasUseful()
{
	$(".was_useful").show();
	function ShowWasUsefulHow()
	{
		$(".was_useful_form, .was_useful_thank_you").hide();
		$(".was_useful_how").show();
	}
	function ShowWasUsefulThankYou()
	{
		$(".was_useful_form, .was_useful_how").hide();
		$(".was_useful_thank_you").show();
	}
	$(".was_useful ul .was_useful_answer_yes a").click(function(){
		pageTracker._trackEvent('Was this information useful? >> Yes / No / I Don\'t Know', 'Yes', document.location.pathname + document.location.search);
		ShowWasUsefulThankYou();
		return false;
	});
	$(".was_useful ul .was_useful_answer_no a").click(function(){
		pageTracker._trackEvent('Was this information useful? >> Yes / No / I Don\'t Know', 'No', document.location.pathname + document.location.search);
		ShowWasUsefulHow();
		return false;
	});
	$(".was_useful ul .was_useful_answer_idk a").click(function(){
		pageTracker._trackEvent('Was this information useful? >> Yes / No / I Don\'t Know', 'I Don\'t Know', document.location.pathname + document.location.search);
		ShowWasUsefulHow();
		return false;
	});
	$(".was_useful_how .input_btn").click(function(){
		var HowUsefulResponse = $(".was_useful_how .input_txt").val();
		console.log(HowUsefulResponse);
		pageTracker._trackEvent('Please summarise how we could make this information more useful: >> Open Response', HowUsefulResponse, document.location.pathname + document.location.search);
		ShowWasUsefulThankYou();
		return false;
	});
}

//------------------------------------------
// Tab Plugin
//------------------------------------------
if (_jQueryLoaded)
{
    (function($) {
	    $.fn.geeTabs = function(options) {
		    var settings = $.extend({}, $.fn.geeTabs.defaults, options);
    		
		    this.each(function(index) {
			    $this = $(this);
    			
			    var o = $.meta ? $.extend({}, settings, $this.data()) : settings;

			    $this.click(function() {
				    $(this).siblings('li.selected').removeClass('selected');
				    $(this).addClass('selected');
				    $(o.tabbedContentSelector + '.current').removeClass('current');
					$(o.tabbedContentSelector + ':eq(' + index + ')').addClass('current');
			    });
		    });
	    }

	    $.fn.geeTabs.defaults = {
		    tabbedContentSelector: '.homeTabContent li'
	    };

    })(jQuery);
}

//------------------------------------------
// Accordion Plugin
//------------------------------------------
if (_jQueryLoaded)
{
    (function($) {
	    $.fn.geeAccordion = function(options) {

		    var settings = $.extend({}, $.fn.geeAccordion.defaults, options);
    		
		    return this.each(function(index) {
			    $this = $(this);
			    var o = settings;
    			
			    $this.removeClass(o.removeNonJsClass);
    			
                var items = $(o.itemSelector, $this);
                                
			    $(o.actionSelector, items).click(function() {
    				
				    if (!$(this).parent().hasClass('.' + o.expandClass)) 
				    {
    				    if (o.closeOtherItems) {
    				        items.siblings('.' + o.expandClass).removeClass(o.expandClass);
				            $(o.contentSelector, items).slideUp(o.speed);
    				    }
				        $(this).parent(o.itemSelector).addClass(o.expandClass);
				        $(this).siblings(o.contentSelector).slideDown(o.speed);
						
				    } else if ( !o.closeOtherItems ) {
				        $(this).parent().removeClass(o.expandClass);
				        $(this).siblings(o.contentSelector).slideUp(o.speed);
				    }
					
					return false;
			    });
		    });
	    }

	    $.fn.geeAccordion.defaults = {
	        removeNonJsClass: 'nonJS',
		    expandClass: 'expanded',
		    itemSelector: 'li',
		    actionSelector: 'h2',
		    contentSelector: 'div.content',
		    closeOtherItems: true,
		    speed: 1000
	    };
    })(jQuery);
}