var $j=jQuery.noConflict();
var alertText = "Please be advised that you are leaving First National Banking Company's website. This link is provided as a courtesy.  First National Banking Company does not endorse or control the content of third party websites.";
var customFolder = "fnbc";
var slideSpeed = 500;
var tabEffect = "fade";	//slide, fade
var url = window.location.pathname; 

$j(document).ready( function() {

	productTabs();

	$j(".confirm").click( function() {						   
			if (!confirmAlert($j(this).attr('href'))){
				return false;			
			}
		});
		
// new page for INMO
	$j('a.newPage').each( function(){
		this.target = "_blank";
	});

// Start of Fancybox jQuery
	
	// fancybox popup on apps
	$j("a#ssnWhy").fancybox({
		'frameWidth': 300,
		'frameHeight': 190
	});
	
	$j('#tellMe a, #downstreamObl a, #financialCalculators li a').addClass('iframe');
	
	$j("#tellMe a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 540,
		'frameHeight': 420,
		'overlayOpacity': 0.8
	});
	
	$j("#downstreamObl a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 540,
		'frameHeight': 35,
		'overlayOpacity': 0.8
	});

	$j("#financialCalculators li a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 650,
		'frameHeight': 394,
		'padding': 10,
		'overlayOpacity': 0.8
	}); 
	
// End of Fancybox jQuery

//	Overlabel
	var labelFor = $j('#obLogin form label[for]');
	var inputFor = $j('#obLogin form input').attr('id');
	if (labelFor !== inputFor) {
		labelFor.addClass('overLabel');
		$j('#obLogin input').focus(function(){
			$j('#obLogin label.overLabel').css({
				'text-indent': '-9999px'
			});
		});
		$j('#obLogin input').blur(function(){
			$j('#obLogin label.overLabel').css({
				'text-indent': '0'
			});
		});	
	}

// add id to body
	$j(function(){
		if ($j('#primaryNav li a').hasClass("inPath")) {
			var primary = $j('#primaryNav li a.inPath').text().replace(/ /g,'');
			var secondary = $j('#leftNav li.inPath h2 a').text().replace(/ /g,'');
			$j('body').attr("id",primary);
			$j('body #wrapper').addClass(secondary);
		}
	});
	
//  Clickable Container	
	$j("#bizMonth, #homeFeaturedProducts ul li, div#productCategory ul > li, #search li").live("click", function(){
		window.location = $j(this).find("a").attr("href"); return false;
	});

//	BizMonth Cursor Pointer

	$j('#bizMonth').hover(function(){
		$j(this).css('cursor', 'pointer');
	}, function(){
		$j(this).css('cursor', 'auto');
	});

//	Quick Links Homepage - slideDown	
	$j('body#home #innerquickLinks ul').css('display', 'none');
	$j('body#home #innerquickLinks p').toggle(function() {
		$j('body#home #innerquickLinks p').css('cursor', 'pointer');
		$(this).addClass('active');
		$j('body#home #innerquickLinks ul').slideDown('slow');
	}, function() {
		$j('body#home #innerquickLinks ul').slideUp('slow', 
				function() {
					$j('body#home #innerquickLinks p').removeClass('active');	
				}
		);
	});

//	Home Featured Products
	$j('#homeFeaturedProducts ul li').mouseenter(function(){
		$j(this).css('cursor', 'pointer');
		$j('div.hidden', this).fadeIn(500);
		$j('div.shown', this).fadeOut(500);
	});
	$j('#homeFeaturedProducts ul li').mouseleave(function(){
		$j(this).css('cursor', 'default');
		$j('div.hidden', this).fadeOut(500);
		$j('div.shown', this).fadeIn(500);
	});
		
