if (typeof(addCurves)=="undefined")
{
var addCurves = true;
}

$(document).ready(function(){

	function addProductNavTabGradients()
	{
	$("body#home li#nav-home, body#aboutNI li#nav-aboutUs, body#products li#nav-our-savings-products, body#FAQs-forms li#nav-FAQsForms, body#applyNow li#nav-applyNow, body#security li#nav-security, body#contactus li#nav-contactus, body#savingsIndex li#nav-savingsIndex").each(function(){
				$(this).addClass("currentActiveTab")
				$(this).prev().addClass("activeTabLeft")
				$(this).prev().find(">a").append("<div class=\"added\">")
				$(this).next().addClass("activeTabRight")
				$(this).next().find(">a").append("<div class=\"added\">")
		})
	}
	addProductNavTabGradients();
	
	function addTitlesToSavingsSubNav()
	{
		$("#navigation-primary ul li ul li a.abbreviated").each(function(){
			$(this).attr("title",$(this).text() + " Account");
		});
	}
	addTitlesToSavingsSubNav();

$("#navigation-primary ul li:not(li.currentActiveTab)").each(function(){
	
	$(this).find("a")
		.mouseover(function(e){  $(this).parent().addClass("navHoverState");})
		.focus(function(e){$(this).parent().addClass("navHoverState");})
		.mouseout(function(e){$(this).parent().removeClass("navHoverState");})
		.blur(function(e){$(this).parent().removeClass("navHoverState");});	

});


/* tab subnavigation - add keyboard suport for hover */
$("#navigation-primary ul li ul li a").focus(function(e){
  $(this).addClass("hover");
 }).blur(function(e){
  $(this).removeClass("hover");
 });

	if (addCurves)
	{
		/* Add in the curvy bits to the tertiary navigation (rather than have to add in unneccessary markup on each and every page */
		$("#navigation-tertiary ul:first").prepend("<li class='first'></li>");
		$("#navigation-tertiary ul:first").append("<li class='last'></li>");
		$("#navigation-tertiary ul li.first").html("<b></b>");
		$("#navigation-tertiary ul li.last").html("<b></b>");
	}

		function applyButtonStyles()
		{
		//start button behaviour
		$(".darkbg .button").wrap("<b class=\"button\"></b>")
		$("a.button, input.button").addClass("buttonstyles");
		$("a.apply, input.apply").addClass("applyButton");
		$("a.info, input.info").addClass("infoButton");

$("a.button.big, input.button.big").addClass("bigFatButton");
	
		$("a.button").each(function(e){
			if ($(this).html().length<5) {
				$(this).addClass("smallbutton");
			}
			if (($(this).html().length>10) && ($(this).html().length<21)) {
				$(this).addClass("bigbutton");
			}
			if ($(this).html().length>20) {
				$(this).addClass("hugebutton");
			}
		});
		$("input.button").each(function(e){
			if ($(this).attr("value").length<5) {
				$(this).addClass("smallbutton");
			}
			if (($(this).attr("value").length>7) && ($(this).attr("value").length<21)) {
				$(this).addClass("bigbutton");
			}
			if ($(this).attr("value").length>20) {
				$(this).addClass("hugebutton");
			}
		});
	
		$("a.button, input.button").each(function(){
			var buttonType="";
			if ($(this).hasClass("apply")){buttonType="Apply";}
			if ($(this).hasClass("info")) {buttonType="Info";}
			$(this).mousedown(function(e){	
	//			$(this).removeClass("button" + buttonType + "Hover");
				$(this).removeClass("button" + buttonType + "Click");
				$(this).addClass("button" + buttonType + "Click");
			}).mouseup(function(e){
				$(this).removeClass("button" + buttonType + "Click");
			}).mouseover(function(e){
				$("a.apply, input.apply").removeClass("button" + buttonType + "Click");
				$(this).addClass("button" + buttonType + "Hover");
			}).focus(function(e){
				$(this).addClass("button" + buttonType + "Hover");
			}).mouseout(function(e){
				$(this).removeClass("button" + buttonType + "Hover");
			}).blur(function(e){
				$(this).removeClass("button" + buttonType + "Hover");
			});
		});
		//end button behaviour
		}
		applyButtonStyles();

  function clickableParents()
		{
			$(".clickableParent").each(function(){
			 var thisLink = $(this).find("a.button:last").attr("href");
				$(this).find("img").wrap("<a href=\"" + thisLink + "\" class=\"addedLink noreposition\" tabindex=\"-1\"></a>");
			});
		}
		clickableParents();
		
		function removeUnwantedBorderFromLastTableRow()
		{
			$("div.productFeaturesTable table tr:last td, div.productFeaturesTable table tr:last th, div.panelBG table tr:last td, div.panelBG table tr:last th").css("border-bottom","none");
		}
		removeUnwantedBorderFromLastTableRow();
		
		// for home page so that the user hears more than just 'More Info' when tabbing through
		function fixMeaninglessMoreInfoLinks()
		{
		$("#homepage-campaigns a.info, #homepage-campaigns a.simple").each(function(){
			$(this).append(" <span class='srhelp'>(" + $(this).prev().children(0).attr("alt") + ")</span>");
		})
		$("span.srhelp")
		.css("display","block")
		.css("position","absolute")
		.css("top","0")
		.css("left","0")
		.css("width","1px")
		.css("height","1px")
		.css("text-indent","-30000px")
		.css("overflow","hidden")
		;
		}
		if (!$.browser.safari)
		{
			fixMeaninglessMoreInfoLinks();
		}
		
		function leftNavHasSubSection() 
		{
			$("#navigation-tertiary li a.current").parent().filter(":has(ul)").each(function(){
				$(this).children("a").addClass("hasSubSection");
			});
		}
		leftNavHasSubSection();

});

