var $j=jQuery.noConflict();
var alertText = "Please be advised that you are leaving Advantage Plus Federal Credit Union's website. This link is provided as a courtesy. Advantage Plus Federal Credit Union does not endorse or control the content of third party websites.";
var customFolder = "advantagepluscreditunion";
var slideSpeed = 500;
var tabEffect = "fade";
function wrapperAdjustment(){
	$j('#wrapper').css('height','auto');
	var windowHeight = $j(window).height();
	var wrapperHeight = $j('#wrapper').height();
	if (windowHeight > wrapperHeight){
		$j('#wrapper').css('height',windowHeight);
	}
}
$j(window).load(function(){
	wrapperAdjustment();
	$j(window).resize(function(){
		wrapperAdjustment();
	});
	if($j('#homeBanner img').length){
		$j('#homeBanner img').wrap('<a href="/checking/free-reward-checking.html"/>');
	}
});

$j(document).ready( function() {
	productTabs();
	if($j('#productIntro').length){
		Cufon.replace('#productIntro h1');
	}
	if($j('.individualPage').length){
		Cufon.replace('.individualPage h1');
	}
	if($j('#applicationPage').length){
		Cufon.replace('fieldset#newApplication div#introduction h1');
	}
	if($j('.multiPage').length){
		Cufon.replace('fieldset#newApplication div#introduction h1');
	}
	if($j('#leftColumn').length){
		Cufon.replace('#leftColumn #quickLinks h2');
	}
	$j(".confirm").click( function() {						   
		if (!confirmAlert($j(this).attr('href'))){
			return false;			
		}
	});
	if($j('#wrapper').length > 0){
		//$j('#wrapper a').each(function(){
			//var bustURL = $j('#wrapper a:first').attr('href');
			$j('#wrapper a:first').attr('href','/index.html?var=home');
		//});
	}
	//	Overlabel - place a div with the class 'overLabelWrapper' around whatever will be using this code. Make sure that the label is set to display block
	if($j('.overLabelWrapper').length){
		var labelFor = $j('.overLabelWrapper form label[for]');
		var inputFor = $j('.overLabelWrapper form input').attr('id');
		if (labelFor !== inputFor) {
			labelFor.addClass('overLabel');
			$j('.overLabelWrapper input[type=text]').addClass('overLabel');
			$j('.overLabelWrapper input[type=password]').addClass('overLabel');
			$j('.overLabelWrapper input.overLabel').focus(function(){
				$j(this).prev().css({
					'text-indent': '-999em'
				});
			});
			$j('.overLabelWrapper input.overLabel').blur(function(){
				if($j(this).val() == ''){
					$j(this).prev().css({
						'text-indent': '0'
					});
				}
			});
			$j('.overLabelWrapper label.overLabel').click(function(){
				$j(this).css('text-indent','-999em');
				$j(this).next('.BodyCopy').trigger('focus');
			})
		}
	}
	if($j('#obNav').length){
		$j('#obNav a#demoButton').click(function(){
			$j('#demosubmit').trigger('click');
		});
	}
	
	if($j('body#onlineBanking').length){
		$j('body#onlineBanking #obNav li a').attr('target','_blank');
		$j('body#onlineBanking #obNav li:eq(1)').addClass('second');
	}
	if($j('#quickLinks').length){
		$j('#quickLinks a:contains("Switch Kit")').attr('target','_blank');
	}
	if($j('#rates').length){
		$j('#rates a:contains("Mortgage Rates")').attr('target','_blank');
	}
	if($j('#homeFeatures').length){
		$j('#greatRates li').addClass('enabled');
		$j('#greatRates li').hover(function(){
			$j(this).find('a').addClass('hover');
		},function(){
			$j(this).find('a').removeClass('hover');
		});
		$j('#greatRates li').click(function(){
			window.location = $j(this).find('a').attr('href');
		});
		$j('#serviceGroup').addClass('enabled');
		$j('#serviceGroup').hover(function(){
			$j(this).find('a').addClass('hover');
		},function(){
			$j(this).find('a').removeClass('hover');
		});
		$j('#serviceGroup').click(function(){
			window.location = $j(this).find('a').attr('href');
		});
	}
	// anythingSlider
	if ($j('#greatRates').length > 0 ){
		var checkingRate = $j('#checkingTable td.homeRates').text();
		var checkingRateLength = checkingRate.length-1;
		var loanRate = $j('#loansTable td.homeRates').text();
		var loanRateLength = loanRate.length-1;
		var savingsRate = $j('#savingsTable td.homeRates').text();
		var savingsRateLength = savingsRate.length-1;
		var cdRate = $j('#cdsTable td.homeRates').text();
		var cdRateLength = cdRate.length-1;
		
		var checkingRate = checkingRate.substr(0,checkingRateLength);
		var loanRate = loanRate.substr(0,loanRateLength);
		var savingsRate = savingsRate.substr(0,savingsRateLength);
		var cdRate = cdRate.substr(0,cdRateLength);
		
		$j('#greatRates li.nthChild-1 .rateWrapper').prepend(cdRate);
		$j('#greatRates li.nthChild-2 .rateWrapper').prepend(loanRate);
		$j('#greatRates li.nthChild-3 .rateWrapper').prepend(checkingRate);
		$j('#greatRates li.nthChild-4 .rateWrapper').prepend(savingsRate);
		
		$j('.anythingSlider ul').show();

		$j('#greatRates').anythingSlider({
			easing			: "easeInOutExpo", // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay		: true, // This turns off the entire FUNCTIONALY
			startStopped	: false, // If autoPlay is on, this can force it to start stopped
			delay			: 13000, // How long between slide transitions in AutoPlay mode
			animationTime	: 500, // How long the slide transition takes
			hashTags		: true, // Should links change the hashtag in the URL?
			buildNavigation	: true, // If true, builds and list of anchor links to link to each slide
			pauseOnHover	: true, // If true, and autoPlay is enabled, the show will pause on hover
			startText		: "Start", // Start text
			stopText		: "Stop", // Stop text
			navigationFormatter: null // Details at the top of the file on this use (advanced use)
		});
		if($j('#thumbNav').length > 0) {
			$j('#thumbNav a:nth-child(1)').addClass('nthChild-1');
			$j('#thumbNav a:nth-child(2)').addClass('nthChild-2');
			$j('#thumbNav a:nth-child(3)').addClass('nthChild-3');
			$j('#thumbNav a:nth-child(4)').addClass('nthChild-4');

		}
		$
		$j("#slide-jump").click(function(){
			$j('.anythingSlider').anythingSlider(5);
		});
	}
	if($j("#atmLocator").length){
		$j('#atmLocator input#submitButton').hover(function(){
			$j(this).addClass('hover');
		},function(){
			$j(this).removeClass('hover');
		});
	}
// Category Related Products Hover
	if($j('#productCategory').length){
		$j('#productCategory li.odd').addClass('enabled');
		$j('#productCategory li.even').addClass('enabled');
		$j('#productCategory li .photoHover img').each(function(){
			var imageSource = $j(this).attr('src');
			var imageSource2 = '/'+imageSource;
			$j(this).attr('src',imageSource2);
		});
		$j('#productCategory li').hover(function(){
			$j(this).find('.photoHover').hide();
			$j(this).find('.photoNormal').show();
			$j(this).find('.learnMore').addClass('hover');
			$j(this).find('h3 a').addClass('hover');
		},function(){
			$j(this).find('.photoHover').show();
			$j(this).find('.photoNormal').hide();
			$j(this).find('.learnMore').removeClass('hover');
			$j(this).find('h3 a').removeClass('hover');
		});
		$j('#productCategory li').click(function(){
			window.location = $j(this).find('a').attr('href');
		});
	}
// Product Page
	if($j('#productDetails').length){
		$j('#productTabs dt').wrapInner('<span class="dtBody"/>').prepend('<span class="leftBG"></div>').append('<span class="rightBG"></div>');
		$j('#productTabs dt .dtBody').append('<span class="arrow"></span>');
		$j('#productTabs dt').hover(function(){
			if($j(this).hasClass('selected') === false) {
				$j(this).find('.arrow').css('background-position','left top');
			}
		},function(){
			if($j(this).hasClass('selected') === false) {
				$j(this).find('.arrow').css('background-position','left -21px');
			}
		});
		$j('#productTabs dt:first').addClass('firstChild');
		if($j('#applyNow img').length){
			$j('#applyNow img').hover(function(){
				$j(this).addClass('hover');
			},function(){
				$j(this).removeClass('hover');
			});
		}
		if($j('#makePayment').length){
			$j('#makePayment img').hover(function(){
				$j(this).addClass('hover');
			},function(){
				$j(this).removeClass('hover');
			});
		}
	}
// Related Products Hover
	if($j('#relatedProducts').length){
		$j('#relatedProducts li').addClass('enabled');
		$j('#relatedProducts li .photoHover img').each(function(){
			var imageSource = $j(this).attr('src');
			var imageSource2 = '/'+imageSource;
			$j(this).attr('src',imageSource2);
		});
		$j('#relatedProducts li').hover(function(){
			$j(this).find('.photoHover').hide();
			$j(this).find('.photoNormal').show();
			$j(this).find('h3 a').addClass('hover');
		},function(){
			$j(this).find('.photoHover').show();
			$j(this).find('.photoNormal').hide();
			$j(this).find('h3 a').removeClass('hover');
		});
		$j('#relatedProducts li').click(function(){
			window.location = $j(this).find('a').attr('href');
		});
	}
	if($j('.individualPage').length){
		if($j('.individualPage h1').text() == "Membership"){
			$j('.individualPage ul:first').addClass('twoCol');
		}
	}
// Locations
	if($j('#locations').length){
		var offset = 75;
		$j('#locations li:first').addClass('first');
		$j('#locations li').addClass('enabled');
		$j('#locations li:eq(0)').addClass('selected');
		$j('#locations .locationWrapper').addClass('pane');
		$j('#locations .locationWrapper').hide();
		$j('#locations .locationWrapper:eq(0)').show();
		$j('#locations #locList').css('height', $j('#locations .locationWrapper:eq(0)').height() + offset);
		$j('#locations h2').hover(function(){
			$j(this).addClass('hover');
		},function(){
			$j(this).removeClass('hover');
		});
		$j('#locations h2').click( function(){
			var holdThis = $j(this).parent();
			if( !holdThis.hasClass('selected') ){
				$j('#locations li').removeClass('selected');
				holdThis.addClass('selected');
				$j('#locations .locationWrapper').fadeOut(slideSpeed);
				$j('#locations #locList').animate({ height : holdThis.children('.locationWrapper').height() + offset }, slideSpeed, function(){
					holdThis.children('.locationWrapper').fadeIn(slideSpeed);
				});
			}
		});
	}
// Search Page
	if($j('#search').length){
		$j('#search li').live('click', function(){
			window.location = $j(this).find('a').attr('href');
		});
		$j('#search li').live('mouseover mouseout',function(event){
			if(event.type=="mouseover"){
				$j(this).addClass('hover');
			} else {
				$j(this).removeClass('hover');
			}
		});
	}
// New page for INMO
	$j('a.newPage').each( function(){
		this.target = "_blank";
	});

	// FancyBox popup on applications
	$j("a#ssnWhy").fancybox({
		'frameWidth': 300,
		'frameHeight': 190
	});
	
// Tell Me More, calculator, and online banking login popups provided by FancyBox 
	$j('#questions a, #ultraTopNav li a:contains("Online Banking"), #financialCalculators li a').addClass('iframe');
	
	$j("#questions a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 540,
		'frameHeight': 340,
		'overlayOpacity': 0.8,
		'padding':0
	});
	
	$j("#ultraTopNav li a.iframe").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 400,
		'frameHeight': 280,
		'overlayOpacity': 0.8,
		'padding': 0
	});

	$j("#financialCalculators li a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 650,
		'frameHeight': 400,
		'padding': 10,
		'overlayOpacity': 0.8
	}); 

});

