/* ########################################################################### *
/* ***** DOCUMENT INFO  ****************************************************** *
/* ########################################################################### *
/* ##### NAME:  HomePage.1.2.js
/* ########################################################################### */
/* ##### INIT
/* ##### DROP DOWN MENUS
/* ##### IE
/* ##### UTILS
/* ##### FORMS
/* ########################################################################### */

/**********************/
/* INIT */
/**********************/

$(document).ready(custom_init);

/* Initialisation functions */
function custom_init()
{    
    // JS enabled

    // Custom scroll bars
   init_scrollPane();
   init_utils();
   init_dropDowns();

    // Important notice

   init_importantNotice();
    // IE hacks
   if ($.browser.msie) { init_ie(); }
}


/**********************/
/* DROP DOWN MENUS */
/**********************/


function init_dropDowns()
{
    // Mega dropdown / hoverIntent configuration
    // - sensitivity: mouse movement sensitivity
    // - interval: delay before show    
    // - timeout: delay before hide
    // - over: show function callback
    // - out: hide function callback
    // Mega drop downs configuration
    var config_megaDropDowns = 
    {
         sensitivity: 4,
         interval: 300,
         timeout: 100,
         over: addHover,
         out: removeHover
    };
    
    var config_otherDropDowns = 
    {
         sensitivity: 1,
         interval: 0,
         timeout: 100,
         over: function (){ },
         out: removeHover
    };

    /** Primary navigation (show with hover intent config) **/
    $("#nav_primary .hasSubNav").hoverIntent(config_megaDropDowns);
    $("#nav_primary .hasSubNav a.btn").keydown(function(event)
    {
        // Handle enter key
        if (event.keyCode == '13') 
        {
            event.preventDefault();
            $(event.target).each(toggleHover);
        }
    });

    // Handle click to close on primary nav main buttons (and prevent anchor click)
    $("#nav_primary a.btn").click(toggleHover);

    /*
    $("#nav_primary a.btn").click(function()
    {
        $(this).parent('.hasSubNav').removeClass('hovering');
        $(this).parent('.hasSubNav').find('.subNav').addClass('offscreen');
        return false;    
    });
    */
    
/*Fix : Using keyboard navigation, after expanding a fly-out or dropdown menu and then 
navigating outside of the fly-out, the menu remains open and is not collapsed*/
if($.browser.msie)
{

$(".item_accounts a").blur(function(event)
{
		if($(document.activeElement).parents(".subNav_links").length == 0 && !($(document.activeElement).hasClass("promo_content"))){
			$(this).parents(".subNav").prevAll("a.btn").each(toggleHover);
		}
});

$("a.promo_content").blur(function(event)
{
			$(this).parents(".subNav").prevAll("a.btn").each(toggleHover);
});
}
/*---------------------------------------------------*/


/*------Laos Defect fix---------------------------------------------*/
if($.browser.msie && $.browser.version=="6.0")
{
 $("#nav_primary.laos a.btn").mouseover(function(event)
    {
             $("#nav_primary.laos .subNav_links li.item_landing").css("margin-bottom", -6 + "px");
               });
            
            $("#nav_primary.laos .subNav_links li.item_landing a").mouseover(function(event)
    {
       $("#nav_primary.laos .subNav_links li.item_landing").css("margin-bottom", -7 + "px");
     
            });

$("#nav_primary.laos a.btn").focusin(function(event)
    {
             $("#nav_primary.laos .subNav_links li.item_landing").css("margin-bottom", -6 + "px");
               });
            
            $("#nav_primary.laos .subNav_links li.item_landing a").mouseover(function(event)
    {
       $("#nav_primary.laos .subNav_links li.item_landing").css("margin-bottom", -7 + "px");
     
            });


}

if($.browser.msie && $.browser.version > "6.0")
{
 $("#nav_primary.laos a.btn").mouseover(function(event)
    {
             $("#nav_primary.laos .subNav_links li.item_landing").css("margin-bottom", -7 + "px");
               });
            
            $("#nav_primary.laos .subNav_links li.item_landing a").mouseover(function(event)
    {
       $("#nav_primary.laos .subNav_links li.item_landing").css("margin-bottom", -8 + "px");
     
            });

$("#nav_primary.laos a.btn").focusin(function(event)
    {
             $("#nav_primary.laos .subNav_links li.item_landing").css("margin-bottom", -7 + "px");
               });
            
            $("#nav_primary.laos .subNav_links li.item_landing a").mouseover(function(event)
    {
       $("#nav_primary.laos .subNav_links li.item_landing").css("margin-bottom", -8 + "px");
     
            });


}


/*--------------------------------------------------------*/


//Drop down Collapse on focus out
/*
$(".subNav a").focusout(function(event){
		if($(document.activeElement).parents(".subNav").length == 0){
			$(this).parents(".subNav").prevAll("a.btn").each(toggleHover);
		}	
	});

*/
    // Get and set the height of the right border to match the content area (slight delay to calculate render heights accurately).
    setTimeout(function() 
    { 
        $("#nav_primary .subNav").each(function()
        {
            var contentHeight = $(this).outerHeight() - 11;
        });
    }, 500);

    /** Top nav country selection **/
    // Handle hover exit
    // Nb: Config different as doesn't show on hover
    $("#nav_top .hasSubNav").hoverIntent(config_otherDropDowns);

    // Handle on hover
    // Nb: Adding a.btn prevents the removeHover click event when the user clicks a html link
    $("#nav_top .hasSubNav a.btn").click(toggleHover);
    
    /** Quicklinks **/
    $(".nav_quicklinks .hasSubNav").hoverIntent(config_otherDropDowns);
    $(".nav_quicklinks .hasSubNav a.btn").click(toggleHover);

    /** Situationals */
    $(".moduleContent .hasSubNav").hoverIntent(config_otherDropDowns);
    $(".moduleContent .hasSubNav a.btn").click(toggleHover);
    
    /** Logon select **/
    $(".module_logon .hasSubNav").hoverIntent(config_otherDropDowns);
    $(".module_logon .hasSubNav a.btn").click(toggleHover);
   

    // Handle selection of items
     $(".module_logon label").click(function ()
    {
        // Trigger the radio button
       $(this).siblings('input:first').attr('checked', 'checked');
               // Set the text in the select box
        var selectedHtml = $('span a', this).html();
              $(this).parents('.menu_logon:first').find('.btn span').html(selectedHtml);
  
        showHideDemolink();
        // Close the drop down

        $(this).parents('.hasSubNav:first').removeClass('hovering');

        $(this).parents('.hasSubNav:first').find('.subNav').hide();   

    });


    // Handle keyboard nav
    $(".module_logon .subNav input[type='radio']").focus(function ()
    {
        $(this).siblings('label:first').addClass('hover');
    });

    $(".module_logon .subNav input[type='radio']").blur(function ()
    {
        $(this).siblings('label:first').removeClass('hover');
    });      
}

