var $j=jQuery.noConflict();
var alertText = "You are now leaving the Consumers National Bank website.";
var customFolder = "_templateSECONDBranch";
var slideSpeed = 500;
var tabEffect = "fade";	//slide, fade                           

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

	productTabs();
	
	$j('#primaryNav h2').mouseenter( function(){
		$j(this).next().slideDown(350);
	});
	$j('#primaryNav li').mouseleave( function(){
		$j(this).children('ul.nthTier-2').slideUp(200);
	});

	$j(".confirm").click( function() {						   
		if (!confirmAlert($j(this).attr('href'))){
			return false;			
		}
	});
	
	$j(".warn").click( function() {						   
		$j(this).css("target", "_blank");
	}); 	
		
	
// 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
	});
	
// online banking link in ultratopnav
	//$j('#downstreamObl a:contains("Online Banking Login")').addClass('iframe');
	
	$j("#downstreamObl a.iframe").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 500,
		'frameHeight': 160,
		'overlayOpacity': 0.8
	});
	
	$j('#financialCalculators li a').addClass('iframe');

	$j("#financialCalculators li a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 650,
		'frameHeight': 400,
		'overlayOpacity': 0.8
	});
	
// Japanese Nav names 
	$j('#primaryNav.jp a:contains("サービスのご案内")').attr("name", "サービスのご案内");

//  Allows the Quick Links Container to be clickable	
	$j("#leftColumn #fourStars, #quickLinks #fourStars, #quickLinks #calendar, #homeFeaturedProducts li.productContainer, #featuredContainer, #secondaryProducts li, #search ul li").not("#secondaryProducts li li").click(function(){
		  window.location = $j(this).find("a").attr("href"); return false;
	});
	
	
	$j("#leftColumn #fourStars, #quickLinks #fourStars").hover(function(){
		  $j('#leftColumn #fourStars a, #quickLinks #fourStars a').css("backgroundPosition", "68px -24px");
		  $j('#leftColumn #fourStars a, #quickLinks #fourStars a').css("color", "#9A0037");
		  $j('#quickLinks #fourStars, #fourStars, #quickLinks #fourStars').css("backgroundPosition", "0px -89px");
		
	}, function() {
		  $j('#leftColumn #fourStars a, #quickLinks #fourStars a').css("backgroundPosition", "68px 0px");
		  $j('#leftColumn #fourStars a, #quickLinks #fourStars a').css("color", "#000");
		  $j('#quickLinks #fourStars, #fourStars, #quickLinks #fourStars').css("backgroundPosition", "0px 0px");
	});
	
	//makes the whole prod container to look clickable (not in css b/c confusing if no js)
	$j('#homeFeaturedProducts li, #featuredContainer, #secondaryProducts li').css('cursor', 'pointer');
//  Changes the Learn More and Image
	$j("#homeFeaturedProducts li.productContainer").hover(function(){
  
		$j('a', this).css("backgroundPosition", "66px -24px");
		  $j('a', this).css("color", "#9A0037");
		var divTier = $j('div.fadeout', this);
		// on hovering over, find the element we want to fade *up*
	    var fade = $j('> div', divTier);
	    // if the element is currently being animated (to a fadeOut)...
	    if (fade.is(':animated')) {
	      // ...take it's current opacity back up to 1
	      fade.stop().fadeTo(200, 1);
	    } else {
	      // fade in quickly
	      fade.fadeIn(200);
	    }
	}, function() {
		  $j('a', this).css("backgroundPosition", "66px 0px");
		  $j('a', this).css("color", "#000");
		var divTier = $j('div.fadeout', this);
		var fade = $j('> div', divTier);
	    if (fade.is(':animated')) {
	      fade.stop().fadeTo(200, 0);
	    } else {
	      // fade away slowly
	      fade.fadeOut(200);
	    }		
	});                       

	$j("#featuredContainer").hover(function() {
		$j('#featuredContent h1', this).css("color", "#9B0037"); 
		$j('#fpLearnMore a', this).css("backgroundPosition", "0 -38px");  
	}, function() {
		$j('#featuredContent h1', this).css("color", "#333333"); 		
		$j('#fpLearnMore a', this).css("backgroundPosition", "0 0"); 		         
	});   

	$j("#secondaryProducts li").hover(function() {
		$j('h2 a', this).css("color", "#9B0037"); 
		$j('h3 a', this).css("color", "#9B0037");
		$j('h3 a', this).css("backgroundPosition", "70px -24px");  
	}, function() {
		$j('h2 a', this).css("color", "#333333"); 		
		$j('h3 a', this).css("color", "#333333"); 		         
		$j('h3 a', this).css("backgroundPosition", "70px 0px"); 		         		
	});
	
	$j("#search ul li").hover(function() {
		$j('h2 a', this).css("color", "#9B0037"); 
		$j('h3 a', this).css("color", "#9B0037");
		$j('h3 a', this).css("backgroundPosition", "82px -22px");  
	}, function() {
		$j('h2 a', this).css("color", "#333333"); 		
		$j('h3 a', this).css("color", "#333333"); 		         
		$j('h3 a', this).css("backgroundPosition", "82px 2px"); 		         		
	});
	
	if ($j("#leftNav li ul.nthTier-2").length){
	   // animate sub menu
	   $j("#leftNav li ul.nthTier-2").hide().delay(300).slideDown(400);
	 };
	

// Leftnav Hovering Effect
	$j("#leftNav li h2 a").hover(
    	function(){
        	if (!$j(this).hasClass("inPath")) {
            	$j(this).stop().css("background-color", "#BB9050");
        	} 
    	},
    
		function(){
        	if (!$j(this).hasClass("inPath")) {
            	$j(this).stop().animate(
					{backgroundColor: '#B0AC92'},
					"fast"
				)
        	}                       
    });

	$j("#username label").overLabel();
	$j("#password label").overLabel();
	
	$j('#investments a:contains("Account Log In")').attr("id", "button");

//  Search Page

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

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