function showSkipLinks() {
var skipBgColor= "#004499";
var skipTextColor = "white";
// Amend/tweak these to your satisfaction	
var textIndent = "20px";
var skipNavHeight = "auto";
var skipFontSize = "2.4em";
var sk_a = document.getElementsByTagName("a");
for (i=0; i<sk_a.length; i++)
 {
	bodyEl = document.getElementsByTagName("body")[0];
	if (sk_a[i].className=="skip-link")
		{
		sk_a[i].onfocus=function(e){
			this.style.width="100%";
			this.style.padding="4px 0";
			this.style.fontSize = skipFontSize;
			this.style.height = skipNavHeight;
			this.style.textIndent = textIndent;
			this.style.backgroundColor = skipBgColor;
			this.style.color = skipTextColor;
			}
		sk_a[i].onblur=function(e){
			this.style.width="0";
			this.style.padding="0";
			this.style.fontSize="0px";
			this.style.height="0";
			this.style.textIndent="-30000px";
			this.style.backgroundColor="transparent";
			this.style.backgroundImage="none";
			}
		}
	}
}
function init()
{
//place calls to all functions that you want to run after page load here
showSkipLinks();
}
window.onload=init;

//Concertina script

$("dt").size()>0&&$("div.tabs>div, div.tabbedUI>div").size()>0&&(pageHasTabsAndConcertinas=!0);$("dt").each(function(){$(this).data("previewText","Click to read in full:"+$(this).next().text().substring(0,300)+"...").wrapInner('<a href="#" id="jumpAnchor_'+$(this).attr("id")+'"></a>');var a=location.href;a.indexOf($(this).attr("id"))!=-1&&(a=a.split("#")[1],a==$(this).attr("id")&&$(this).find("a").addClass("autoExpand"))});$("dd").each(function(){$(this).hide()}); $("dt>a").each(function(){$(this).attr("title",$(this).parent().data("previewText")).prepend("<b></b>").toggle(function(){$(this).addClass("expanded").removeAttr("title");$(this).parent().next().addClass("visible").slideDown("medium");return!1},function(){$(this).removeClass("expanded").attr("title",$(this).parent().data("previewText"));$(this).parent().next().removeClass("visible").slideUp("medium");return!1})});$("dl").each(function(){$(this).find("dt").size()>5&&$(this).prepend('<dt class="showHideAll"><a href="#"><b></b>Show all</a></dt>')}); $(".showHideAll a").each(function(){$(this).toggle(function(){$(this).parent().parent().addClass("showAll");$(this).parent().parent().removeClass("hideAll");$(this).html("<b></b>Hide all");$(this).parent().parent().find("dd").addClass("visible").show();$(this).parent().parent().find("dt a").not("dt.showHideAll a").each(function(){$(this).hasClass("expanded")||$(this).click()});$(this).parent().parent().find("dt a").addClass("expanded");$(this).parent().addClass("expanded");return!1},function(){$(this).parent().parent().addClass("hideAll"); $(this).parent().parent().removeClass("showAll");$(this).html("<b></b>Show all");$(this).parent().parent().find("dd").removeClass("visible").hide();$(this).parent().parent().find("dt a").not("dt.showHideAll a").each(function(){$(this).hasClass("expanded")&&$(this).click()});$(this).parent().parent().find("dt a").removeClass("expanded");return!1})});$("a.autoExpand").size()>0&&$("a.autoExpand").each(function(){$(this).html()!=""&&($(this).click().focus(),concertinaOpened=!0)});