// Handles click of btn for standard drop downs (necessary as the hoverIntent may have already hidden the drop down)
function toggleHover()
{
    if ($(this).hasClass('btn'))
    {
        if ($(this).parents('.hasSubNav:first').hasClass('hovering'))
        {
            // Hide this menu
            $(this).parents('.hasSubNav:first').removeClass('hovering');
            $(this).parents('.hasSubNav:first').find('.subNav').hide();
        }
        else
        {
            // Hide ALL other menus
            $('.hasSubNav').removeClass('hovering');
            $('.hasSubNav .subNav').hide();
                
            // Show this menu
            $(this).parents('.hasSubNav:first').addClass('hovering')
            $(this).parents('.hasSubNav:first').find('.subNav').show();
        }
        return false;
    }
}
    
// On state
function addHover()
{
    // If this is a .btn or .hasSubNav object, else ignore
    if ($(this).hasClass('hasSubNav') || $(this).hasClass('btn'))
    {
        var target = this;
          
        // Handle the .btn type events used for click on click off
        if ($(this).hasClass('btn'))
        {
            target = $(this).parents('.hasSubNav:first');
        }
            
        // Hide ALL other menus
        $('.hasSubNav').removeClass('hovering');
        $('.hasSubNav .subNav').hide();
            
        // Add on state
        $(target).addClass("hovering");
        $(target).find('.subNav').show();
    }
}
    
