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

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

	productTabs();
	
// cufon
Cufon.replace('#primaryNav a, #catDescription h1, #thankYou h1', { hover: true });

// make containers clickable 
$j('#productCategory ul > li, #homeFeaturedProducts li, #search li').live('click', function(){
	window.location=$j(this).find('a').attr('href');
});

// leftnav - if the li does not contain a ul.nthTier-2 then show different select state
$j("#leftNav li:not(:has(ul))").addClass("noSubnav");

// add the header to .individualPage
$j(".individualPage").append("<span id='topBar'></span>");

// quicklinks rollover : add the arrow for li.inPath
$j("#quickLinks li.inPath").append("<span class='qlInpath'></span>");
// quicklinks rollover : add a span with the arrow
$j("#quickLinks a").live("mouseover mouseout", function(event){
	var theLi = $j(this).parent("li");
	var theSpan = $j(theLi).find("span.qlHover");
	if (event.type == 'mouseover') {
		// no mouseover for li.inPath
		if (theLi.hasClass("inPath")) {
			return false;
		}  else {
			$j(this).css({backgroundPosition : "0 -999px"})
			.stop().animate({paddingLeft:"0",paddingRight:"10px"},{duration:200})
			.parent("li").append("<span class='qlHover'></span>");
		}
	} else {
		// mouseout
		$j(this).css({backgroundPosition : "0 -279px"})
		.stop().animate({paddingLeft:"10px",paddingRight:"0"},{duration:200});
		$j(theSpan).fadeOut("fast", function(){
			$j(theSpan).remove();
		});
	}
});
// search results rollover
$j("#search li").live("mouseover mouseout", function(event){
	var searchA = $j(this).find('a');
	if (event.type == 'mouseover') {
		searchA.css({color : "#FFB226", textDecoration : "underline"});
	} else {
		searchA.css({color : "#D8862F", textDecoration : "none"});
	}
});

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

//Contact
$j('#formContactUs #roi-captchaCode').attr('tabindex', '4');
$j('#formContactUs .submitButton').attr('tabindex', '6');

// FancyBox popup on applications
if($j("#applicationPage").length > 0){
	$j("#ssnWhy").fancybox({
		'frameWidth': 300,
		'frameHeight': 190
	});
}

// add target parent to obl links
$j("#obNav a").attr("target","_parent");
	
// 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;
	}
});	
// home featured
if($j("body#home").length > 0){
	
	$j("#homeFeaturedProducts li").css("cursor","pointer")
    	.hover(function(){
			// fade out image and animate the title down
			$j('.image',this).stop(true, true).fadeOut(200);
	    	$j("h3",this).stop().animate({'margin-top':'100px'}, {
				duration: 300,
				easing: 'easeOutBack'
			}).css({backgroundPosition : '0 0', padding : '18px 0 0'});
			// show the over state content
			$j(".over",this).stop(true, true).fadeIn(250);
       	}, function(){
			$j('.image',this).stop(true, true).fadeIn(350);
			$j("h3",this).stop().animate({'margin-top':'0'},{
				duration: 400,
				easing: 'easeOutBack'
			}).css({backgroundPosition : '0 -47px', padding : '4px 0 0'});
			$j(".over",this).stop(true, true).fadeOut(200);
	    }
	);
	
} // END home featured

// category li rollovers
if($j("#productCategory").length > 0){
	
	$j("#productCategory li").css("cursor","pointer")
    	.hover(function(){
			$j('h3 a',this).css("color","#D18606");
			$j('h4 a',this).css({color : "#FFB226", backgroundPosition : "79px -382px"});
       	}, function(){
			$j('h3 a',this).css("color","#795D26");
			$j('h4 a',this).css({color : "#CE6B01", backgroundPosition : "79px -331px"});
	    }
	);
	
} // END category li rollovers

// Tell Me More, calculator, and online banking login popups provided by FancyBox 
	$j('#tellMeMoreButton a').addClass('iframe');
	
	$j("#tellMeMoreButton a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 540,
		'frameHeight': 370,
		'overlayOpacity': 0.8
	});
	
	// Standalone online banking link
	$j('#ultraTopNav a:contains("Online Banking")').addClass('iframe');
	
	$j("#ultraTopNav a.iframe").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 250,
		'frameHeight': 200,
		'overlayOpacity': 0.8
	}); 
	
	$j('#financialCalculators li a').addClass('iframe');

	$j("#financialCalculators li a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 650,
		'frameHeight': 394,
		'padding': 10,
		'overlayOpacity': 0.8
	});

	//	Overlabel - place a div with the class 'overLabelWrapper' around whatever will be using this code. Make sure that the label is set to display block
	if($j('.overLabelWrapper').length > 0){
		$j('#obLogin label').css('position','absolute');
		var labelFor = $j('.overLabelWrapper form label[for]');
		var inputFor = $j('.overLabelWrapper form 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': '-999em'
				});
			});
			$j('.overLabelWrapper input.overLabel').blur(function(){
				if($j(this).val() == ''){
					$j(this).prev().css({
						'text-indent': '0'
					});
				}
			});	
		}
	}
		
}); // 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);									 
					});
				}
			}
		});
	}
}