var $j=jQuery.noConflict();
var alertText = "Please be advised that you are leaving Red River Federal Credit Union's website. This link is provided as a courtesy.  Red River Federal Credit Union does not endorse or control the content of third party websites.";
var customFolder = "redriverfcu";
var slideSpeed = 500;
var tabEffect = "fade";	//slide, fade
var fadeDuration = 200; //time in milliseconds

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

	productTabs();

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

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

//  Delay Drop Down for Leftnav
	if ($j("#leftNav li ul.nthTier-2").length){
	   // animate sub menu
	   $j("#leftNav li ul.nthTier-2").hide().delay(300).slideDown(400);
	 };
		
// add id to body
	$j(function(){
		if ($j('#primaryNav li a').hasClass("inPath")) {
			var primary = $j('#primaryNav li a.inPath').text().replace(/ /g,'');
			$j('body').attr("id",primary);
		}
	});
	
	$j(function(){
		if ($j('#ultraTopNav li a').hasClass("inPath")) {
			var primary = $j('#ultraTopNav li a.inPath').text().replace(/ /g,'');
			$j('body').attr("id",primary);
		}
	});
	
// Tell Me More - SAF - Calculators - OBL Popup provided by FancyBox 
	$j('#tellMeMoreButton a').addClass('iframe');
	
	$j("#tellMeMoreButton a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 570,
		'frameHeight': 400,
		'overlayOpacity': 0.8
	});
	
	$j('#shareButton a').addClass('iframe');
	
	$j("#shareButton a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 570,
		'frameHeight': 520,
		'overlayOpacity': 0.8
	});
	
/*	stand alone online banking link
	$j('#downstreamObl a').addClass('iframe');
	
	$j("#downstreamObl a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 570,
		'frameHeight': 520,
		'overlayOpacity': 0.8
	});*/
	
	// online banking link in ultratopnav
	$j('#ultraTopNav li a:contains("Online Banking")').addClass('iframe');
	
	$j("#ultraTopNav li a.iframe").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 400,
		'frameHeight': 200,
		'overlayOpacity': 0.8
	});
	
	$j('#listLink a').addClass('iframe');

	$j("#listLink a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 550,
		'frameHeight': 300,
		'overlayOpacity': 0.8
	});
	
	$j('#financialCalculators li a').addClass('iframe');

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

//  Primary Navigation Query
	$j("#primaryNav a").hover(function(){
		
		if (!$j(this).hasClass("inPath")) { 
			$j(this).stop().animate(
				{	backgroundPosition: "0 -36px"	}
				, 400);	}
		
		//$j(this).animate({	backgroundPosition: "0 -36px"	}, 400);	   	
		
		}, function() {
			if (!$j(this).hasClass("inPath")) {	
				$j(this).stop().animate(
					{	backgroundPosition: "0 0"	}
					, 400);	}
				}
		);

//  Left Nav Animation		
	/*$j('#leftNav li h2 a').hover(function() {
		$j(this).animate({ 
				paddingLeft: '30px' }, 
				fadeDuration	);
		//$j(this).children('span').show().animate({ left: -5 }, fadeDuration);
		 
		if ( $j('#leftNav li h2 a').hasClass("inPath") ) {
			$j("#leftNav li h2 a.inPath").css("padding-left", "30px");
	    } else {
			$j("#leftNav li h2 a.inPath").css("padding-left", "10px");
	    } 
		
	}, function() {
		$j(this).animate({     
				paddingLeft: '10px' }, 
				fadeDuration	);
		//$j(this).children('span').animate({ left: -35 }, fadeDuration).fadeOut(fadeDuration);
		
		if ( $j('#leftNav li h2 a').hasClass("inPath") ) {
			$j("#leftNav li h2 a.inPath").css("padding-left", "30px");
	    } else {
			$j("#leftNav li h2 a.inPath").css("padding-left", "10px");
	    }
	          
	});*/
	
//  Clickable Container Query  
	$j('ul#homeFeaturedProducts li, #productCategory li, #search ul li, #locations ul#locList li').not("#productCategory li li").click(function(){
		  window.location = $j(this).find("a").attr("href"); return false;
	});

//  Home Featured Products Query
	$j("ul#homeFeaturedProducts li").hover(function(){
		$j('.learnMore a', this).stop().css("backgroundPosition", "0 -29px");
		$j('.imgHolder img', this).stop().animate({
			marginTop: "-97px"
		}, 400);
		//$j('#quickLinks #fourStars, #fourStars, #quickLinks #fourStars').css("backgroundPosition", "0px -89px");
		
	}, function() {
		$j('.learnMore a', this).stop().css("backgroundPosition", "0 0");
		$j('.imgHolder img', this).stop().animate({
			marginTop: "0px"
		}, 400);
		  //$j('#leftColumn #fourStars a, #quickLinks #fourStars a').css("color", "#000");
		  //$j('#quickLinks #fourStars, #fourStars, #quickLinks #fourStars').css("backgroundPosition", "0px 0px");
	});                      
	
//  Category Page Hover Effects
	$j("#productCategory li").hover(function(){
		//$j(".productContent h3 a", this).css("color", "#A00606");
		$j(".productContent h4 a", this).css("backgroundPosition", "0 -31px");

	}, function() {
		//$j(".productContent h3 a", this).css("color", "#333");
		$j(".productContent h4 a", this).css("backgroundPosition", "0 0");				

	});
	