// Off state
function removeHover()
{
    // If this is a .btn or .hasSubNav object, else ignore
    if ($(this).hasClass('hasSubNav') || $(this).hasClass('btn'))
    {
        var target = this;
          
        // Handle the .btn type events used for click on click off
        if ($(this).hasClass('btn'))
        {
            target = $(this).parents('.hasSubNav:first');
        }
            
        // Add on state
        $(target).removeClass("hovering");
        $(target).find('.subNav').hide();
    }
}

/**********************/
/* IE */
/**********************/

function init_ie()
{
    // Supersleight PNG fix for IE6 (path to transparent gif)
    var config_supersleightGifPath = "scripts/x.gif";

    // Get the version of IE
    var version = parseInt($.browser.version);

    // Handle .last-child
$('#navigation #leftnav .display_nav li:last-child, #navigation #leftnav .anznav_currentthirdlevel li:last-child, #anz-lotus #navigation li.anznav_expandable .hide_nav li:last-child').addClass('last-child');
      
      // Handle .first-child
      $('#navigation #leftnav .display_nav li:first-child, #navigation #leftnav .anznav_currentthirdlevel li:first-child, #anz-lotus #navigation li.anznav_expandable .hide_nav li:first-child').addClass('first-child');
        
    // Rounded corners - IE6, IE7, IE8 
    if (version < 9)
    { 
        $('.module, .jspTrack, .jspDrag').cornerz(
        {
            'radius': 5
        });

    }
    
    // IE6
    if (version < 7)
    {
             
    $('.btn_logon').hover(function() 
     { 
          $(this).addClass('btn_logon_hover'); 
     }, 
       function () 
       {
           $(this).removeClass('btn_logon_hover'); 
     });
        
 $('.module_logon .subNav li').hover(function() 
   { 
       $('label', this).addClass('hover'); 
    }, 
     function () 
   {
         $('label', this).removeClass('hover'); 
  });
        //Situationals - IE6 Fix - Li Hovering

$('.moduleContent ul li.hasSubNav .subNav ul li').hover(function() 
   { 
       $('a', this).addClass('hover'); 
       
    }, 
 function () 
   {
         $('a', this).removeClass('hover'); 
  });


        // Handle important notice fixed position

        if ($('.notice').length > 0)
        {

            // Set the initial position

      $('.notice').css('top', $(this).scrollTop() + $(window).height() - $('.notice').outerHeight() - 80 + "px");
   
            $(window).scroll(function() 
            {

                // Check it still exists (ie. hasn't been closed)
                if ($('.notice').length > 0)
                {

                    $('.notice').css('top', $(this).scrollTop() + $(window).height() - $('.notice').outerHeight() - 80 + "px");
                }
            });
        }
    }
}


/**********************/
/* IMPORTANT NOTICE */
/**********************/

// Handle important notices
// - If an ID is put on the div.notice, the script will store the ID as a cookie
//   and hide the notice on subsequent visits.
function init_importantNotice()
{
    $('.notice_important').each(function ()
    {

        // Check if this notice has already been closed

//path: '/', domain: 'jquery.com'
var domain = document.domain;

var resURL = '/'

        if ($.cookie($(this).attr('id')) == null)
        {
            // User has not closed this notice so show it
            $(this).parents('div.notice_container').show();
         
            // Append btn and wire events
            $(this).append('<a href="#"  class="btn">Close</a>');

            $('a.btn', this).click(function()
            {
                // Grab the notice element
                var notice = $(this).parents('div.notice_important');
                
                // Store the notice ID as a cookie
                var noticeId = $(notice).attr('id');
                $.cookie(noticeId, "true",  { path: resURL , domain: domain} );
                
                // Hide the notice
                $(notice).parents('div.notice_container').fadeOut();
                 return false;
            });

        }
    });
}


/**********************/
/* UTILS */
/**********************/

function init_utils()
{
    // Handle offscreen
$('.offscreen').hide().removeClass('offscreen');
//set up the class for current selected list item
$('#anz-lotus #navigation li.anznav_expandable a.currentPage').parent().addClass('CurrentLhnList');
}

