var $j=jQuery.noConflict();
var alertText = "Please be advised that you are leaving State Employees Credit Union's website. This link is provided as a courtesy.  State Employees Credit Union does not endorse or control the content of third party websites.";
var customFolder = "secunm";
var slideSpeed = 500;
var tabEffect = "fade";	//slide, fade
var url = window.location.pathname; 

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

    productTabs();

    $j(".confirm").click( function() {			   
        if (!confirmAlert($j(this).attr('href'))) {
            return false;			
        }
    });
	
// open in new page for INMO and othera
    $j('a.newPage, body.popup #obNav a').each( function(){
            this.target = "_blank";
    });
// target="_blank"
    $j("a[href*='http://']:not([href*='"+location.hostname+"']),[href*='https://']:not([href*='"+location.hostname+"'])").attr("target","_blank").attr("title","Opens new window");
    
// logo image
    $j('#logo').append('<img src=\"/custom/secunm/image/logo.png\" alt=\"State Employees Credit Union - New Mexico\" />');
        
// obl form
    $j('#userIdWrapper label, #passwordWrapper label').addClass('overlabel');
    $j('label.overlabel').overlabel();
        
// clickable containers
    $j("#productCategory li, #locations ul#locList li, #promotionList li").not("#productCategory.holiday li").click(function(){
        window.location=$j(this).find("a").attr("href");
    }); 

// category page hovers
    $j("#productCategory li, #search li, #promotionList li").not("#productCategory.holiday li").css({cursor:"pointer"}).hover(function(){
            $j(this).addClass("hover");
        },
        function() {
            $j(this).removeClass("hover");	
        }
    );

// product page
    $j("dl#productTabs dd").css({position: "absolute"});
    $j("dl#productTabs dt:last").css({borderRight: "none", background: "none"});
   
    if( (url.indexOf("/loans/unsecured-loans.html") !=-1) ) {
        $j("dl#productTabs dt").css({padding:"0 10px"});
    }

// locations
    $j("#locations .locationInfo").hide();
    $j("#locations li:first .locationInfo").show().parent().find("h2 a").addClass("open");
    $j("#locations li h2").click(function () {
        var thisLocation = $j(this).next("div");
        if (thisLocation.is(":hidden")) {
            $j("#locations h2 a").removeClass("open").parent().parent().find(".locationInfo").slideUp("slow");
            $j(this).find("a").addClass("open");
            thisLocation.slideDown("slow");
        } else {
            $j("#locations h2 a").removeClass("open").parent().parent().find(".locationInfo").slideUp("slow");
            thisLocation.slideUp("fast");
            $j(this).find("a").removeClass("open");
        }
    });

// ncua hover popup
	$j("#footer #ncua a").parent().append("<div id=\"ncuaDisclaimer\"></div>");
	$j("#ncuaDisclaimer").hide();
	$j("#footer #ncua a").hover(function(){
		$j("#ncuaDisclaimer").show();			   
	}, function(){
		$j("#ncuaDisclaimer").hide();
	});
  
// primary nav hover      
    var arrowXY;
    if ((url.indexOf("/deposit-accounts") != -1)) {
        arrowXY = function(){
            $j("#primaryNav").stop().animate({backgroundPosition:'92px bottom'});
        }
    } else if ((url.indexOf("/loans") != -1)) {
        arrowXY = function(){
            $j("#primaryNav").stop().animate({backgroundPosition:'237px bottom'});
        }
    } else if ((url.indexOf("/services") != -1)) {
        var arrowXY = function(){
            $j("#primaryNav").stop().animate({backgroundPosition:'340px bottom'});
        }
    } else if ((url.indexOf("/about-us") != -1)) {
        var arrowXY = function(){
            $j("#primaryNav").stop().animate({backgroundPosition:'460px bottom'});
        }
    } else { var arrowXY = function(){
        $j("#primaryNav").stop().animate({backgroundPosition:'-50px bottom'});
        }
    }

    arrowXY();
    
   $j("#primaryNav li a.nthChild-1").hover(function(){
        $j("#primaryNav").stop().animate({backgroundPosition:"92px bottom"});
    },function(){
        arrowXY();
    });
    $j("#primaryNav li a.nthChild-2").hover(function(){
        $j("#primaryNav").stop().animate({backgroundPosition:"237px bottom"});
    },function(){
        arrowXY();
    });
    $j("#primaryNav li a.nthChild-3").hover(function(){
        $j("#primaryNav").stop().animate({backgroundPosition:"340px bottom"});
    },function(){
        arrowXY();
    });
    $j("#primaryNav li a.nthChild-4").hover(function(){
        $j("#primaryNav").stop().animate({backgroundPosition:"460px bottom"});
    },function(){
        arrowXY();
    });

// 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, .tellMeMoreButton a, .memberNew a, #ultraTopNav li a:contains("Online Banking"), #financialCalculators li a, #oblLink a').addClass('iframe');
    
    $j("#tellMeMoreButton a, .tellMeMoreButton a, a.ccDisclaimer").fancybox({
            'hideOnContentClick': false,
            'frameWidth': 570,
            'frameHeight': 460,
            'overlayOpacity': 0.8
    });
    
    $j("#ultraTopNav li a.iframe, #oblLink a.iframe").fancybox({
            'hideOnContentClick': false,
            'frameWidth': 400,
            'frameHeight': 280,
            'overlayOpacity': 0.8
    });

    $j("#financialCalculators li a").fancybox({
            'hideOnContentClick': false,
            'frameWidth': 650,
            'frameHeight': 400,
            'overlayOpacity': 0.8
    }); 
 	$j(".memberNew a").fancybox({
            'hideOnContentClick': false,
            'frameWidth': 411,
            'frameHeight': 240,
            'overlayOpacity': 0.8
    });
	
	if($j('#footer').length){
		$j('#footerNav li.nthChild-7 a').hover(function(){
			$j('#routingRollover').stop(true,true).fadeIn();
		},function(){
			$j('#routingRollover').stop(true,true).fadeOut();
		});
	}
	if($j('#header').length){
		$j('#ultraTopNav li.lastChild a').hover(function(){
			$j('#routingRolloverUltra').stop(true,true).fadeIn();
		},function(){
			$j('#routingRolloverUltra').stop(true,true).fadeOut();
		});
	}
// hide homepage noscript link
/*var flashLink = $j("body#homepage #mainContent > a"); 
flashLink.children().insertBefore(flashLink);  
flashLink.remove(); 
*/

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

