﻿// Adelaide Bank JS (DT)

if (jQuery) {  
    $(document).ready(function()
	{
		if ($('div').is('#locatorContainer')) { 
			storeLocator();
		};
		
		if ($('table').is('.productComparison')) { 
			tableHighlights();	
		};
		
		if (($('div.ZoneControls').length > 0 ) && ($('table').is('.productComparison')))  { 
			stopPropagation();
		}	
		else {
			productTable();
		};
		
		if ($('div').is('.rotatingBanner')) { 
			slider();
		};
		
		if ($('div').is('#content')) { 
			collapsePanel();
		};	
		
		if ($('div').is('#header')) {
			searchreplace();
			cookieset();
		};
		
		if ($('div').is('#utilities')) {
			textresizer();
		};
		
		if (document.getElementById("tabsContainer")) {
			tabcool();
		};
		
		if ($('div').is('.Rating')) {
			fixrating();
		};
		
		if ($('div').is('.GMapEZ')) {
			googlemapsy();
		};
											
	});
} 

function googlemapsy()
{
  $('.GMapEZ div div div a').live('hover', function () {
	  var addressone = $('.clsPUBAddress1').text();
	  var addresstwo = $('.clsPUBAddress3').text();
	  var fulladdress = 'http://maps.google.com.au/maps?q=' + addressone + ' ' + addresstwo;
	  $('.GMapEZ div div div a').attr('href', fulladdress);
  });
}

function slider()
{
	// reformat widgets
	$('div.rotatingBanner div.allsubItems > div').appendTo($('div.rotatingBanner'));
    $('div.rotatingBanner > div').addClass('mainItem');
	$('div.rotatingBanner div.allsubItems').remove();
	$('div.rotatingBanner h2').remove();
	
	// cycle config
    $('.rotatingBanner')
	.after('<div id="nav"><div class="end">')
    .cycle({
		fx: 'fade',
                timeout: 4000,
                pager:  '#nav'
	});
	$('#nav .end').appendTo('#nav');
	$('#nav a').appendTo('#nav .end');
}

function tableHighlights()
{
	$('.tableHoverRows td').live('mouseover', function(){
        var i = $(this).index();
		$(this).parents('table').find('tr').children('td:nth-child(' + (i + 1) + ')').addClass('hover');
    
    }).live('mouseout', function(){
        $('.tableHoverRows td').removeClass('hover');
    })
    
    $('table').mouseleave(function(){
        $('.tableHoverRows td').removeClass('hover');
    })
}

function storeLocator()
{
	// assign classes for icons
	$(".clsgridHeader th:contains('Type')").replaceWith('<th scope="th">Bank</th>');
	$("th.clsHeaderView:contains('View')").replaceWith('<th scope="th">Map</th>');
	$("span.ZOOM:contains('Suncorp ATM')").addClass("suncorpIcon");
	$("span.ZOOM:contains('Bendigo ATM')").addClass("bendigoIcon");
	$('.FieldSearch label').replaceWith('<label>Enter your postcode/suburb and state</label>');
	$('#locatorContainer').prepend('<div class="message"></div>');
	$('#locatorContainer .message').load('/view.aspx?ArticleID=1221 .blurb');
	$('#breadcrumbs').append('<span>ATM Locator</span>');
}

var howMany = 0;

function hideCol(whichOne) {
    if (howMany < 4) {
        $('.productComparison th:nth-child('+whichOne+')').hide();
        $('.productComparison td:nth-child('+whichOne+')').hide();
        howMany++;
    }
    else {
		// alert('you cannot hide anymore');
	}
}

function showCol() {
    $('.productComparison th').show();
    $('.productComparison td').show();
    howMany = 0;
}

function collapsePanel() {
	$(".msg_body").hide();
    //toggle the componenet with class msg_body
    $(".msg_head").click(function(){
        $(this).next(".msg_body").slideToggle(200);
		$(this).toggleClass("highlight");
    });
}

