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

$j(document).ready( function() {
	productTabs();
	$j(".confirm").click( function() {
		if (!confirmAlert($j(this).attr('href'))){
			return false;
		}
	});
	
	var windowHeight = $j(window).height() - 210;
	$j('#wrapper').css('min-height',windowHeight + 'px');
	$j(window).resize(function(){
		var windowHeight = $j(window).height() - 210;
		$j('#wrapper').css('min-height',windowHeight + 'px');
	});
// Online Banking 
	if ($j('#obLogin').length > 0) {
		var defaultText = "User ID";
		$j('#obLogin input#ttin').val(defaultText);
		$j('#obLogin input#ttin').focus(function() {
			if($j(this).val() == defaultText) {
				$j(this).val("");
			}
		});
		$j('#obLogin input#ttin').blur(function() {
			if($j(this).val() == "") {
				$j(this).val(defaultText);
			}
		});
		$j('#obNav li.nthChild-1 a').attr('target','_blank');
	}
	if ($j('#onlinePopup').length > 0) {
		var defaultText = "User ID";
		$j('#onlinePopup input#ttin').val(defaultText);
		$j('#onlinePopup input#ttin').focus(function() {
			if($j(this).val() == defaultText) {
				$j(this).val("");
			}
		});
		$j('#onlinePopup input#ttin').blur(function() {
			if($j(this).val() == "") {
				$j(this).val(defaultText);
			}
		});
		$j('#obNav li a').attr('target','_top');
	}
// Quick Links
	if($j('#quickLinks').length > 0) {
		$j('#quickLinks a').addClass('enabled');
		$j('#quickLinks li').hover(
			function(){
				$j(this).addClass('over');
			}, function(){
				$j(this).removeClass('over');
			}
		);
		$j('#quickLinks li a:contains("Report a Lost or Stolen Card")').addClass('iframe');

		$j("#quickLinks li a.iframe").fancybox({
			'hideOnContentClick': false,
			'frameWidth': 550,
			'frameHeight': 180,
			'overlayOpacity': 0.8
		});
	}
// Home Page
	if($j('#featuredProduct').length > 0) {
		$j('#featuredProduct').click(function(){
			window.location=$j(this).find('a').attr('href');
		})
		$j('#featuredProduct').css('cursor','pointer');
		$j('#featuredProduct').hover(
			function(){
				$j(this).find('h4 a').css('background-position','left -33px');
				$j(this).find('h3').css('background-position','left -79px');
			},function(){
				$j(this).find('h4 a').css('background-position','left top');
				$j(this).find('h3').css('background-position','left top');
			}
		);
	}
// Category Page
	if($j('#productCategory').length > 0) {
		$j('#productCategory li:nth-child(3n)').addClass('lastChild');
		$j('#productCategory li').css('cursor','pointer');
		$j('#productCategory li').click(function(){
			window.location = $j(this).find('a').attr('href');
		});
		$j('#productCategory li').hover(
			function(){
				$j(this).find('.productContent').css('background-position','left bottom');
				$j(this).find('h4 a').css('background-position','left -21px');
			},function(){
				$j(this).find('.productContent').css('background-position','right bottom');
				$j(this).find('h4 a').css('background-position','left top');
			}
		);
		
	}
// Product Page
	if($j('#productTabs').length > 0) {
		$j('#productTabs dt:first').addClass('firstChild');
	}

// Search Results Page
	if($j('#searchResults').length > 0) {
		$j('#searchResults li').click(function(){
			window.location=$j(this).find('a').attr('href');
		})
		$j('#searchResults li').css('cursor','pointer');
		$j('#searchResults li').hover(
			function(){
				$j(this).find('h4 a').css('background-position','left -21px');
				$j(this).find('h3 a').css('color','#185E76');
			},function(){
				$j(this).find('h4 a').css('background-position','left top');
				$j(this).find('h3 a').css('color','#262219');
			}
		);
	}
// 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': 550,
		'frameHeight': 400,
		'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': 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': 550,
		'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
	}); 
	
// End of Fancybox jQuery

//Twitter Feed Stuff
	/*
	var theTwitterUsername = "sbtTweets";
    var statusUpdateURL = "https://www.sbtbanknow.com/custom/suburbanbanktrust/tal/getStatus.php";
	$j('#twitterFeed2').load(statusUpdateURL, {twitterUsername: theTwitterUsername});
	*/

// hide homepage noscript link
/*var flashLink = $j("body#homepage #mainContent > a"); 
flashLink.children().insertBefore(flashLink);  
flashLink.remove(); 
*/

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

/* add images for addPrintLink  */
/*$j('#logo a').after('<img src="/custom/' + customFolder + '/image/logo.png" alt="BANK NAME"/>');
$j('#footer #firstROI').after('<img class="froiLogo" src="/custom/' + customFolder + '/image/firstroi-logo.png" alt="First ROI"/>');*/

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

