// PAGES WITH TABS THAT REQUIRE IN PAGE LINKS, OR MORE SPECIFICALLY LINKS TO A NAMED ANCHOR EG. #LEGAL UTITLISE THIS FUNCTION SO AS NOT TO DISRUPT URL AND HISTORY
/* Sep 2010 - following improvements made (MK):
1) inPageScroll - class can be used as well as id to allow for multiple anchored links on any given page
2) speed/easing explicitly specified, to avoid conflict with s_code.js (Omniture tracking)
*/

jQuery.fn.extend({
  scrollTo : function() {
    return this.each(function() {
      var targetOffset = $(this).offset().top;
      $('html,body').animate({scrollTop: targetOffset}, 1000);
    });
  }
});
$(function(){
	$('.inPageScroll').click(function() {	
		var numberer = '#pos' + $(this).attr("href");
		$(numberer).scrollTo();
	});
	$('a[href=#apply]').click(function() {	
	  $('#centerColumnContent').scrollTo();
	});

});

/* 
BELOW IS RECOMMENDED IMPROVED VERSION OF THE SAME FNCTIONALITY WITH THE FOLLOWING BUGS FIXED:
THIS IS ALREADY USED ON PCA PAGE

jQuery.fn.extend({
  scrollTo : function() {
    return this.each(function() {
      var targetOffset = $(this).offset().top;
      $('html,body').animate({scrollTop: targetOffset}, 1000);
    });	 
  }
});
$(function(){
	$('.inPageScroll').click(function() {
		$('#scrolled').scrollTo();
	});
});
*/



// MANAGING SAVINGS PAGE, SHOW/HIDE FAQ ANSWERS
$(function(){
	$("a.faqQuestion").click(function(event){
	   event.preventDefault();
	   $(this).next("div.faqAnswer").slideToggle(500);
	 });
});	  



// HOME //
// CAN WE HELP... DROPDOWN REDIRECTS //
// RESET "CAN WE HELP YOU..." DROPDOWNS TO ORIGINAL VALUE
$(function(){
	$('#selectApply, #selectQuote, #selectRates, #selectFind').find('option:first').attr('selected', 'selected').parent('select');
});
// REDIRECT USER TO RELEVANT DROPDOWN LINK ON SELECTION OF CAN WE HELP DROPDOWN
$(function(){
	$("#rightColumn .helpContent SELECT").change(function(){
		location = $("OPTION:selected", this).val();
	});
}); 

// CONTENT //
// INTEREST RATES SHOW/HIDE CURRENT/PREVIOUS RATES
function showPreviousRates() {
	$('#previousRates').css('display','block');
	$('#currentRates').css('display','none');
};

function showCurrentRates() {
	$('#currentRates').css('display','block');
	$('#previousRates').css('display','none');
};


// ACCOUNT STATEMENT NOTES ROLLOVER UPDATES
$(function() {	
	var note1Text = "<p><strong><u>Note 1</u></strong><br />"
	+ "This is the 'cleared' balance of your account at the close of business on 5&nbsp;April&nbsp;2010.</p>";
	var note2Text = "<p><strong><u>Note 2</u></strong><br />"
	+ "This is the date of the most recent interest payment made for this account.</p>";
	var note3Text = "<p><strong><u>Note 3</u></strong><br />"
	+ "This is the total gross value of interest paid for this account (ie before tax).</p>";
	var note4Text = "<p><strong><u>Note 4</u></strong><br />"
	+ "This figure is the amount of tax we have deducted (if any) from the gross interest, and paid directly to HM Revenue and Customs.</p>";
	var note5Text = "<p><strong><u>Note 5</u></strong><br />"
	+ "This is the net value of interest actually paid to you, ie after tax has been deducted.</p>";
	var note6Text = "<p><strong><u>Note 6</u></strong><br />"
	+ "This shows the next expected interest payment date, and is determined by the terms of your account.</p>";
	
	$("#annualStatementNotes a")./*mouseout(function(){
	  $(".annualStatementDefinition").html("<p><strong>Rollover each of the notes below to show a more detailed explanation of each part of the Annual Statement:</strong></p>");
	}).*/mouseover(function(){
		if (($(this).attr("title")) == "note1"){
	  		$(".annualStatementDefinition").html(note1Text);
		}
		else if (($(this).attr("title")) == "note2"){
	  		$(".annualStatementDefinition").html(note2Text);
		}
		else if (($(this).attr("title")) == "note3"){
	  		$(".annualStatementDefinition").html(note3Text);
		}
		else if (($(this).attr("title")) == "note4"){
	  		$(".annualStatementDefinition").html(note4Text);
		}
		else if (($(this).attr("title")) == "note5"){
	  		$(".annualStatementDefinition").html(note5Text);
		}
		else if (($(this).attr("title")) == "note6"){
	  		$(".annualStatementDefinition").html(note6Text);
		}
	});
});