function confirmAlert(url){
			jConfirm(alertText, "Confirm", function(r) {
				if( r ){
					window.open(url);
				} else {
					return false;
			}
		});
		return false;
}

function confirmAlert2(url){
	if (!confirmAlert(url)) 
		return false; 
}

function productTabs(){
	if( $j('#productTabs').length > 0 ){
		var offset = 40;
		$j('#productTabs dt').addClass('label');
		$j('#productTabs dt:eq(0)').addClass('selected');
		$j('#productTabs dd').addClass('pane');
		$j('#productTabs dd').css('position','absolute');
		$j('#productTabs dd').not("dd:eq(0)").hide();
		$j('#productTabs').css('height', $j('#productTabs dd:eq(0)').height() + offset);
		
		$j('#productTabs dt').click( function(){
			var holdThis = $j(this);
			if( !holdThis.hasClass('selected') ){
				$j('#productTabs dt').removeClass('selected');
				holdThis.addClass('selected');
				if(tabEffect == "slide"){
					$j('#productTabs dd').slideUp(slideSpeed);
					$j('#productTabs').animate({ height : holdThis.next().height() + offset }, slideSpeed, function(){
						holdThis.next().slideDown(slideSpeed);
						wrapperAdjustment();
					});
				}
				else{
					$j('#productTabs dd').fadeOut(slideSpeed);
					$j('#productTabs').animate({ height : holdThis.next().height() + offset }, slideSpeed, function(){
						holdThis.next().fadeIn(slideSpeed);
						wrapperAdjustment();
					});
				}
			}
		});
	}
}
