$(document).ready(function() {

	//set the corners on sub navigation elements on col 3
	//uses the cornerz plugin - not curvycorners like the homepage
	$('#col_3 > .sub_nav').cornerz({radius:10});
	$('#col_1 > .sub_nav_static').cornerz({radius:10});
	$('#col_3 > .sub_nav_static').cornerz({radius:10});
	$('#bread_crumb').cornerz({radius:10});
	$('.feature_control  li').cornerz({radius:10});
	$('.suppNav').cornerz({radius:10});
	$('.tgNav').cornerz({radius:10});
	$('.sitemapNavWrapper').cornerz({radius:10});
	$('.cPod').cornerz({radius:10});
	$('.redbox').cornerz({radius:10});
	$('#redbox_scroller_control li').cornerz({radius:10});
	$('#nyroModalFull').cornerz({radius:10});
	$('#popUpCTA').cornerz({radius:10});
	$('#applyWrapper').cornerz({radius:10});


	$('.leadNav .navTitle').topcornerz({radius:10});


	//inititate the scrollTo class and set default values
	$.scrollTo.defaults.axis = "xy";
    $.scrollTo(0);
	var scrollSpeed = 800;

	//set the scrollTo functionality for the scroller element - used at the top of hubpages
	$("#scroller").scrollTo(0);
    var $paneTarget = $("#scroller");
    $paneTarget.scrollTo(0);

	//set the behaviour for links
    $("#slink_1").click(function () {
		$paneTarget.scrollTo("#section_a", scrollSpeed);
		setFeatureControl(0);
		return false;
	});
    $("#slink_2").click(function () {
		$paneTarget.scrollTo("#section_b", scrollSpeed);
		setFeatureControl(1);
		return false;
	});
    $("#slink_3").click(function () {
		$paneTarget.scrollTo("#section_c", scrollSpeed);
		setFeatureControl(2);
		return false;
	});
	$("#slink_4").click(function () {
		$paneTarget.scrollTo("#section_d", scrollSpeed);
		setFeatureControl(3);
		return false;
	});
	//function defined to assist scroller functionality. sets the colour of controlling tabs
	function setFeatureControl(pos) {
		$("#feature .feature_control li").attr("class","");
		$("#feature .feature_control li:eq("+pos+")").attr("class","active");
	}

	//set the scrollTo functionality for the redbox_scroller element
	$("#redbox_scroller").scrollTo(0);
    var redbox_target = $("#redbox_scroller");
    redbox_target.scrollTo(0);

	//set the behaviour for links
    $("#rblink_1").click(function () {
		redbox_target.scrollTo("#rb_section_a", scrollSpeed);
		setRedBoxControl(0);
		return false;
	});
    $("#rblink_2").click(function () {
		redbox_target.scrollTo("#rb_section_b", scrollSpeed);
		setRedBoxControl(1);
		return false;
	});
    $("#rblink_3").click(function () {
		redbox_target.scrollTo("#rb_section_c", scrollSpeed);
		setRedBoxControl(2);
		return false;
	});
    $("#rblink_4").click(function () {
		redbox_target.scrollTo("#rb_section_d", scrollSpeed);
		setRedBoxControl(3);
		return false;
	});
    $("#rblink_5").click(function () {
		redbox_target.scrollTo("#rb_section_e", scrollSpeed);
		setRedBoxControl(4);
		return false;
	});
    $("#rblink_6").click(function () {
		redbox_target.scrollTo("#rb_section_f", scrollSpeed);
		setRedBoxControl(5);
		return false;
	});
	//function defined to assist redbox_scroller functionality. sets the colour of controlling tabs
	function setRedBoxControl(pos) {
		$("#redbox_scroller_control li").attr("class","");
		$("#redbox_scroller_control li:eq("+pos+")").attr("class","active");
	}




	//set mouseover behaviours for the cta images

	$("#cta_click").mouseover(function () {		
		$("#cta_click_image").attr("src","/_site/images/common/icons/cta-click-on.gif");
	});
	
	$("#cta_click").mouseout(function () {		
		$("#cta_click_image").attr("src","/_site/images/common/icons/cta-click-off.gif");
	});
	
	$("#cta_call").mouseover(function () {		
		$("#cta_call_image").attr("src","/_site/images/common/icons/cta-call-on.gif");
	});
	
	$("#cta_call").mouseout(function () {		
		$("#cta_call_image").attr("src","/_site/images/common/icons/cta-call-off.gif");
	});	

	$("#cta_visit").mouseover(function () {		
		$("#cta_visit_image").attr("src","/_site/images/common/icons/cta-visit-on.gif");
	});
	
	$("#cta_visit").mouseout(function () {		
		$("#cta_visit_image").attr("src","/_site/images/common/icons/cta-visit-off.gif");
	});



	//javascript generated date
	var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
	var months = ["January","February","March","April","May","June","July","August","September","October","November","December"]
	var date = new Date();
	var str_date = days[date.getDay()]+" "+date.getDate()+" "+months[date.getMonth()];
	$("#datetime").text(str_date);


	//check to see if the hub and sub_nav have been set in the page
	//if they are set then set display properties
	try{
		if((hub != undefined) && (hub.length > 0)) {
			$("#nav_"+hub).addClass("active");
		}
		if((sub_nav_1 != undefined) && (sub_nav_1.length > 0)) {
			$("#subnav_"+sub_nav_1).addClass("active");
		}
		if((sub_nav_2 != undefined) && (sub_nav_2.length > 0)) {
			$("#subnav_"+sub_nav_2).addClass("active");
		}
		if((sub_nav_3 != undefined) && (sub_nav_3.length > 0)) {
			$("#subnav_"+sub_nav_3).addClass("active");
		}
	}catch(e){}

	//using the sub_nav definitions - set out the display elements for sub navigation
	var sub_nav_options = [sub_nav_1, sub_nav_2, sub_nav_3];
	$.fn.subnavigate(sub_nav_options);


	//tooltip code for valuation and conveyance icons on product tables
	$('a.product_table_icon_valuation, a.product_table_icon_conveyance').cluetip({
		cluetipClass: 'pretty',
		positionBy: 'auto',
		showTitle: false,
		sticky: true,
		dropShadow: false,
		activation: 'click',
		closePosition: 'bottom'
	});


	//nyroModal pluginis used to power the product detail pop-up
	if($('.product_option_detail a').length > 0) {
		$('.product_option_detail a').nyroModal({
			bgColor: '#fff',
			width:200
		});
	}

	//nyroModal pluginis used to power the quick search pop-up
	if ($('.nav_search a').length > 0) {
		$('.nav_search a').nyroModal({
			bgColor: '#fff',
			width:490
		});

	}



	//generate mortgage product tables
	if($('#product_data').length == 1) {
		
		try {
			$.fn.productBuilder(product_ids);
		} catch(e){}
		
	}

	//functionality to control display of the product detail tables
	//hide the body on page load
	$(".redbox_body").hide();

	//only the expander icon should be displayed on load
	$(".redbox_header").each(function() {
		$(this).find(".product_option_detail").hide();
		$(this).find(".product_option_quote").hide();
		$(this).find(".product_expander").show();
	});

	//define behaviours for user actions
	$(".redbox_title").click(function() {
		var target = $(this).parent().parent().children(".redbox_body");
		toggleProductTable(target);
	});
	$(".product_expander, .product_shrinker").click(function() {
		var target = $(this).parent().parent().parent().children(".redbox_body");
		toggleProductTable(target);
	});
	function toggleProductTable(target) {
		if (target.is(":hidden")) {
			target.slideDown(1400);
			target.parent().children(".redbox_header").find(".product_expander").hide();
			target.parent().children(".redbox_header").find(".product_shrinker").fadeIn(1400);
			target.parent().children(".redbox_header").find(".product_option_detail").fadeIn(1400);
			target.parent().children(".redbox_header").find(".product_option_quote").fadeIn(1400);
		}
		else {
			target.slideUp(1400);
			target.parent().children(".redbox_header").find(".product_expander").fadeIn(1400);
			target.parent().children(".redbox_header").find(".product_shrinker").hide();
			target.parent().children(".redbox_header").find(".product_option_detail").hide();
			target.parent().children(".redbox_header").find(".product_option_quote").hide();
			$('#cluetip').hide();
		}
	}


	//font control for low graphics page
	// Reset Font Size
	var originalFontSize = $('html').css('font-size');
		$(".resetFont").click(function(){
		$('html').css('font-size', originalFontSize);
	});
	// Increase Font Size
	$(".increaseFont").click(function(){
		var currentFontSize = $('html').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*1.2;
		$('html').css('font-size', newFontSize);
		return false;
	});
	// Decrease Font Size
	$(".decreaseFont").click(function(){
		var currentFontSize = $('html').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*0.8;
		$('html').css('font-size', newFontSize);
		return false;
	});


	//add the date to printed version of pages
	$('#printer_url_details').append('URL: '+window.location.href+'<br/>Printed on: '+Date());

});






