$(document).ready(function(){
						   
	//image rollover
	$.swapImage(".swapImage");	
	
	//easyslider	
	$("#slider").easySlider({
		auto: true, 
		continuous: true,
		numeric: true
	});
			
	//PNG fix
    $(function(){
		$(document).pngFix();
	});
	
	//primaryNav	
	$("ul.topnav li").hover(function() { //When trigger is clicked...
		
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).find("ul.subnav").show(); //Drop down the subnav on click

		$(this).hover(function() {
		}, function(){	
			$(this).find("ul.subnav").hide(); //When the mouse hovers out of the subnav, move it back up
		});
	});

	// Synthetix FAQ
	$("#searchtext, #searchtext2").click(function() {
		$(this).val("");
		$(this).css("color", "#000");
	});


});	

// OOBA Splash page - only shown once to each user
$(function(){
// If user clicks on Login link, set seenOOBA2_BBS cookie to 'yes' and show popup layer
// If it's already set to 'yes' - do nothing (proceed with the link)
	$('a[href="https://online.barnsley-bs.co.uk/public/authentication/pre_login.do"]').click(function() {
		if ($.cookie('seenOOBA2_BBS') != 'yes') 
		{ 
			$.cookie('seenOOBA2_BBS', 'yes', {expires: 365} );
			// Horisontal centering - move (540px / 2) pixels to the left from the center of the page
			$('.oobaPopup').css('margin-left', '-270px');
			// Vertical centering - add top margin but if value becomes negative set to 10px instead
			var oobaMarginTop = Math.max((($(window).height() - $('.oobaPopup').height())/2 - 50), 10);
			$('.oobaPopup').css('margin-top', oobaMarginTop); 
			$('.oobaPopup').show('slow');
			$('.oobaPopupContainer').show();
			return false;
		}
	}); 
	
	$('a.continueToLogin').click(function() {
		$('.oobaPopup').hide(); $('.oobaPopupContainer').hide();
    });

	$('a.oobaClose').click(function() {
		 $('.oobaPopup').hide('slow'); $('.oobaPopupContainer').hide();
	});
});

// accordion
$(function(){
	$("#accordionContainer").accordion({ 
		header: '.productCategory'
	});							   
	
	var accordions = $("#accordionContainer");
	
	$("#showAll").click(function() {
		$(".basic a").addClass('selected');		
		accordions.accordion("destroy");
		wizardButtons.unbind("click");		
	});
});


// quicknav
/*
$(function(){	
	
	// by default the css value of quicknav on load is set to invisible so it does not show with js switched off. This sets it to visible if user has js active.
	$('#quicknav').css("visibility","visible");	

	// BUTTONS
	$('.fg-button').hover(
		function(){ $(this).removeClass('ui-state-quicknav-default').addClass('ui-state-quicknav-focus'); },
		function(){ $(this).removeClass('ui-state-quicknav-focus').addClass('ui-state-quicknav-default'); }
	);
	
	// MENUS    	
	$('#flat').menu({ 
		content: $('#flat').next().html(), // grab content from this page
		showSpeed: 400 
	});
	
	$('#hierarchy').menu({
		content: $('#hierarchy').next().html(),
		crumbDefaultText: ' '
	});
	
	$('#hierarchybreadcrumb').menu({
		content: $('#hierarchybreadcrumb').next().html(),
		backLink: false
	});
	
	// or from an external source
	$.get('menuContent.html', function(data){ // grab content from another page
		$('#flyout').menu({ content: data, flyOut: true });
	});
});	
*/
	
// scrollable
$(function() {	
	// by default the css value of the next arrow on load is set to invisible so it does not show with js switched off. This sets it to visible if user has js active.
	$('.next').css("visibility","visible");		
		
	// initialize scrollable 
	$("div.scrollable").scrollable({
		size: 3,
		items: '#thumbs',  
		hoverClass: 'hover'
	});		
	
	/* tooltip remover */
	$(".next").click(function(){
		$("#tooltipright").css("display","none");
	});
	
	$(".prev").click(function(){
		$("#tooltipleft").css("display","none");
	});		
	
});


// LAUNCH SAVINGS PRODUCT COMPARISON APPLICATION
$(function(){	
	
	// if javascript is turned off, make sure the Savings Account Tool doesn't show
	$("#scrollableSavingsComparison").css('display','block');
	$(".savingsCompareBanner").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');
	});
	
// 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://www.barnsley-bs.co.uk/tcs-demo/index.html',null,openAppFeatures
		);
	});	
	
});
