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

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

	productTabs();

	$j(".confirm").click( function() {
		if (!confirmAlert($j(this).attr('href'))){
				return false;			
			}
		});
		
// add noSubMenu class to body for Insurance and About Us pages
if (/\/insurance-investments/.test(window.location) || /\/about-us/.test(window.location) || /\/online-banking/.test(window.location)) {
	$j('body').addClass("noSubMenu");
};
// new page for INMO
	$j('a.newPage').each( function(){
		this.target = "_blank";
	});

// fancybox popup on apps
	$j("a#ssnWhy").fancybox({
		'frameWidth': 300,
		'frameHeight': 190
	});

// main navigation hover effect
	$j("#primaryNav li").append("<span></span>");
	$j("#primaryNav li a").not("#primaryNav li a.inPath").css("background","none");
	$j("#primaryNav li").mouseover(function() {
		$j("span",this).stop().fadeTo(300,1);
	});
	$j("#primaryNav li").mouseout(function() {
		$j("span",this).stop().fadeTo(500,0);
	});
	
// make containers clickable 
	$j('#productCategory ul > li, #homeFeaturedProducts li#featuredB, #homeFeaturedProducts li#featuredC').click(function(){
		window.location=$j(this).find('a').attr('href');
	});
	
if($j("body#home").length > 0){
	// homeFeaturedProducts rates
	// add spinner 
	$j("#ratesContainer").append("<img id='spinner' src='custom/floridacentralcu/image/spinning-numbers.gif'/>")
	function spinner (){
		$j("#spinner").fadeIn(200).delay(200).fadeOut(200);
	};
		
	function ratesBack(){
		var holdThis = $j('#ratesContainer div:visible');
		spinner ();
		if( $j(holdThis).prev(".rateInfo").length > 0 ){
			$j(holdThis).fadeOut(200, function(){
				$j(holdThis).prev().fadeIn(500);
			});
		}
		else{
			$j(holdThis).fadeOut(200, function(){
				$j('#ratesContainer div:last').fadeIn(500);
			});
		}
	};
	$j('#ratesBack').bind('click', function(){
		ratesBack();
	});
	
	function ratesNext(){	
		var holdThis = $j('#ratesContainer div:visible');
		spinner ();
		if( $j(holdThis).next(".rateInfo").length > 0 ){
			$j(holdThis).fadeOut(200, function(){
				$j(holdThis).next().fadeIn(500);
			});
		}
		else{
			$j(holdThis).fadeOut(200, function(){
				$j('#ratesContainer div:first').fadeIn(500);
			});
		}
	};
	
	$j('#ratesNext').bind('click', function(){
		ratesNext();
	});
	// set interval for rates to automatically spin
	var ratesNextAuto = setInterval(ratesNext, 7000);

	// stop on mouse enter
	$j('#featuredA').bind('mouseenter', function(){
		clearInterval(ratesNextAuto);
	});
	// resume setInterval on mouse leave
	$j('#featuredA').bind('mouseleave', function(){
		ratesNextAuto = setInterval(ratesNext, 7000);
	});
	
	
	// homeFeaturedProducts rotate sprint paragraphs
	// fade out the visible and fadein the next hidden
		function rotateSprint() {
			var holdThis = $j('#homeFeaturedProducts li#featuredB p:visible');
			if( $j(holdThis).prev(".featuredDesc").length > 0 ){
				$j(holdThis).fadeOut(500, function(){
					$j(holdThis).prev().fadeIn(400);
				});
			}
			else{
				$j(holdThis).fadeOut(500, function(){
					$j('#homeFeaturedProducts li#featuredB p:last').show(500);
				});
			}
		}
		var rotateSprintAuto = setInterval(rotateSprint, 5000);
		rotateSprint();		

	// homeFeaturedProducts rollovers
	$j("#homeFeaturedProducts li#featuredB, #homeFeaturedProducts li#featuredC")
		.css("cursor","pointer")
		.append("<span class='hoverSpan'></span>")
	    	.hover(function(){
		    	$j("span.featuredPeople",this).stop().animate({'margin-right':'-4px'},400);
				$j("span.hoverSpan",this).stop().fadeTo(300,1);
				$j('a',this).stop().css('backgroundPosition','0 -25px');
	       	}, function(){
	       		$j("span.featuredPeople",this).stop().animate({'margin-right':'-7px'},300);
				$j("span.hoverSpan",this).stop().fadeTo(500,0);
				$j('a',this).stop().css('backgroundPosition','0 0');
	    }
	);
}; // END if home

// ultratopnav social links
	$j('#ultraTopNav li:contains("blog")').addClass('linkBlog');
	$j('#ultraTopNav li:contains("twitter")').addClass('linkTwitter');
	$j('#ultraTopNav li:contains("facebook")').addClass('linkFacebook');

// add name to category h1
	var catName = $j('#primaryNav li.inPath a').text() + " ";
	$j('#catDescriptionCopy h1').prepend(catName);

// productCategory rollovers
    $j("#productCategory ul li").not("#productCategory ul li li").css("cursor","pointer")
    	.hover(function(){
       		$j(this).stop().animate({'backgroundPosition':'140px 0'},200);
			$j('h4 a',this).stop().css('backgroundPosition','0 -25px');
       	}, function(){
       		$j(this).stop().animate({'backgroundPosition':'140px 90px'},500);
			$j('h4 a',this).stop().css('backgroundPosition','0 0');
       	}
    );
	
// leftNav rollovers
	$j("#leftNav li ul.nthTier-2 li a").not("#leftNav li ul.nthTier-2 li a.inPath").hover(function(){
	       $j(this).stop().animate({'marginLeft':'10px'},200);
	     }, function(){
	       $j(this).stop().animate({'marginLeft':'2px'},300);
	     }
	 );
	
// locations
    $j("#locations .locationInfo").hide();
    $j("#locations li h2").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");
        }
    });


// Tell Me More - SAF - Calculators - OBL Popup provided by FancyBox 
	$j('#tellMeMoreButton a').addClass('iframe');
	
	$j("#tellMeMoreButton a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 540,
		'frameHeight': 360,
		'overlayOpacity': 0.8
	});
	
	// stand alone online banking link
	// $j('#downstreamObl a').addClass('iframe');
	// 	
	// 	$j("#downstreamObl a").fancybox({
	// 		'hideOnContentClick': false,
	// 		'frameWidth': 570,
	// 		'frameHeight': 540,
	// 		'overlayOpacity': 0.8
	// 	});
	
	// online banking link in ultratopnav
	
	$j('#financialCalculators li a').addClass('iframe');

	$j("#financialCalculators li a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 650,
		'frameHeight': 394,
		'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; 
}

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