var $j=jQuery.noConflict();
var alertText = "Please be advised that you are leaving Princeville State Bank's website. This link is provided as a courtesy.  Princeville State Bank does not endorse or control the content of third party websites.";
var customFolder = "princevillestatebank";
var slideSpeed = 500;
var tabEffect = "fade";	//slide, fade

$j(document).ready( function() {
/*	targetBlank(); */
	productTabs();

	$j(".confirm").click( function() {						   
			if (!confirmAlert($j(this).attr('href'))){
				return false;			
			}
	}); 
	
	
	
/* About Us Title */
	if ($j('#aboutUs').length > 0) {
		$j('#aboutUs h2:first-child').addClass('firstChild');
	}
/* Investment Services */
	if ($j('#investmentServices').length > 0) {
		$j('#investmentServices h2:first').addClass('firstChild');
	}
/* Newsletters */
	if ($j('#newsletters').length > 0) {
		$j('#newsletters h2:first').addClass('firstChild');
	}
// Category Related Products Hover
	$j('#productCategory li .photoHover img').each(function(){
		var imageSource = $j(this).attr('src');
		var imageSource2 = '/'+imageSource;
		$j(this).attr('src',imageSource2);
	});
	$j('#productCategory li.odd')
		.mouseover(function(){
			$j(this).find('h3 a').css('color','#114B8C');
			$j(this).find('h4 a').css('color','#114B8C');
			$j(this).find('h4 a').css('background','transparent url(/custom/princevillestatebank/image/related-product-learn-more.png) no-repeat right -17px');
			$j(this).find('.photoNormal').css('display','none');
			$j(this).find('.photoHover').css('display','block');
			$j(this).css('background-color','#ffffff');
		})
		.mouseout(function(){
			$j(this).find('h3 a').css('color','#66001F');
			$j(this).find('h4 a').css('color','#666666');
			$j(this).find('h4 a').css('background','transparent url(/custom/princevillestatebank/image/related-product-learn-more.png) no-repeat right 5px');
			$j(this).find('.photoNormal').css('display','block');
			$j(this).find('.photoHover').css('display','none');
			$j(this).css('background-color','transparent');
		})
	$j('#productCategory li.even')
		.mouseover(function(){
			$j(this).find('h3 a').css('color','#114B8C');
			$j(this).find('h4 a').css('color','#114B8C');
			$j(this).find('h4 a').css('background','transparent url(/custom/princevillestatebank/image/related-product-learn-more.png) no-repeat right -17px');
			$j(this).find('.photoNormal').css('display','none');
			$j(this).find('.photoHover').css('display','block');
			$j(this).css('background-color','#ffffff');
		})
		.mouseout(function(){
			$j(this).find('h3 a').css('color','#66001F');
			$j(this).find('h4 a').css('color','#666666');
			$j(this).find('h4 a').css('background','transparent url(/custom/princevillestatebank/image/related-product-learn-more.png) no-repeat right 5px');
			$j(this).find('.photoNormal').css('display','block');
			$j(this).find('.photoHover').css('display','none');
			$j(this).css('background-color','transparent');
		})
	if ($j('#productCategory').length > 0) {
		$j('#mainContentBottom').css('margin-top','-3px');
		$j('#productCategory li.lastChild')
			.mouseover(function(){
				$j('#mainContentBottom').css('background','transparent url(/custom/princevillestatebank/image/main-content-bg-bottom.png) no-repeat left -16px');
			})
			.mouseout(function(){
				$j('#mainContentBottom').css('background','transparent url(/custom/princevillestatebank/image/main-content-bg-bottom.png) no-repeat left top');
			})
	}


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

// fancybox popup on apps
	$j("a#ssnWhy").fancybox({
		'frameWidth': 300,
		'frameHeight': 190
	});
// locations
	$j('#locList tr.tableHead th:first').addClass('firstCell');
	$j('#locList tr td:first').addClass('firstCell');
	$j('#locList li:nth-child(2)').find('tr.tableHead th:first').addClass('firstCell');
	$j('#locList li:nth-child(2)').find('tr td:first').addClass('firstCell');
//This adds iframe class inorder for forms to work
	$j('#tellMeMoreButton a').addClass('iframe');
	
	$j("#tellMeMoreButton a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 550,
		'frameHeight': 430,
		'overlayOpacity': 0.8
	});
	
	$j('#tellMeMoreTop a').addClass('iframe');
	
	$j("#tellMeMoreTop a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 550,
		'frameHeight': 430,
		'overlayOpacity': 0.8
	});
	
	$j('#shareButton a').addClass('iframe');
	
	$j("#shareButton a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 550,
		'frameHeight': 500,
		'overlayOpacity': 0.8
	});
	
/*	stand alone online banking link
	$j('#downstreamObl a').addClass('iframe');
	
	$j("#downstreamObl a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 570,
		'frameHeight': 520,
		'overlayOpacity': 0.8
	});*/
	
	
	// online banking link in ultratopnav
	$j('#ultraTopNav li a:contains("Online Banking")').addClass('iframe');
	
	$j("#ultraTopNav li a.iframe").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 400,
		'frameHeight': 280,
		'overlayOpacity': 0.8
	});
	
	$j('#financialCalculators li a').addClass('iframe');

	$j("#financialCalculators li a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 650,
		'frameHeight': 400,
		'overlayOpacity': 0.8
	});
	$j('#quickLinks li.nthChild-2 a').addClass('iframe');
	$j('#quickLinks li.nthChild-2 a').fancybox({
		'hideOnContentClick': false,
		'frameWidth': 450,
		'frameHeight': 200,
		'overlayOpacity': 0.8
	});
}); // END doc ready
  

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 targetBlank(){
	$j('a').each( function(){
		var url = $j(this).attr('href');
		if( url.indexOf('fidelityhomestead') == -1 && url != '#' ){
			$j(this).attr('target', '_blank');
		}
	});
}
*/



/* Product Details */
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:eq(1), #productTabs dd:eq(2)').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);									 
					});
				}
			}
		});
	}
}

/*
addPrintLink function by Roger Johansson, www.456bereastreet.com
*/

var addPrintLink = {
	init:function(sTargetEl,sLinkText) {
		if (!document.getElementById || !document.createTextNode) {return;} // Check for DOM support
		if (!document.getElementById(sTargetEl)) {return;} // Check that the target element actually exists
		if (!window.print) {return;} // Check that the browser supports window.print
		var oTarget = document.getElementById(sTargetEl);
		var oLink = document.createElement('a');
		oLink.id = 'printLink'; // Give the link an id to allow styling
		oLink.href = '#'; // Make the link focusable for keyboard users
		oLink.appendChild(document.createTextNode(sLinkText));
		oLink.onclick = function() {window.print(); return false;} // Return false prevents the browser from following the link and jumping to the top of the page after printing
		oTarget.appendChild(oLink);
	},
	
/*
addEvent function included here for portability. Replace with your own addEvent function if you use one.
*/
/* addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html */
	addEvent:function(obj, type, fn) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() {obj["e"+type+fn](window.event);}
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	}
};
addPrintLink.addEvent(window, 'load', function(){addPrintLink.init('printThisPage','Print this page');});
