var $j=jQuery.noConflict();
var alertText = "Please be advised that you are leaving Bank2's website. This link is provided as a courtesy. Bank2 does not endorse or control the content of third party websites.";
var customFolder = "bank2online";
var slideSpeed = 500;
var tabEffect = "fade";
$j(window).load(function(){
	if($j('#flashBanner img').length){
		$j('#flashBanner img').wrap('<a href="/personal/checking/great-rate-checking.html"/>');
	}
});
$j(document).ready( function() {
	if($j('#primaryNav').length){
		Cufon.replace('#primaryNav a',{
			textShadow: '1px 2px 4px #440B16'
		});
	}
	if($j('#obNav').length){
		$j('#obNav li a:contains("Demo")').attr('target','_blank');
	}
	if($j('#chatIcon').length){
		$j('#chatIcon a img').hover(function(){
			$j(this).css('top','-29px');
		},function(){
			$j(this).css('top','0');
		});
		
	}
	if($j('#homeLoans').length){
		Cufon.replace('#homeLoans .loanContent h3');
		$j('#loanWrapper').click(function(){
			window.location = $j(this).find('a').attr('href');
		});
		$j('#loanWrapper').addClass('enabled');
		$j('#loanWrapper').hover(function(){
			$j('#loanNormal').filter(':not(:animated)').fadeOut(250);
		},function(){
			$j('#loanNormal').filter(':not(:animated)').fadeIn(500);
		});
	}
	if($j('#productCategory').length){
		$j('#productCategory li:last').addClass('lastChild');
		$j('#productCategory li').click(function(){
			window.location = $j(this).find('a').attr('href');
		});
		$j('#productCategory li').hover(function(){
			$j(this).addClass('hover');
		},function(){
			$j(this).removeClass('hover');
		});
		$j('#productCategory li').each(function(){
			$j(this).append('<div class="clear"></div>');
		});
	}
	if($j('#leftNav').length){
		$j('#leftNav li li a').css('padding-left','5px');
		$j('#leftNav li li.inPath a').css('padding-left','13px');
		$j('#leftNav li li a').hover(
			function(){
				$j(this).stop().animate({paddingLeft: 13}, 250);
			}, function(){
				if($j(this).hasClass('inPath') == true) {
					return false;
				}
				else {
					$j(this).stop().animate({paddingLeft: 5}, 250);
				}
			}
		);
		sideArrow();
	}
	if($j('#content').length){
		Cufon.replace('#content #mainContent h1');
	}
	if($j('#productPage').length){
		productTabs();
		Cufon.replace('#productPage h1');
		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');
		});
		var leftHeight = $j('#productLeft').height();
		var rightHeight = $j('#productIntro').height();
		if(rightHeight > leftHeight){
			if($j('#applyNow').css('display') == 'none'){
				var height = rightHeight - 5;
				$j('#productPhoto').css({height:height});
			} else {
				var height = rightHeight - 9;
				$j('#productPhoto').css({height:height});
			}
			
		}
		if($j('#questions').length){
			$j('#questions').hover(function(){
				$j(this).find('img').addClass('hover');
			},function(){
				$j(this).find('img').removeClass('hover');
			});
		}
		if($j('#relatedProducts').length){
			$j('#relatedProducts li').click(function(){
				window.location = $j(this).find('a').attr('href');
			});
			$j('#relatedProducts li').hover(function(){
				$j(this).addClass('hover');
			},function(){
				$j(this).removeClass('hover');
			});
		}
		var url = window.location.toString();
		if(url.indexOf('second') > -1){
			$j('#productTabs dt:eq(1)').trigger('click');
		}
	}
	if($j('#validateForm').length){
		Cufon.replace('#validateForm h1',{
			textShadow: '1px 2px 4px #440B16'
		});
		Cufon.replace('#wrapper #validateForm h1');
	}
	if($j('#popupInner').length){
		Cufon.replace('#popupInner h1', {
			textShadow: '1px 2px 4px #440B16'
		});
	}
	if($j('#olbPopup').length){
		Cufon.replace('#olbPopup h1', {
			textShadow: '1px 2px 4px #440B16'
		});
	}
	if($j('.individualPage').length){
		Cufon.replace('.individualPage h1');
		if($j('.individualPage h1').text() == 'Chickasaw Nation') {
			$j('.individualPage img').addClass('noBorder');
		}
		if($j('#locations').length){
			$j('#locations .locList2 li').appendTo('.locList');
			$j('#locations .locList2').remove();
			$j('.locList li:eq(1)').addClass('middleColumn');
			$j('.locList li:eq(2)').addClass('rightColumn');
			$j('<li class="clear"></li>').appendTo('.locList');
			$j('.locList li:eq(0) .directions a').attr('target','_blank').attr('href','http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=909+S.+Meridian+Oklahoma+City,+OK+73108&sll=37.925699,-122.384647&sspn=0.008598,0.014269&ie=UTF8&hq=&hnear=909+S+Meridian+Ave,+Oklahoma+City,+Oklahoma,+73108&t=h&z=16');
			$j('.locList li:eq(1) .directions a').attr('target','_blank').attr('href','http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=1701+S.+Morgan+Road+Oklahoma+City,+OK+73128+&sll=35.456378,-97.601672&sspn=0.008879,0.014269&ie=UTF8&hq=&hnear=1701+S+Morgan+Rd,+Oklahoma+City,+Canadian,+Oklahoma+73128&t=h&z=16');
		}
	}
	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');
			}
		});
		$j('#ultraTopNav li.firstChild').hide();
	}
	$j('a:contains("Switch Kit")').attr('target','_blank');
	if($j('#aboutUs').length){
		$j('#aboutUs #blurbPhoto img:first').attr('usemap','#splash_final_r4_c2Map').attr('id','splash_final_r4_c2');
	}



	$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'
					});
				}
			});	
		}
	}
	// New page for INMO
	$j('a.newPage').each( function(){
		this.target = "_blank";
	});

	// FancyBox popup on applications
	if($j('#ssnWhy').length){
		$j("a#ssnWhy").fancybox({
			'frameWidth': 300,
			'frameHeight': 190
		});
	}
	
	
	// Tell Me More, calculator, and online banking login popups provided by FancyBox 
	$j('#questions a, #oblButton a, #ultraTopNav li a:contains("Online Banking"), #financialCalculators li a, #mortCalc a').addClass('iframe');
	if($j('#financialCalculators').length){
		$j('#financialCalculators li:last a').removeClass('iframe').attr('target','_blank');
	}
	if($j('#questions').length){
		$j("#questions a").fancybox({
			'hideOnContentClick': false,
			'frameWidth': 509,
			'frameHeight': 330,
			'overlayOpacity': 0.9,
			'padding':4
		});
	}
	if($j('#oblButton').length){
		$j("#oblButton a").fancybox({
			'hideOnContentClick': false,
			'frameWidth': 310,
			'frameHeight': 275,
			'overlayOpacity': 0.9,
			'padding':4
		});
	}
	if($j('ultraTopNav').length){
		$j("#ultraTopNav li a.iframe").fancybox({
			'hideOnContentClick': false,
			'frameWidth': 308,
			'frameHeight': 234,
			'overlayOpacity': 0.9,
			'padding':4
		});
	}
	if($j('#financialCalculators').length){
		$j("#financialCalculators li a.iframe").fancybox({
			'hideOnContentClick': false,
			'frameWidth': 650,
			'frameHeight': 405,
			'padding': 4,
			'overlayOpacity': 0.9
		});
	}
	if($j('#mortCalc').length){
		$j("#mortCalc a.iframe").fancybox({
			'hideOnContentClick': false,
			'frameWidth': 650,
			'frameHeight': 405,
			'padding': 4,
			'overlayOpacity': 0.9
		});
	}
});
function sideArrow(){
	$j('#leftNav li h2 a').each(function(){
		if($j(this).hasClass('inPath')){
			var secondTier = $j(this).parent().next().html();
			if (secondTier == null){
				$j(this).attr('id','sideArrow');
			}
		}
	});
}
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('#productDetails dt:first').addClass('firstChild');
		$j('#productTabs dt:eq(0)').addClass('selected').css('background-position','right 24px');
		$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($j('#productTabs dt.firstChild').hasClass('selected')){
					$j('#productTabs dt.firstChild').css('background-position','right 23px');
				} else {
					$j('#productTabs dt.firstChild').css('background-position','right -27px');
				}
				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);
					});
				}
			}
		});
	}
}
