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

jQuery(document).ready(function($j) {
							 
	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";
	});

// 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, #questionsButton a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 520,
		'frameHeight': 355,
		'overlayOpacity': 0.8
	});
	
	$j('#shareButton a').addClass('iframe');
	
	$j("#shareButton a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 570,
		'frameHeight': 520,
		'overlayOpacity': 0.8
	});
	
	// online banking link in ultratopnav
	$j('#ultraTopNav li a:contains("Online Banking Login")')
		.addClass('iframe')
		.before('<span class="oblLock" />');
	
	$j("#ultraTopNav li a.iframe").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 200,
		'frameHeight': 220,
		'overlayOpacity': 0.8
	});
	
	$j('#financialCalculators li a').addClass('iframe');

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

// set Cufon
Cufon.set("selector", jQuery);
Cufon.replace("#homeFeaturedProducts li h2", { fontFamily: 'Copperplate', separate: 'words', hover: true });
Cufon.replace("#featuredProduct h1, div.productContent h3, div.productContent h4, body.popup form h4.title, #productSummary h1, h1.pageHead, #thankYou h1, #quickLinks h2, h4.title, fieldset#newApplication div#introduction h1, #currentOpportunities", { fontFamily: 'Rockwell', separate: 'words', hover: true });

// make containers clickable 
	$j("li.categoryListItem, #homeFeaturedProducts li, #search li").live('click', function() { 
		window.location=$j(this).find("a").attr("href"); return false;
	});
	
// category and search page li hover effects
	$j("#secondaryProducts li.categoryListItem, #search li").css({cursor: "pointer"}).hover(
		function() {								
			$j(this).addClass('hover');
		},
		function() {
			$j(this).removeClass('hover');
		}
	);
// home page featured products hover effects
	$j("#homeFeaturedProducts li div.featureHover").css({'display':'block','opacity':'0'});
	$j("#homeFeaturedProducts li").css({cursor: "pointer"}).mouseover(
		function() {
			$j('div.featureHover',this).stop().animate({'opacity':.2}, 300);
			$j('h3 a',this).stop().css({'backgroundPosition':'left bottom'});
		}
	);	
	$j("#homeFeaturedProducts li").mouseout(
		function() {
			$j('div.featureHover',this).stop().animate({'opacity':0}, 500);
			$j('h3 a',this).stop().css({'backgroundPosition':'0 6px'});
		}
	);

// if left nav breaks to a second line then adjust padding and height
$j('#leftNav li h2 a').each(function() {
	if ($j(this).text().length > 16) {
		$j(this).parent().addClass('longTitle');
	}
});

// online banking overlabel
$j("label.overlabel").overlabel(); 

// add target _parent to online banking links
if ($j('#obNav').length){
	$j('#obNav li a').attr('target','_parent');
};

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