//	Downstream Online Banking
	$j('div#downstreamObl').hover(function(){
		$j(this).css('cursor', 'pointer');
		$j('a', this).css({
			color: '#971C1F',
			backgroundPosition: '26px 6px'
		});
		$j('p', this).css({
			backgroundPosition: '112px -18px'
		});
	
	}, function(){
		$j(this).css('cursor', 'auto');
		$j('a', this).css({
			color: '#947531',
			backgroundPosition: '26px -28px'
		});
		$j('p', this).css({
			backgroundPosition: '112px 2px'
		});

	});

//	Category Pages & Search Pages
	$j('div#productCategory ul li').not('#fdic a.confirm img, #eh a.confirm img').hover(function(){
		$j(this).css('cursor', 'pointer');
		$j('h3 a', this).css('color', '#971B1E');
		$j('img', this).css({
			borderRight: '1px solid #971B1E',
			borderLeft: '1px solid #971B1E',
			borderTop: '1px solid #971B1E'
		});
		$j('h4 a', this).css('background-position', '0 -17px');
	}, function(){
		$j('h3 a', this).css('color', '#A1854A');
		$j('img', this).css({
			borderRight: '1px solid #DDAD2C',
			borderLeft: '1px solid #DDAD2C',
			borderTop: '1px solid #DDAD2C'
		});
		$j('h4 a', this).css('background-position', '0 0');
	});

	// $j('div#search ul li').hover(function(){
	// 	$j(this).css('cursor', 'pointer');
	// 	$j('h3 a', this).css('color', '#971B1E');
	// 	$j('h4 a', this).css('background-position', '0 -17px');
	// }, function(){
	// 	$j('h3 a', this).css('color', '#A1854A');
	// 	$j('h4 a', this).css('background-position', '0 0');
	// });
	
	// new search results rollover
	$j("div#search ul li").live("mouseover mouseout", function(event){
		var searchA = $j(this).find('h2 a');
		if (event.type == 'mouseover') {
			searchA.css({color : "#971B1E", textDecoration : "underline"});
		} else {
			searchA.css({color : "#A1854A", textDecoration : "none"});
		}
	});
	
//	For Individual Pages
	if( $j('#mainContent img.individualImage').length > 0 ){ 
		$j('div.individualPage').css({
			float: 'left',
			display: 'inline',
			width: '42em', 
			padding: '0'
		});
	}
	
//	For Locations Pages
	if( $j('#mainContent #map').length > 0 ){ 
		$j('#locations').css({
			float: 'left',
			display: 'inline',
			width: '30em', 
			padding: '0'
		});
	}

	$j('#locations ul#locList>li>ul').hide();
	$j('#locations ul#locList>li>h2').click(function () {
		//$j(this).addClass('active');
		var thisLocation = $j(this).next("ul");
		$j('#locations ul#locList>li>ul>li:nth-child(even)').addClass("even");
		if (thisLocation.is(":hidden")) {
			$j(this).addClass("open");
			thisLocation.slideDown("slow");
		} else {
			//$j(this).addClass('active');
			thisLocation.slideUp("fast");
			$j(this).removeClass("open");
		}
	});
	
//	homepage equal height columns
	var highestCol = Math.max($j('#innerWrapper').height(),$j('.individualPage').height());
	var highestCol = Math.max($j('#innerWrapper').height(),$j('body#Personal #mainContent').height());	
	if ( !(url.indexOf("/personal/checking/passport-club-checking.html") != -1) ) {
		$j('.individualPage, body#Personal #mainContent').height(highestCol);
	}
}); // END doc ready

Cufon.set("selector", jQuery);
Cufon.replace("#homeFeaturedProducts ul li h2, #quickLinks h2, div#bizMonth h2, #downstreamObl a, body#home #header #headerBar h4#oblTitle, #foreclosures h3, #classifiedAds h3", { 
	fontFamily: 'Adobe Caslon Pro',
	separate: "words", 
	hover: true	 
});

Cufon.replace("#catBreadcrumb", { 
	fontFamily: 'Bickham Script Pro',
	separate: "words", 
	hover: true	 
});

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);									 
					});
				}
			}
		});
	}
}