var $j=jQuery.noConflict();
var alertText = "Please be advised that you are leaving Worthington Federal Bank's website. This link is provided as a courtesy. Worthington Federal Bank does not endorse or control the content of third party websites.";
var customFolder = "worthingtonfederalbank";
var slideSpeed = 500;
var tabEffect = "fade";
$j(window).load(function(){
	if($j('#homeBanner img').length){
		$j('#flashBanner #flashNav').show();
	}
});
$j(document).ready( function() {

	productTabs();

	$j(".confirm").click( function() {						   
		if (!confirmAlert($j(this).attr('href'))){
			return false;			
		}
	});
	//	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': '-9999px'
				});
			});
			$j('.overLabelWrapper input.overLabel').blur(function(){
				if($j(this).val() == ''){
					$j(this).prev().css({
						'text-indent': '0'
					});
				}
			});	
		}
	}
	if($j('#primaryNav').length){
		Cufon.replace("#primaryNav li a");
	}
	if($j('#obLogin').length){
		Cufon.replace('#obLogin h2');
	}
	if($j('#homeRates').length){
		Cufon.replace('#homeRates h2');
		$j('#ratesTop').hover(function(){
			$j(this).css('cursor','pointer').find('a').addClass('hover');
		},function(){
			$j(this).css('cursor','default').find('a').removeClass('hover');
		});
		$j('#ratesTop').click(function(){
			window.location = $j(this).find('a').attr('href');
		});
	}
	if($j('#homeFeaturedProducts').length){
		Cufon.replace('#homeFeaturedProducts h2');
		Cufon.replace('#homeFeaturedProducts .featured h2');
		Cufon.replace('#homeFeaturedProducts a h2');
		$j('#investorRelations').hover(function(){
			$j(this).addClass('hover');
			$j(this).find('a').addClass('hover');
		},function(){
			$j(this).removeClass('hover');
			$j(this).find('a').removeClass('hover');
		});
		$j('#investorRelations').click(function(){
			window.location = $j(this).find('a').attr('href');
		});
		$j('#communityNews li').hover(function(){
			$j(this).addClass('hover');
		},function(){
			$j(this).removeClass('hover');
		});
		$j('#communityNews li').click(function(){
			window.location = $j(this).find('a').attr('href');
		})
	}
	if($j('#catContent').length){
		Cufon.replace('#catBreadcrumb li a');
	}
	if($j('#productCategory').length){
		$j('#productCategory li').hover(function(){
			$j(this).addClass('hover');
		},function(){
			$j(this).removeClass('hover');
		});
		$j('#productCategory li').click(function(){
			window.location = $j(this).find('a').attr('href');
		});
	}
	if($j('#productPage').length){
		Cufon.replace('#productPage h1');
		$j('#questions').hover(function(){
			$j(this).find('img').addClass('hover');
		},function(){
			$j(this).find('img').removeClass('hover');
		});
		if($j('#applyNow').is(':empty')){
			$j('#applyNow').hide();
		}
		$j('#applyNow').hover(function(){
			$j(this).find('img').addClass('hover');
		},function(){
			$j(this).find('img').removeClass('hover');
		});	
	}
	if($j('#newApplication').length){
		Cufon.replace('#newApplication h1');
	}
	if($j('.individualPage').length){
		Cufon.replace('.individualPage h1');
	}
	if($j('#catContent').length){
		Cufon.replace('#catContent h1');
	}
	if($j('#leftNav').length){
		var height = $j('#leftNav').height();
		var repeatHeight = height - 45;
		if(repeatHeight > 0){
			$j('#leftNavRepeat').css({height:repeatHeight});
		}
	}
	if($j('.openAccount').length){
		Cufon.replace('.featuredWrapper div h3');
		$j('.featuredWrapper div').click(function(){
			window.location = $j(this).find('a').attr('href');
		});
	}
	if($j('#obNav').length){
		$j('#obNav li a').not(':first').attr('target','_blank');
		$j('#obNav li a:first').attr('target','_parent');
	}
	if($j('#contactUs').length){
		$j('#contactUs #contactBlurb h2:eq(1)').addClass('sendFiles');
		$j("#contactUs #contactBlurb a:last").addClass('phone');
	}
	
	// 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, #quickLinks a:contains("Lost or Stolen Card"), #contactBlurb a.phone').addClass('iframe');
	
	$j("#questions a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 552,
		'frameHeight': 414,
		'overlayOpacity': 0.8,
		'padding':0
	});
	$j("#contactBlurb a.iframe").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 352,
		'frameHeight': 354,
		'overlayOpacity': 0.8,
		'padding':0
	});
	
	$j("#ultraTopNav li a.iframe").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 322,
		'frameHeight': 254,
		'overlayOpacity': 0.8
	});
	$j("#quickLinks li a.iframe").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 322,
		'frameHeight': 254,
		'overlayOpacity': 0.8
	});

	$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);									 
					});
				}
				else{
					$j('#productTabs dd').fadeOut(slideSpeed);
					$j('#productTabs').animate({ height : holdThis.next().height() + offset }, slideSpeed, function(){
						holdThis.next().fadeIn(slideSpeed);									 
					});
				}
			}
		});
	}
}
