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").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();

$("#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("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;
