// jQuery functions that run on "dom ready"

var _jQueryLoaded = (typeof(jQuery) == "function");
var minCols;
var url = window.location.pathname;
if (_jQueryLoaded)
{
	$(document).ready(function()
	{
		
		InitRolloverImages();
		
		ButtonPress();
		
		ClearInput();
		
		SearchBoxIframeInit();

	/*from page-load.js*/

if(document.getElementById('location.typeId') && (url.search(/personal/i)) != -1){
			document.getElementById('location.typeId').selectedIndex = 2;
	} else if(document.getElementById('location.typeId') && (url.toLowerCase().indexOf("/wps/wcm/connect/nab/nab/home/business_solutions/11")) != -1){
			document.getElementById('location.typeId').selectedIndex = 7;			
	}else if(document.getElementById('location.typeId') && (url.search(/business/i)) != -1){
			document.getElementById('location.typeId').selectedIndex = 3;			
	} else if(document.getElementById('location.typeId')){
			document.getElementById('location.typeId').selectedIndex = 2;			
	}	

	// If the root homepage (only), set the tab highlight and telephone number
	if (url == "/wps/wcm/connect/nab/nab/home" || url =="/wps/wcm/connect/nab/nab/home/" || url =="/" || url =="/index.html"){
			$("#header p strong").html("13 22 65");
			$("#navigation li:first").addClass("active");
	}	

	// If a help page, set the telephone number
	if (url.indexOf("/wps/wcm/connect/nab/help/home") != -1 || url.indexOf("/wps/wcm/connect/nab/Help/home") != -1){
			$("#header p strong").html("13 22 65");
	}

	/*end page-load.js*/
		
						
	});
}


var _RolloverImagesLoaded = false;
function InitRolloverImages()
{
	if (_jQueryLoaded && !_RolloverImagesLoaded)
	{
		$(".list-logo a").each(function()
		{
			$(this).find("img.img_prejs").each(function()
			{
				$(this).attr("class", "img_off");
			
				var newImage = $(this).clone();
		
				var newImageSrc = newImage.attr("src").replace("_0.gif", "_1.gif");
				newImage.attr("src", newImageSrc);
		
				newImage.attr("class", "img_hover");
		
				newImage.insertAfter(this);
			});
			
			$(this).focus(
				function()
				{
					$(this).toggleClass("hover");
				}
			).blur(
				function()
				{
					$(this).toggleClass("hover");
				}
			);
		});
		
		_RolloverImagesLoaded = true;
	}
}


	

function CountColums()
{
return $(".ico-close").size();
}
	

function ButtonPress(){
	
 	$("input[type=button]").mousedown(function(){
      $(this).addClass("btn-press");
    }).mouseup(function(){
      $(this).removeClass("btn-press");
    }).mouseover(function(){
      $(this).addClass("btn-hover");
    }).mouseleave(function(){
		$(this).removeClass("btn-press btn-hover");
	});
	
	$("a.link-btn").mousedown(function(){
      $(this).addClass("btn-press");
    }).mouseup(function(){
      $(this).removeClass("btn-press");
    }).mouseleave(function(){
		$(this).removeClass("btn-press");
	});
	
	$("ul.list-4 li a").mousedown(function(){
      $(this).addClass("link-press");
    }).mouseup(function(){
      $(this).removeClass("link-press");
    }).mouseleave(function(){
		$(this).removeClass("link-press");
	});
		
}

function ClearInput() {
	
	var clearInputPrevious = '';

	// clear input on focus
	$('input:text').focus(function()
	{
		if($(this).val()==$(this).attr('title'))
		{
			clearInputPrevious = $(this).val();
			$(this).val('');
		}				
	});
	
	// if field is empty afterward, add text again
	$('input:text').blur(function()
	{
		if($(this).val()=='')
		{
		$(this).val(clearInputPrevious);
		}
	});
	
	
}

/* Insert Iframe for ie6 to display suggestion on top of selectboxes in ie6 */
function SearchBoxIframeInit() {
	
	sb_e = $(".nab-search-inside");
	
	isie6 = $.browser.msie && $.browser.version<7;
	
	if (isie6) {
		sb_iframe = $("<iframe src='' height='1' width='1'></iframe>").insertAfter(sb_e);
		sb_iframe.css({
				width: (sb_e.width() + 2) + "px",
				height: (sb_e.height() + 2) + "px",
				zIndex: 9000,
				visibility: 'visible' // brings the popup back in to view,
		});
	}
	
}

// The below is for the generic Hoax Alert message		
now = new Date(); mo = now.getMonth(); da = now.getDate(); da = (da <10) ? ("0" + da) : da; we = now.getDay(); ye = now.getFullYear(); Mon = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var artifactSecUpdate = '<a class="labelBold" href="/wps/wcm/connect/nab/nab/home/personal_finance/12/13/9/1" title="Security alerts">Security alerts - '+da+' '+Mon[mo]+' '+ye+'</a>';