function productTable () {
	$('.applyrow tr').appendTo('.tableHoverRows > tbody:last');
	$('.applyrow').remove();
}

function searchreplace() {
	$('#ctl00_SearchPlaceHolder_ctl01_strSearchKeyword').attr('value', 'Search');
	$('#ctl00_SearchPlaceHolder_ctl01_strSearchKeyword').focus(function() { if (this.value == 'Search') {this.value = '';} });
	$('#ctl00_SearchPlaceHolder_ctl01_strSearchKeyword').blur(function() { if (this.value == '') {this.value = 'Search';} });
}

function tabcool() {
		$("#tabsContainer .tabContent").hide(); //Hide all content
		$("#tabbedContentContainer ul.tabbedContentTabs li:first").addClass("active").show(); //Activate first tab
		$("#tabsContainer .tabContent:first").css("display","block"); //Show first tab content
		if ($('div').is('.ZoneControls')) {
			$("#tabsContainer .tabContent").css("display","block");
		};	
		// Hover Intent

function selectTabContent() {

	$("#tabbedContentContainer ul.tabbedContentTabs li").removeClass("active"); //Remove any "active" class
	$(this).addClass("active"); //Add "active" class to selected tab
	
	$("#tabsContainer .tabContent").hide(); //Hide all tab content
	var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
	$(activeTab).fadeIn(); //Fade in the active ID content

	$("#tabsContainer .tabContentz").css("visibility","hidden"); //Hide all content product zoom
	var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
	$(activeTab).css("visibility","visible"); //Fade in the active ID content
}

function doNothing() {
	// No need to do anything on roll out
}

var config = {    
	interval: 200,  // number = milliseconds for onMouseOver polling interval    
	over: selectTabContent,   // function = onMouseOver callback (REQUIRED)    
	out: doNothing    // function = onMouseOut callback (REQUIRED)    
};

$("#tabbedContentContainer ul.tabbedContentTabs li").hoverIntent( config );

// Disable Click Event
$("#tabbedContentContainer ul.tabbedContentTabs li").click(function() {

	return false;
});
}

function textresizer() {
	// font resizer
    $('a.fontresizer').click(function(){
	var ourText = $('#ContentLeft');
	var currFontSize = ourText.css('fontSize');
	var finalNum = parseFloat(currFontSize, 10);
	var stringEnding = currFontSize.slice(-2);
	if(this.id == 'fontlarge') {
            finalNum *= 1.2;
	}
	else if (this.id == 'fontsmall'){
            finalNum /=1.2;
	}
	ourText.css('fontSize', finalNum + stringEnding);
    });
}



function cookieset()
{
	$('#TopMenu li.first > a').live('click', function() {
		$(this).addClass('clearcookie');
	});
}

function Get_Cookie(check_name) {
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split(';');
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f
    var i = '';

    for (i = 0; i < a_all_cookies.length; i++) {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split('=');


        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed check_name
        if (cookie_name == check_name) {
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if (a_temp_cookie.length > 1) {
                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
            }
            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if (!b_cookie_found) {
        return null;
    }
}

function Set_Cookie(name, value, expires, path, domain, secure) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());
    // if the expires variable is set, make the correct expires time, the
    // current script below will set it for x number of days, to make it
    // for hours, delete * 24, for minutes, delete * 60 * 24
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    //alert( 'today ' + today.toGMTString() );// this is for testing purpose only
    var expires_date = new Date(today.getTime() + (expires));
    //alert('expires ' + expires_date.toGMTString());// this is for testing purposes only
    document.cookie = name + "=" + escape(value) + ((expires) ? ";expires=" + expires_date.toGMTString() : "") + //expires.toGMTString()
    ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ((secure) ? ";secure" : "");
}

// this deletes the cookie when called
function Delete_Cookie(name, path, domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

// take that radmenu
$('.clearcookie, #ctl00_TopMenuForSite_MN_m0').live('click', function() {
		Delete_Cookie('userLanding', '/', '');
		document.location = '/';
});