// Customised scroll bar used for Country selector
function init_scrollPane()
{
    $('.scroll-pane').jScrollPane(
    {
    	showArrows: false,
    	horizontalGutter: 10
    });
}


/**********************/
/* FORMS */
/**********************/

function init_forms()
{
    // Select text on focus
    init_forms_selectOnClick();
    
    // Search
    init_search();
}

function init_search()
{   
    // Mock JavaScript, will need to be replaced with AJAX callbacks etc.
    setInterval(function()
    {
        if ($('#txt_search').val().length > 0 && $('#txt_search').val() != $('#txt_search').attr('title'))
        {
            $('.search_suggestions').fadeIn(function() 
            {
                // Fix IE fade in anti-alias bug.
                if ($.browser.msie)
                {
                    this.style.removeAttribute('filter');
                }
            });

        }
        else
        {
            $('.search_suggestions').fadeOut();
        }           
    }, 500);
    
    $('#txt_search').blur(function()
    {
        $('#txt_search').val($('#txt_search').attr("title"));
        $('.search_suggestions').fadeOut();
    });
}

// Select contents of input on click
function init_forms_selectOnClick()
{
	if ($(".js_forms_selectOnClick").length > 0)
	{
		// When the element has focus, set its value to the following
		var SEARCH_TEXT_ON = "";	
		
		// Setup the value of the element to it's title attribute
		$(".js_forms_selectOnClick").each(function() 
			{
				$(this).val($(this).attr("title"));
			});
		
		// Handle this element's focus event
		$(".js_forms_selectOnClick").focus(function()
		{
			// Get the value from the elements title
			var searchTextOff = $(this).attr("title");
			
			// If the current value of the element is the same as the title attribute then set it to the ON value.
			if ($(this).val() == searchTextOff)
			{
				$(this).val(SEARCH_TEXT_ON);
			}
		});
		
		// Handle this element's blur event
		$(".js_forms_selectOnClick").blur(function()
		{
			// Get the value from the elements title
			var searchTextOff = $(this).attr("title");
			
			// If the value of the element is empty set it to the default value (taken from the element title)
			if ($(this).val() == "")
			{
				$(this).val(searchTextOff); 
			}
		});	
	}
}




function initLoginBoxarea() {
	var loginOptions = document.getElementById('loginbuttons').getElementsByTagName('input');
                      var loginoptionlink = document.getElementById('login_form').getElementsByTagName('a');
	var oneIsChecked = false;
	var i = 0;
              for (i==0; i<loginoptionlink.length; i++) {
                  if(loginoptionlink[i].innerHTML!='Security' && loginoptionlink[i].parentNode.id!='SecurityLink' && loginoptionlink[i].className!='btn btn_noFollow' && loginoptionlink[i].className!='singlelink'){
                             loginoptionlink[i].href="javascript:void(0);";
                   }
                 else{
                   if(loginoptionlink[i].className=='btn btn_noFollow'){
                             loginoptionlink[i].href="Internet Banking";
                       }
                  }
             }
            i=0;
	for (i==0; i<loginOptions.length; i++) {
		if (loginOptions[i].checked) {			
			oneIsChecked = true;
		}
	}
	if (!oneIsChecked) {
		loginOptions[0].checked = 'checked';
	}
	if($("html").attr("lang")=='en'){
	                if($('body').hasClass('lowerlevel')){
	                 document.getElementById('button_logon').src='/base/Resources/resources/e/9/e9c13180464a90ad953795e7e8d2a6b3/logon_Eng_L2.gif';
	                }
	                else{
	                    document.getElementById('button_logon').src='/base/Resources/resources/5/2/52739080463a9094be0bbfe7e8d2a6b3/logon_Eng_L1.gif';
		    }
	}
	showHideDemolink();
}

