var $j=jQuery.noConflict();
var alertText = "Please be advised that you are leaving Piedmont Community Bank's website. This link is provided as a courtesy. Piedmont Community Bank does not endorse or control the content of third party websites.";
var customFolder = "piedmontcommunitybank";
var slideSpeed = 500;
var tabEffect = "fade";	// slide, fade
// add class if js is loaded
$j('html').addClass('js'); 

$j(document).ready( function() {
							 
	homeFeaturedProducts();
	mainNav();
	categoryBoxes();
	productTabs();

	$j(".confirm").click( function() {						   
			if (!confirmAlert($j(this).attr('href'))){
				return false;			
			}
		}); 	
// write body class noFeatured for Personal Savings and Services category pages
if (/\/personal\/savings/.test(window.location) || /\/personal\/checking/.test(window.location) || /\/services/.test(window.location)) {
	$j('body').addClass("noFeatured");
};

// TEMPORARILY add missing branch images in
if ($j('#locList').length){
	$j('#locList li:eq(0) img').attr('src','/custom/piedmontcommunitybank/branch/branch-bass.jpg')
	$j('#locList li:eq(1) img').attr('src','/custom/piedmontcommunitybank/branch/branch-gray.jpg')
	$j('#locList li:eq(2) img').attr('src','/custom/piedmontcommunitybank/branch/branch-real-gray.jpg');
};

// new page for INMO
	$j('a.newPage').each( function(){
		this.target = "_blank";
	});

// fancybox popup on apps
	$j("a#ssnWhy").fancybox({
		'frameWidth': 300,
		'frameHeight': 190
	});
	
// Tell Me More - SAF - Calculators - OBL Popup provided by FancyBox 
	$j('#tellMeMoreButton a').addClass('iframe');
	
	$j("#tellMeMoreButton a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 520,
		'frameHeight': 340,
		'overlayOpacity': 0.8
	});
	
	$j('#shareButton a').addClass('iframe');
	
	$j("#shareButton a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 570,
		'frameHeight': 520,
		'overlayOpacity': 0.8
	});
	
	//stand alone online banking link
	$j('#downstreamObl a').addClass('iframe');
	
	$j("#downstreamObl a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 230,
		'frameHeight': 210,
		'overlayOpacity': 0.8
	});
	// add target parent for popup links
	$j('#obNav li a').attr('target','_parent');
	
	$j('#financialCalculators li a').addClass('iframe');

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

// animate left menu
if ($j("#leftNav li ul.nthTier-2").length > 0){
	  // animate sub menu
	  $j("#leftNav li ul.nthTier-2").hide().delay(300).slideDown(400);
};
	
// category page boxes
if ($j('#productCategory li').length > 0){
	$j('#productCategory li').not('#productCategory li li')
		.borderImage('url("../custom/piedmontcommunitybank/image/cat-shadow.png") 2 5 5 2');
};
if ($j('#catDescription').length > 0){
	$j('#catDescription').borderImage('url("../custom/piedmontcommunitybank/image/cat-shadow.png") 2 5 5 2');
};
// add 'featured product'
$j('#productCategory li.firstChild div.productContent').append('<span id="featuredProduct">featured product</span>');
// add 'overview' to catBanner
$j('#catBanner h1').append(' Overview');

// product page container
if ($j('#productContainer').length > 0){	
	$j('#productContainer').borderImage('url("../../custom/piedmontcommunitybank/image/cat-shadow.png") 2 5 5 2');
};
	// questions button text
	$j('#tellMeMoreButton a img').replaceWith('<span id="questionsText">QUESTIONS?</span>')

// product page container
if ($j('#mainContent .individualPage').length > 0){	
	$j('#mainContent .individualPage').borderImage('url("../../custom/piedmontcommunitybank/image/cat-shadow.png") 2 5 5 2');
};

// locations containers
if ($j('#locations').length > 0){	
	$j('#locations .locationBox').borderImage('url("../../custom/piedmontcommunitybank/image/cat-shadow.png") 2 5 5 2');
	$j('#locList .vcard').borderImage('url("../../custom/piedmontcommunitybank/image/cat-shadow.png") 2 5 5 2');

};

}); // END doc ready

// homeFeatured
function homeFeaturedProducts (){
if ( $j("#homeFeaturedProducts").length > 0){	
	 $j("#homeFeaturedProducts li a").bigTarget();
	 
	 $j("#homeFeaturedProducts li")
		.mouseover(function() {	
			$j(this).stop().animate( {
				backgroundPosition: '0 -308px'
				}, {queue:true, duration: 300});
			$j("h3",this).stop().animate({color: "#670001"}, 200);
		})
		
		.mouseout(function() {
			$j(this).stop().animate( {
					backgroundPosition: '0 0'
					}, 450);
			$j("h3",this).stop().animate({color: "#333"}, 300);
		});
	
	};
};
// end homeFeatured

// main nav
function mainNav (){
	$j('#primaryNav li a').mouseover(function() {
	
	if (!$j(this).hasClass('inPath')){
		$j(this).stop().css('backgroundPosition','0 -92px')				
		.animate( {
			backgroundPosition: '0 -95px',
			color: "#BA9D16"
			}, 350)
		}
	
	});
	
	$j('#primaryNav li a').mouseout(function() {
	
	if (!$j(this).hasClass('inPath')){
		$j(this).stop().css('backgroundPosition','0 -47px')
		.animate( {
			backgroundPosition: '0 -44px',
			color: "#650915"
			}, 300);
		}
	
	});

};// end mainNav

// categoryBoxes
function categoryBoxes (){
if ( $j("#productCategory li").length > 0){	
	 $j("#productCategory li a").bigTarget();
	 
	 $j("#productCategory li div.productContent")
	 	.css('cursor','pointer')
		.mouseover(function() {	
			$j(this).stop().animate( {
				backgroundPosition: '0 -490px'
				}, {queue:true, duration: 300});
			$j("h3 a",this).stop().animate({color: "#670001"}, 200);
		})
		
		.mouseout(function() {
			$j(this).stop().animate( {
					backgroundPosition: '0 0'
					}, 450);
			$j("h3 a",this).stop().animate({color: "#333"}, 300);
		});
	
	};
};
// end categoryBoxes

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