$(document).ready(function(){
			
	//PNG fix
	$(document).pngFix();
	
});

// 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
jQuery.fn.extend({
  scrollTo : function(speed, easing) {
    return this.each(function() {
      var targetOffset = $(this).offset().top;
      $('html,body').animate({scrollTop: targetOffset}, speed, easing);
    });
  }
});
$(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);
		}
	});
});

// LAUNCH SAVINGS PRODUCT COMPARISON APPLICATION
$(function(){	
	
	// if javascript is turned off, make sure the Savings Account Tool doesn't show
	$(".rhsSavingsComparisonBanner").css('display','block');

	// LAUNCH
	$('#launchApplication').click(function() {
		window.open('/savings/comparison/index.html', '', 'location=no,width=1024,height=768,resizable=yes,scrollbars=yes,toolbar=no,status=no');
	});
	
});

// OPEN ONLINE SAVINGS APPLICATIONS IN NEW WINDOW
$(function() {
		   
	/*$('.loginLaunch').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.thechelsea.co.uk/public/authentication/pre_login.do',null,openAppFeatures
		);
	});*/
		   
	$('.ebondAppLaunch').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.thechelsea.co.uk/public/savings/application/load_ebond.do',null,openAppFeatures
		);
	});
	
	$('.esaverRewardAppLaunch').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.thechelsea.co.uk/public/savings/application/load_deferred_product.do',null,openAppFeatures
		);
	});
	
	$('.eISAppLaunch').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.thechelsea.co.uk/public/savings/application/load_eisa.do',null,openAppFeatures
		);
	});

	
	$('.savingsDemoLaunch').click(function() {
		var middlePosition = screen.width/2 - 503; 
		var hightValue = screen.height - 450; 
		openAppFeatures = 'top=25,left=' + 
		middlePosition + 
		',height=' + 
		hightValue +
		',width=870,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes'; 
		window.open(															
			'http://www.thechelsea.co.uk/savings/demo/index.html?int_cmp=onlineacc_demo',null,openAppFeatures
		);
	});
	
});	