//  Search Page Hover Effects	
	$j("#search li").hover(function(){
		$j("h2 a", this).css("color", "#A00606");
		$j("h2 a", this).css("backgroundPosition", "right -19px");
	}, function() {
		$j("h2 a", this).css("color", "#333333");				
		$j("h2 a", this).css("backgroundPosition", "right 0");
	});
	
//  Search Page Hover Effects
	$j("#locations ul#locList li").hover(function(){
		$j("h2 a", this).css("color", "#A10707");
		$j("h2 a", this).css("text-decoration", "underline");

	}, function() {
		$j("h2 a", this).css("color", "#261F19");					
		$j("h2 a", this).css("text-decoration", "none");
	});

    $j("#username label").overLabel();

	// cycle photos
    $j('#ourRate').cycle({
		fx: 'fade',
		speed:  1000, 
		timeout: 4000, 
		delay: 1000,
		prev:  '#prev2',
		next:  '#next2'
	});
	 
	$j("#ourRate li").css("width", "200px");
	$j("#ourRate li").css("height", "200px");
		
// sort the gMapLocations to match the display
if ( (typeof gMapLocations !== 'undefined') && !($j.browser.msie) && !($j.browser.webkit) ) {
		gMapLocations.sort(function(a, b) { return a.tags > b.tags; });
}
// Resort locations
if ( !($j.browser.webkit) ) {
	$j('.atms ul#locList li').tsort({attr:'class'});
}
		var sa = [];
		var classes = [];
		var city = [];
	$j('.atms ul#locList li').each(function() {
		thisClass = $j(this).attr('class');
		if (thisClass.indexOf(" ") != -1) {
				thisClass = thisClass.substr(0, thisClass.indexOf(" ")-1);
		}

		var spot = classes.length;
		classes[spot] = thisClass;
		city[spot] = $j(this).attr("class").split(/\s/).shift().replace(/-/g," ");

		sa.push( $j(this).clone(true) );
		$j(this).remove();
		});

		sa.reverse();
		var numLocations = classes.length;
		for( var i = 0; i < numLocations; i++ ){
			if( classes[i] != classes[i-1] ){
				$j('.atms ul#locList').append('<li><ul></ul></li>');
				$j('.atms ul#locList li:last').prepend('<h2>' + city[i] + '</h2>').css({'text-transform':'capitalize'});
			}
		$j('.atms ul#locList ul:last').append(sa.pop());
	}

// End resort locations                        
	$j('.atms ul#locList>li>ul').not('.atms ul#locList>li>ul:first').hide();
	$j('.atms ul#locList>li>h2:first').addClass("open");
	$j('.atms ul#locList>li>h2').text().replace(" vcard clear","").replace("-"," ").toUpperCase();
	$j('.atms ul#locList>li>ul:first').addClass('open');

	$j('.atms ul#locList>li>h2').click(function () {
		var thisLocation = $j(this).next("ul");
		if (thisLocation.is(":hidden")) {
			$j(this).addClass("open");
				thisLocation.slideDown("slow");
		} else {                         
			thisLocation.slideUp("fast");
			$j(this).removeClass("open");
		}                                
	});                                        

	$j('.atms ul#locList li ul li').hover(function () {
			$j(this).addClass('hover');
		},
		function () {
			$j(this).removeClass('hover');
		}
	);
	
}); // END doc ready

Cufon.set("selector", jQuery);
Cufon.replace(".individualPage h1, .catgoryBanner h1, #leftNav li h2 a, div#productCategory div.productContent h3 a, body#Services #leftNav li li h3 a, .productHead h1, body.popup form h4.title, #thankYou h4.thanksTitle, #alert .indieHolder h1, fieldset#newApplication div#introduction h1, body#Loans #leftNav li li.nthChild-2 h3 a.inPath", { 
	separate: "words", 
	hover: true
});

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:eq(1), #productTabs dd:eq(2)').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);									 
					});
				}
			}
		});
	}
}

/* add images for addPrintLink  */
/*$j('#logo a').after('<img src="/custom/' + customFolder + '/image/logo.png" alt="BANK NAME"/>');
$j('#footer #firstROI').after('<img class="froiLogo" src="/custom/' + customFolder + '/image/firstroi-logo.png" alt="First ROI"/>');*/

/* addPrintLink function by Roger Johansson, www.456bereastreet.com */
var addPrintLink = {
	init:function(sTargetEl,sLinkText) {
		if (!document.getElementById || !document.createTextNode) {return;} // Check for DOM support
		if (!document.getElementById(sTargetEl)) {return;} // Check that the target element actually exists
		if (!window.print) {return;} // Check that the browser supports window.print
		var oTarget = document.getElementById(sTargetEl);
		var oLink = document.createElement('a');
		oLink.id = 'printLink'; // Give the link an id to allow styling
		oLink.href = '#'; // Make the link focusable for keyboard users
		oLink.appendChild(document.createTextNode(sLinkText));
		oLink.onclick = function() {window.print(); return false;} // Return false prevents the browser from following the link and jumping to the top of the page after printing
		oTarget.appendChild(oLink);
	},
/*
addEvent function included here for portability. Replace with your own addEvent function if you use one.
*/
/* addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html */
	addEvent:function(obj, type, fn) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() {obj["e"+type+fn](window.event);}
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	}
};
addPrintLink.addEvent(window, 'load', function(){addPrintLink.init('printThisPage','Print this page');});

