
$(document).ready(function() {

	// MyNav
	$('#my-nav').hover(
		function(){
			$(this).children('ul').show();
		},
		function(){
			$(this).children('ul').hide();
		}
	);

	// Nav
	//if(!location.href.match(/au\/money\/$/)){
	//quick mod to disable dropdowns
	if(1==0){
		$('#nav li.child').hover(
			function(){
				$(this).find('ul.dropdown').show();
				$(this).children('a').addClass('hover');
			},
			function(){
				$(this).find('ul.dropdown').hide();
				$(this).children('a').removeClass('hover');
			}
		);
		$('#nav ul.dropdown li').hover(
			function(){
				$(this).addClass('hover');
			},
			function(){
				$(this).removeClass('hover');
			}
		);
	}

	// Quicklinks
	$('#quicklinks .columns').hide();
	$('#quicklinks .title a').click(function(){
		if ($('#quicklinks .columns').css('display') == 'none') {
			$('#quicklinks .columns').show(500,function(){ document.getElementById('officials').scrollIntoView(false); });
			$(this).css('backgroundImage', "url(/system/modules/au.com.virginmoney/rebrand/images/quicklinks-arrow-close.gif)");
		} else {
			$('#quicklinks .columns').hide(500);	
			$(this).css('backgroundImage', "url(/system/modules/au.com.virginmoney/rebrand/images/quicklinks-arrow-open.gif)");
		}
		return false;
	});

	// Pane Tabber
	$('.pane-tabber').removeClass('pane-tabber').addClass('pane-tabber-active');
	$('.pane-tabber-active .panes > div').hide().eq(0).show();
	$('.pane-tabber-active .tabs > div:first').addClass('current').css('border-top','1px solid #000');
	$('.pane-tabber-active .tabs > div').click(function(){
		$('.pane-tabber-active .tabs > div').css('border-bottom','1px solid #000');
		$(this).prev('div').css('border-bottom','0');
		$('.pane-tabber-active .panes > div').hide();
		$('.pane-tabber-active .panes > div').eq($('.pane-tabber-active .tabs > div').index(this)).show();
		$('.pane-tabber-active .tabs > div').removeClass('current').eq($('.pane-tabber-active .tabs > div').index(this)).addClass('current');
	});

	// Accordion
	$('.accordion').accordion({
		autoHeight: false,
		header: 'a.header',
		alwaysOpen: false,
		active: false
	});
	
	// Image Switcher
	$('.switcher').hover(
		function () {
			$('img',this).eq(1).show().css('display','block');
			$('img',this).eq(0).hide();
		},
		function () {
			$('img',this).eq(0).show().css('display','block');
			$('img',this).eq(1).hide();
		}
	).css('display','inline');

	// Cycler
	$('.cycle').cycle({
		fade: 'fade',
		timeout: 1000,
		speed: 4000,
		cleartypeNoBg: true
	});
	
	// Pagination
	$('.pagination').before('<div class="pagination-nav"><div class="pagination-nav-wrap">').after('<div class="pagination-controls"><a class="pagination-prev" href="#">Previous</a> <a class="pagination-next" href="#">Next</a></div>').cycle({
	    fx:     'fade',
	    speed:  700,
	    timeout: 0,
	    pager:  '.pagination-nav-wrap',
		prev: '.pagination-prev',
		next: '.pagination-next',
		after: onAfter
	});
	
	function onAfter(curr, next, opts) {
	    var index = opts.currSlide;
		$('.pagination-prev')[index == 0 ? 'hide' : 'show']();
	    $('.pagination-next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
	}
	
	// PNG Fix
	$('div#subnav, div#page-header').pngFix();

	// General form clearing functions
	$('input').focus(function(){
		if ($(this).attr('value') == 'Membership no.' || $(this).attr('value') == 'password') {
			$(this).attr('value','');
		}
	});


	// 'Retreive a quote' form functions
	$('.inputbox-style1').focus(function(){
		if ($(this).attr('value') == 'Enter quote ref #' || $(this).attr('value') == 'Invalid number') {
			$(this).attr('value','');
		}
	});
	$('.inputbox-style1').keydown(function(){
		$(this).css('color','#000000');
	});
	$('.inputbox-style1').keyup(function(){
		$(this).attr('value',$(this).attr('value').toUpperCase());
	});

	$('.ledForm').submit(function(){
		if ($(this).find('.inputbox-style1').attr('value').match(/^E[0-9][A-L][0-9]{6}$/)) {
			return true;
		}
		
		$(this).find('.inputbox-style1').attr('value','Invalid number').css('color','#FF0000');
		return false;
	});
	imgArray = ['/images/icons/virgin-money-login-', '/images/rebrand/virgin-money-remind-me-', '/images/rebrand/5000points-velocity-', '/images/rebrand/5000points-', '/images/rebrand/50000points-', '/images/rebrand/100000points-', '/images/rebrand/50credit-', '/images/rebrand/50creditlater-'];
	offPostfix = '1.png';
	onPostfix = '2.png';
	$("input:image").each(function(a,b){
		for(i = 0; i < imgArray.length; i++){
			if($(b).attr('src') == imgArray[i] + offPostfix){
				$(b).attr('onimage', imgArray[i] + onPostfix)
				$(b).attr('offimage', imgArray[i] + offPostfix)
				$(b).hover(function(){
					$(this).attr('src', $(this).attr('onimage'));
				}, function(){
					$(this).attr('src', $(this).attr('offimage'));
				});
			}
		}
	});
	// Custom form submit input image hover states
/*	$("input[src='/images/icons/virgin-money-login-1.png']").hover(
		function(){
			$(this).attr('src','/images/icons/virgin-money-login-2.png');
		},
		function(){
			$(this).attr('src','/images/icons/virgin-money-login-1.png');			
		}
	);
	$("input[src='/images/rebrand/virgin-money-remind-me-1.png']").hover(
		function(){
			$(this).attr('src','/images/rebrand/virgin-money-remind-me-2.png');
		},
		function(){
			$(this).attr('src','/images/rebrand/virgin-money-remind-me-1.png');			
		}
	);

	$("input[src='/images/rebrand/5000points-1.png']").hover(
		function(){
			$(this).attr('src','/images/rebrand/5000points-2.png');
		},
		function(){
			$(this).attr('src','/images/rebrand/5000points-1.png');			
		}
	);
	$("input[src='/images/rebrand/50000points-1.png']").hover(
		function(){
			$(this).attr('src','/images/rebrand/50000points-2.png');
		},
		function(){
			$(this).attr('src','/images/rebrand/50000points-1.png');			
		}
	);
	$("input[src='/images/rebrand/100000points-1.png']").hover(
		function(){
			$(this).attr('src','/images/rebrand/100000points-2.png');
		},
		function(){
			$(this).attr('src','/images/rebrand/100000points-1.png');			
		}
	);
	$("input[src='/images/rebrand/50credit-1.png']").hover(
		function(){
			$(this).attr('src','/images/rebrand/50credit-2.png');
		},
		function(){
			$(this).attr('src','/images/rebrand/50credit-1.png');			
		}
	);
	$("input[src='/images/rebrand/50creditlater-1.png']").hover(
		function(){
			$(this).attr('src','/images/rebrand/50creditlater-2.png');
		},
		function(){
			$(this).attr('src','/images/rebrand/50creditlater-1.png');			
		}
	);*/
});