// jump menu for log on

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/**********************************************************/
/* start - Generic PDF code to generate PDF name from address bar
/**********************************************************/
/* Tony Nall : 231008
/*
/*
/**********************************************************/

		loc = document.location.href;

		//var re = /www.britannia.co.uk\//g;
		//loc = loc.replace(re,'');
		// removed as now removing domain from address below TN

		var re = /home\//g;
		loc = loc.replace(re,'');

		trimPosition=loc.indexOf("://") + 3; //count characters required for server address - everything after ://
		pdfAddress=loc.substring(trimPosition); // get server address inc sub folders

		trimPosition=pdfAddress.indexOf("/") + 1; //count characters required for address minus the domain - everything after first /
		pdfAddress=pdfAddress.substring(trimPosition); // get address minus server inc sub folders

		var re = /\.html/g;
		pdfAddress = pdfAddress.replace(re,'');

		var re = /\//g;
		pdfAddress = pdfAddress.replace(re,'.');


/**********************************************************/
/* end - Generic code to get affinity name from address bar
/**********************************************************/

/**********************************************************/
/* start - Generic PDF tracking Code - TN 231008
/**********************************************************/

function pdfLink(obj) {
var s=s_gi('britbscoukprod');
s.linkTrackVars='None';
s.linkTrackEvents='None';
s.tl(obj,'d',pdfAddress);
}

/**********************************************************/
/* end - Generic PDF tracking Code
/**********************************************************/


/**********************************************************/
/* start - Cookie checking. 11/05/09
/**********************************************************/


//---------------------------------------------------------------------------------------------
// Obtain the value of the document cookie
//---------------------------------------------------------------------------------------------
function GetCookie(Name)
{
  var String = document.cookie;
  var Prefix = Name + "=";
  var Value  = null
  var Begin  = String.indexOf(Prefix);

  if (Begin != -1)
  {
    var End = String.indexOf(";", Begin);

    if (End == -1)
    {
      End = String.length;
    }

    Value = String.substring(Begin + Prefix.length, End);
  }

  return Value;
}

/**********************************************************/
/* end - Cookie checking. 11/05/09
/**********************************************************/

/**********************************************************/
/* start - mortgage reload page to set buyer type
/**********************************************************/

function reLoad(Type)
{
setmtgType(Type);
window.location.reload();
}


/**********************************************************/
/* end - mortgage reload page to set buyer type
/**********************************************************/