var $j=jQuery.noConflict();
var alertText = "Please be advised that you are leaving Texas First Bank's website. This link is provided as a courtesy. Texas First Bank does not endorse or control the content of third party websites.";
var emailAlertText = "Please note: Texas First Bank advises users to not send any confidential, non-public information via email for their protection, as email is not secure.";
var customFolder = "texasfirstbank";
var slideSpeed = 500;
var tabEffect = "fade";	//slide, fade

// cufon
Cufon.replace('#homeFeatured li h2, .productContent h3, #primaryNav a, #mainContent h1, #search h3, fieldset#newApplication div#introduction h1'), { hover: true }; 

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

	productTabs();

	$j(".confirm").click( function() {						   
			if (!confirmAlert($j(this).attr('href'))){
				return false;			
			}
		});
	$j(".emailConfirm").click( function() {						   
			if (!emailConfirmAlert($j(this).attr('href'))){
				return false;			
			}
		});
// make containers clickable 
	$j('#productCategory ul > li, #homeFeatured li, #search ul > li').click(function(){
		window.location=$j(this).find('a').attr('href');
	});
// easing
jQuery.extend( jQuery.easing,
{
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	}
});
	
// homeFeatured rollovers
    $j("#homeFeatured li").css("cursor","pointer")
    	.hover(function(){
			$j(this).css('backgroundPosition','bottom center');
			$j('img',this).fadeOut(200);
			$j('h2',this).stop().animate({marginBottom:'135px'}, {
				duration: 250, 
				easing: 'easeOutBack'
			});
			$j('.over',this).stop().animate({bottom:'-7px'}, 230);
       	}, function(){
			$j(this).css('backgroundPosition','0 0');
			$j('img',this).fadeIn(350);
			$j('h2',this).stop().animate({marginBottom:'0'}, {
				duration: 350,
				easing: 'easeOutBack'
			});
			$j('.over',this).stop().animate({bottom:'-157px'}, 250);
       	}
    );
		
// productCategory rollovers
    $j("#productCategory ul li").not("#productCategory ul li li").css("cursor","pointer")
    	.hover(function(){
			$j('h3',this).stop().addClass("h3Hover");
       		Cufon('.productContent h3.h3Hover', {color:'#DA283E'});
			$j('h4 a',this).stop().css('backgroundColor','#DA283E');
       	}, function(){
       		Cufon('.productContent h3.h3Hover', {color:'#333'});
			$j('h3',this).stop().removeClass("h3Hover");
			$j('h4 a',this).stop().css('backgroundColor','#002D86');
       	}
    );

// search results rollovers
    $j("#search ul li").not("#search ul li li").css("cursor","pointer")
    	.hover(function(){
			$j('h3',this).stop().addClass("h3Hover");
       		Cufon('h3.h3Hover', {color:'#DA283E'});
			$j('h4 a',this).stop().css('backgroundColor','#DA283E');
       	}, function(){
       		Cufon('h3.h3Hover', {color:'#333'});
			$j('h3',this).stop().removeClass("h3Hover");
			$j('h4 a',this).stop().css('backgroundColor','#002D86');
       	}
    );

//over label
if($j('.overLabelWrapper').length){
	if($j('#user_id').val() !=""){
		$j('#user_id').val(""); 
	}
	if($j('#password').val() !=""){
		$j('#password').val(""); 
	}
	var labelFor = $j('.overLabelWrapper label[for]');
	var inputFor = $j('.overLabelWrapper input').attr('id');
	if (labelFor !== inputFor) {
		labelFor.addClass('overLabel');
		$j('.overLabelWrapper input[type=text]').addClass('overLabel');
		$j('.overLabelWrapper input[type=password]').addClass('overLabel');
		$j('.overLabelWrapper input.overLabel').focus(function(){
			$j(this).prev().css({
				'text-indent': '-9999px'
			});
		});
		$j('.overLabelWrapper input.overLabel').blur(function(){
			if($j(this).val() == ''){
				$j(this).prev().css({
					'text-indent': '0'
				});
			}
		});	
	}
}

// locations
if($j("#locations").length > 0) {
	var locHeader = $j("#locations li h2");
    $j("#locations .locationInfo").hide();
	$j("#locations li:first").css({borderTop: "1px solid #ccc"});
    $j(locHeader).css({cursor: "pointer"}).click(function () {
        var thisLocation = $j(this).next("div");
        if (thisLocation.is(":hidden")) {
            $j(this).addClass("open");
            thisLocation.slideDown(500);
        } else {
            thisLocation.slideUp(400);
            $j(this).removeClass("open");
        }
    });
// locations live search
	$j('#locQuery').liveUpdate('#locList').focus();
// open / close all
	$j('#openAll').css("cursor","pointer").click(function(){
		$j(locHeader).addClass("open").next("div").slideDown(500);
	});
	$j('#closeAll').css("cursor","pointer").click(function(){
		$j(locHeader).removeClass("open").next("div").slideUp(400);
	});	
}

// insurance associations list
if (!($j.browser.msie)) {
	if($j("#associations").length > 0) {
		var alphabet = $j("span strong:visible").text();
		// add alphabet navigation links
		$j.each(alphabet, function(i, value){
			$j("#alphaNav").append( "<li>" + "<a href='#" + value + "'>" + value + "</a>" + "</li>" );
		});	
		// find each letter heading and append the anchor tag
		$j("span strong:visible").each(function(){
			var anchorText = $j(this).text();
			$j(this).prepend("<a name=" + anchorText + "></a>");
		});
	}
}		
// 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, #tellMeMoreTop a').addClass('iframe');
	
	$j("#tellMeMoreButton a, #tellMeMoreTop a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 540,
		'frameHeight': 360,
		'overlayOpacity': 0.8
	});
	
	//	stand alone online banking link
	/*$j('#obl a').addClass('iframe');
	
	$j("#obl a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 230,
		'frameHeight': 230,
		'overlayOpacity': 0.8
	});*/
	
	$j('#financialCalculators li a').addClass('iframe');

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

}); // 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; 
}
// email alert 
function emailConfirmAlert(url){
	jConfirm(emailAlertText, "Confirm", function(r) {
		if( r ){
			window.open(url);
		} else {
			return false;
		}
	});
	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);									 
					});
				}
			}
		});
	}
}
