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

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

	productTabs();

	$j(".confirm").click( function() {						   
		if (!confirmAlert($j(this).attr('href'))){
			return false;			
		}
	});
	$j('.warn a').each( function(){
		this.target = "_blank";
	});
		
	// New page for INMO
	$j('a.newPage').each( function(){
		this.target = "_blank";
	});

	// FancyBox popup on applications
	$j("a#ssnWhy").fancybox({
		'frameWidth': 300,
		'frameHeight': 190
	});
	
	// Tell Me More, calculator, and online banking login popups provided by FancyBox 
	$j('#questions a, #ultraTopNav li a:contains("Online Banking"), #financialCalculators li a').addClass('iframe');
	
	$j("#questions a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 570,
		'frameHeight': 375,
		'overlayOpacity': 0.8,
		'padding': 0
	});
	
	$j("#ultraTopNav li a.iframe").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 265,
		'frameHeight': 250,
		'overlayOpacity': 0.8,
		'padding': 0
	});
	
	if( $j.browser.msie )
	{	$j("#financialCalculators li a").fancybox({
			'hideOnContentClick': false,
			'frameWidth': 650,
			'frameHeight': 400,
			'padding': 0,
			'overlayOpacity': 0.8
		});
	}
	else 
	{	$j("#financialCalculators li a").fancybox({
			'hideOnContentClick': false,
			'frameWidth': 650,
			'frameHeight': 394,
			'padding': 0,
			'overlayOpacity': 0.8
		});
	}
	
	//clickable container
	$j('.productListing, #insideIBT, #testimonials').css('cursor', 'pointer');
	$j('.productContent h4 a, #insideIBT a, #testimonials a, #froisearch-results a').bind('click', function() {
		window.location.href = this.href;
		return false;
	});
	$j('.productListing')
		.click( function(){
			$j('.productContent h4 a', this).trigger('click');
		})
		.hover( function(){
			$j('.productContent h3 a', this).css('color', '#085F81');
			$j('.productContent h4 a', this).css('background-position', '0 -31px');
			$j('.relatedProductFrame', this).css('background-position', '0 -90px');
		}, function(){
			$j('.productContent h3 a', this).css('color', '#666');
			$j('.productContent h4 a, .relatedProductFrame', this).css('background-position', '0 0');
		});
	$j('#insideIBT, #testimonials')
		.click( function(){
			$j('a', this).trigger('click');
		})
		.hover( function(){
			$j('a', this).css('color', '#085F81');
		}, function(){
			$j('a', this).css('color', '#666');
		});
		
	//leftNav animations
	if( !$j.browser.msie )
	{	$j('#leftNav li h2 a:not(.inPath)').hover(
			function(){ 
				$j(this)
					.css({'opacity': '0.5'})
					.stop().animate({'opacity': 1}); },
			function(){ 
				$j(this)
					.css({'opacity': '1'}); }
			);
	}
	//leftNav styling
	var subLeftNav = $j('#leftNav li.lastChild').find('ul.nthTier-2').length;
	if( subLeftNav > 0 )
	{	$j('#leftNav li.lastChild.inPath').addClass('roundedSubmenuCorner');
		if( $j('#leftNav li.lastChild.inPath').find('li.inPath.lastChild').length > 0 )
			$j('#leftNav li.lastChild.inPath').addClass('hover');
		else
		{	$j('#leftNav li.lastChild.inPath li.lastChild').hover( 
				function(){ 
					$j(this).parents('li').addClass('hover'); },
				function(){ 
					$j(this).parents('li').removeClass('hover') }
			);
		}
	}
	
	else
		$j('#leftNav li.lastChild').addClass('roundedCorner');
	
	//Genesis leftnav hack
	$j('#leftNav li h2 a:contains("Genesis")').html('Genesis <span>(Faith-based Organizations)</span>');
	
	//app mailing address slide 
	$j('#addressSwitch').click( function(){
		$j('#address_information-mailing').slideToggle()
	});

	//secondaryNav animations
	/*$j('#primaryNav li').mouseover( function(){
		$j('#primaryNav li a.hover').removeClass('hover');
		$j('a', this).addClass('hover');
		
		var leftPosStart = $j('#header').offset().left;
		$j('#secondaryNav li ul.nthTier-2').hide();
		if( $j(this).hasClass('nthChild-1') )
			$j('#secondaryNav li.nthChild-1 ul.nthTier-2').css('margin-left', leftPosStart + 188).show();
		else if( $j(this).hasClass('nthChild-2') )
			$j('#secondaryNav li.nthChild-2 ul.nthTier-2').css('margin-left', leftPosStart + 312).show();
		else 
			$j('#secondaryNav li.nthChild-3 ul.nthTier-2').css('margin-left', leftPosStart + 397).show();
		$j('#secondaryNav').slideDown();
	});
	$j(':not(#primaryNav)').click( function(){
		$j('#primaryNav li a.hover').removeClass('hover');
		$j('#secondaryNav').slideUp();
	});*/
});

$j(window).load( function(){  
	//non-flash banner
	$j('#flashDNA img').wrap('<a href="/personal/checking/ultimate-checking.html" />');
});

//new search clickable container
$j('.froisearch').live('mouseover', function(){
	$j('li', this).css('cursor', 'pointer');
	$j('li a', this).bind('click', function() {
		window.location.href = this.href;
		return false;
	});
	$j('li', this)
		.click( function(){
			$j('a', this).trigger('click');
		})
		.hover( function(){
			$j('a', this).css({
				'color': '#085F81',
				'text-decoration': 'underline'});
		}, function(){
			$j('a', this).css({
				'color': '#333',
				'text-decoration': 'none'});
		});
});

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