// OPEN ONLINE SAVINGS APPLICATIONS IN NEW WINDOW
$(function() {
	$('.mortgageAppLaunch').click(function() {
		if ($('input[name=hasBeenRead]:checked').val() == 'Y')
		{	
			alert('IMPORTANT - When you submit your application we will obtain details from a credit reference agency.  This will leave a record of our check on your credit data.');
			var middlePosition = screen.width/2 - 503; 
			var hightValue = screen.height - 110; 
			openAppFeatures = 'top=25,left=' + 
			middlePosition + 
			',height=' + 
			hightValue +
			',width=1000,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes'; 
			window.open(															
				'https://online.ybs.co.uk/public/mortgages/new_direct_mortgage.do',null,openAppFeatures
			);
		}
		if ($('input[name=hasBeenRead]:checked').val() == 'N')
		{
			alert('You must read the Initial Disclosure Document before proceeding.');			
		}
		return false;		
	});

	$('.eisaAppLaunch').click(function() {
		var middlePosition = screen.width/2 - 503; 
		var hightValue = screen.height - 110; 
		openAppFeatures = 'top=25,left=' + 
		middlePosition + 
		',height=' + 
		hightValue +
		',width=1000,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes'; 
		window.open(															
			'https://online.ybs.co.uk/public/savings/application/load_eisa.do',null,openAppFeatures
		);
		return false;		
	});

	$('.internetSaverAppLaunch').click(function() {
		var middlePosition = screen.width/2 - 503; 
		var hightValue = screen.height - 110; 
		openAppFeatures = 'top=25,left=' + 
		middlePosition + 
		',height=' + 
		hightValue +
		',width=1000,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes'; 
		window.open(															
			'https://online.ybs.co.uk/public/savings/application/load_esaver.do',null,openAppFeatures
		);
		return false;
	});
});	

// Press releases page - date rewrite
$(function(){
	$('.startdate').each(function() {
		year = $(this).html().split('-')[0];
		month = $(this).html().split('-')[1]; 
		if (month == '01') month = 'January';
		if (month == '02') month = 'February';
		if (month == '03') month = 'March';
		if (month == '04') month = 'April';
		if (month == '05') month = 'May';
		if (month == '06') month = 'June';
		if (month == '07') month = 'July';
		if (month == '08') month = 'August';
		if (month == '09') month = 'September';
		if (month == '10') month = 'October';
		if (month == '11') month = 'November';
		if (month == '12') month = 'December';
		day = $(this).html().split('-')[2]; 
		if (day) 
			{
			day = day.split(' ')[0]; 
			if (day.split('')[0] == '0') day = day.split('')[1];
			}
		if (year && month && day) $(this).html(day + ' ' + month + ', ' + year);
	  });
	
// OOBA DEMO 	
$('.OobaDemoLaunch').click(function() {
		var middlePosition = screen.width/2 - 503; 
		var hightValue = screen.height - 350; 
		openAppFeatures = 'top=25,left=' + 
		middlePosition + 
		',height=' + 
		hightValue +
		',width=870,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes'; 
		window.open(															
			'http://ybs.co.uk/security_privacy/demo/index.html',null,openAppFeatures
		);
	});		
	
});