function showHideDemolink() {
                    	if (document.getElementById('demoLink')){
		var demoLink = document.getElementById('demoLink');
                                           var secuLink = document.getElementById('Securitylink');

		demoLink.style.display="none";
		secuLink.style.display="none";
		var loginButtons = document.getElementById('loginbuttons');
		var options = loginButtons.getElementsByTagName('input');
		var loginOptions = document.getElementById('loginbuttons').getElementsByTagName('input');
		var j = 0;
		for (j==0; j<loginOptions.length; j++) {
			if (loginOptions[j].checked){
                                                                                                                                                          
			         if ((loginOptions[j].className).indexOf("showDemoLink")>=0 && (loginOptions[j].className).indexOf("Security")>=0)
                                                                                    {
				
                                                                                                 
					demoLink.style.display="block";
					secuLink.style.display="block";

                  				}
				if ((loginOptions[j].className).indexOf("showDemoLink")>=0) {
                                                                                                 
					demoLink.style.display="block";
     				}
				if ((loginOptions[j].className).indexOf("Security")>=0) {
                                                                                                 
					secuLink.style.display="block";

                  				}



                       //Reset the selected value when browser back button pressed
	 var selectedHtml = $('span a', $(document.login_form.selectlogin[j]).parents('li').find('label')).html();
			
                      $($(document.login_form.selectlogin[j]).parents('li').find('label')).parents('.menu_logon:first').find('.btn span').html(selectedHtml);
        // Close the drop down
                      $($(document.login_form.selectlogin[j]).parents('li').find('label')).parents('.hasSubNav:first').removeClass('hovering');
                      $($(document.login_form.selectlogin[j]).parents('li').find('label')).parents('.hasSubNav:first').find('.subNav').hide(); 

			}
		}
	}
}

function setLoginOnelink(s) {
if (document.login_form.selectlogin.checked) {
var str = document.login_form.selectlogin.value;
}
	var arrayOfURL = str.split("|");
	var URL1 = arrayOfURL[0];
	var URL2 = arrayOfURL[1];

	var URL3 = arrayOfURL[2];
	if (s == 1) {
		if (URL1 != "") {
			var myFucn = new Function(URL1);
			myFucn();
		}
	}
	else {
		if (s == 3) {
			if (URL3 != "") {
				var myFucn = new Function(URL3);
				myFucn();
			}
		}
		else {
			if (URL2 != "") {
				var myFucn = new Function(URL2);
				myFucn();
			}
		}
	}
	return false;
}

/**********************/

/***********************/
// omniture tracking 
/***********************/


function trackCountry(currentSel)
{
if(typeof s_gi == "function"){
	var s=s_gi(s_account);
	var curCountry = $("#nav_top .hasSubNav ul.list li a[selected='selected']").text();
	var selCountry = currentSel.innerHTML;
	s.linkTrackVars="prop24,eVar24,prop33,events";
	s.linkTrackEvents="event11";
	s.prop24=s.eVar24="country selector";
	s.events="event11";
	s.prop33= curCountry + ":" +  selCountry;
	s.tl(this,"o",s.prop24 + ":" + s.prop33);
	}
}

function trackFlyout(currentSel)
{
if(typeof s_gi == "function"){
	var parentName,currName;
	var s=s_gi(s_account);
	parentName = $(currentSel).parents("li").find("a.btn span").html();
	parentName = parentName.toLowerCase().replace(" ", "-");
	currName = $(currentSel).find("span.title").text();
	s.linkTrackVars="prop24,eVar24,events";
	s.linkTrackEvents="event11";
	s.prop24=s.eVar24=parentName + ":fly-out:" + currName ;
	s.events="event11";
	s.tl(this,"o",s.prop24);
	}
}

function trackFF(currentSel)
{
if(typeof s_gi == "function"){
	var tabName,ffName, linkName;
	var s=s_gi(s_account);
	tabName = $("li.currentfirstlevel").find("a.btn span").html();
	tabName = tabName.toLowerCase().replace(" ", "-");
	ffName = $(currentSel).attr('class');
	//alt tag only exists on truncated newws items
	if ($(currentSel).attr("alt")) {
		linkName = $(currentSel).attr("alt");
	}else{
		linkName = $(currentSel).html();
	}
	s.linkTrackVars="prop24,eVar24,events";
	s.linkTrackEvents="event11";
	s.prop24=s.eVar24=tabName + ":" + ffName + ":" + linkName;
	s.events="event11";
	s.tl(this,"o",s.prop24);
	}
}

function trackHB(strPID)
{
if(typeof s_gi == "function"){
	var s=s_gi(s_account);
	s.linkTrackVars="eVar15,events";
	s.linkTrackEvents="event23";
	s.eVar15=strPID;
	s.events="event23";
	s.tl(this,"o","Internal Campaign Impression");
	}
}

/* END OMNITURE */


/*Hero banner click*/
function setactive(sequence,banImg,banFlash){
var i=0;
var actdiv;
var intBanCnt1=5;
for(i=1; i<intBanCnt1+1; i++){

var actnum=i+1;
var activdiv='act'+i.toString();
actdiv=document.getElementById(activdiv);
actdiv.style.display="none";
if(banImg[i].length>0 || banFlash[i].length>0){
actdiv.style.display="block";

}

if(i==sequence){
 actdiv.className="act";
}else{
actdiv.className="inact";
}

}
}

function replaceimage(sequence,strBanImg,strBanFlash){
setactive(sequence,strBanImg,strBanFlash);


var requiredMajorVersion = 7;
		// Minor version of Flash required
var requiredMinorVersion = 0;
		// Revision of Flash required
var requiredRevision = 0;

		var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
                                          var xmlLocation = "/personal/herobanner.xml";
if(strBanFlash[sequence]&&hasRightVersion){

			var so = new SWFObject(strBanFlash[sequence], "heropanel_flash", "972", "290", requiredMajorVersion, "#FFFFFF");
so.addParam("wmode", "transparent");

var heroactadd = document.getElementById("heroact");
var heropanelID = document.getElementById("heropanel");
heropanelID.removeChild(document.getElementById("Heroreloadload"));
var heroreoadchk=document.createElement("div");
heroreoadchk.setAttribute("id","Heroreloadload");
heropanelID.appendChild(heroreoadchk);
			so.write("Heroreloadload");
heropanelID = document.getElementById("Heroreloadload")
heropanelID.appendChild(heroactadd);

}
else{

if (document.getElementById("herpanelrighttop")==null){
var heropanelID = document.getElementById("heropanel");
heropanelID.removeChild(document.getElementById("Heroreloadload"));
var heroreoadchk=document.createElement("div");
heroreoadchk.setAttribute("id","Heroreloadload");
heroreoadchk.innerHTML=strheroreloadload;
heropanelID.appendChild(heroreoadchk);

}
var imgval='url('+strBannerImg[sequence]+')';


var contentID1 = document.getElementById("herpanelrighttop");
contentID1.removeChild(document.getElementById("panelreload"));

var newTBDiv1 = document.createElement("div");
newTBDiv1.setAttribute("id","panelreload");
newTBDiv1.innerHTML='<h2>' + strBannerText[sequence] + '</h2>' + '<p>' + strBannerTextSec[sequence] + '</p>';
contentID1.appendChild(newTBDiv1);
var primary=document.getElementById("herpanelright").getElementsByTagName('h2');
var secondary=document.getElementById("herpanelright").getElementsByTagName('p');
primary[0].className="heroprimary " + strBannerTextColor[sequence];
secondary[0].className="herosecondary " + strBannerTextSecColor[sequence]
var contentID = document.getElementById("heropanelrightbuttom");
contentID.removeChild(document.getElementById("herobutton"));

var newTBDiv = document.createElement("div");
newTBDiv.setAttribute("id","herobutton");
newTBDiv.innerHTML=strBannerLink[sequence];
contentID.appendChild(newTBDiv);


document.getElementById("heropanel").style.background =imgval;
var parentTag=document.getElementById("herobutton").getElementsByTagName('a');
if(strBannerLink[sequence]!=''){

parentTag[0].onmouseover = function (){

				var alinkImgs, curImg;
	alinkImgs = this.getElementsByTagName("img");

		curImg = alinkImgs.item(0);
		curImg.style.top='-32px';

				return false;
			}

parentTag[0].onmouseout = function (){
				var alinkImgs, curImg;
	alinkImgs = this.getElementsByTagName("img");

		curImg = alinkImgs.item(0);
		curImg.style.top='0px';

				return false;
			}
}

}
}
/* End Hero banner code*/




