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

$j(document).ready( function() {
	$j('#homeFeaturedProducts li a').bigTarget({
    	clickZone : 'li:eq(0)'
	});
	$j('#productCategory li a').bigTarget({
    	clickZone : 'li:eq(0)'
	});
	
	if( $j('#productCategory').length > 0 ){
		$j('#productCategory li').hover( function(){
			$j(this).find('img').attr('src', '/custom/first-federal/image/learnMoreButtonHover.png');
		}, function(){
			$j(this).find('img').attr('src', '/custom/first-federal/image/learnMoreButton.png');
		});
	}
	
	if( $j('#homepage').length == 0 && $j('.noLeftNav').length == 0 ) {
		$j('#quickLinks').data('expanded', false);
		$j('#quickLinks').hover( function(){
			if( !$j('#quickLinks').data('expanded') ){
				$j('#quickLinks').stop().animate({bottom: '0px'}, 500);
			}
		}, function(){
			if( !$j('#quickLinks').data('expanded') ){
				$j('#quickLinks').stop().animate({bottom: '-145px'}, 200);
			}
		});
	}

	primaryNav();
	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
	});
	
// 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
	});
	
	// 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': 280,
		'overlayOpacity': 0.8
	});
	
	$j('#financialCalculators li a').addClass('iframe');

	$j("#financialCalculators li a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 650,
		'frameHeight': 400,
		'overlayOpacity': 0.8
	}); 
	
	//Questions replace
	$j('#tellMeMoreButton img').hover( function(){
		$j(this).attr('src', '/custom/first-federal/image/questionsButtonHover.png');
	}, function(){
		$j(this).attr('src', '/custom/first-federal/image/questionsButton.png');
	});
	
	//OLB
	if( $j('#Remote').length > 0 ){
		$j('#Remote').submit( function(){
			return doLoginRefresh();
		});
	}
	
// End of Fancybox jQuery

	/*if( $j('#locations').length > 0 ){
		var blah = [];
		var j = 0;
		for( var i = 0; i < gMapLocations.length; i++ ){
			blah[j] = gMapLocations[i];
			j++;
			blah[j] = gMapLocations[i];
			j++;
		}
		gMapLocations = [];
		for( var i = 0; i < blah.length; i++ ){
			gMapLocations.push(blah[i]);
			console.log(blah[i]);
		}
	}*/

}); // END doc ready

function forceQL(){
	$j('#quickLinks').stop().css({bottom: '-146px'});
}

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 primaryNav(){
	$j('#primaryNav h2').mouseenter( function(){
		$j(this).children('a').addClass('noBG');
		$j(this).next().slideDown(350);
	});
	$j('#primaryNav li').mouseleave( function(){
		$j('#primaryNav li h2 a').removeClass('noBG');
		$j(this).children('ul').slideUp(200);
	});
}

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);									 
					});
				}
			}
		}, function(){forceQL();});
		forceQL();
	}
}


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


function setAction()
{
	//Fill in the Routing number below.
	var rtNum = "272471085";
	var x = document.forms.Remote;
	
	if(x.loginTo[0].checked) {
		x.nmUID.value = x.AccessID.value;
		x.nmRTN.value = rtNum;
		x.action = 'https://web6.secureinternetbank.com/pbi_pbi1961/Pbi1961.ashx?WCI=RemoteLogin&RT=272471085&LogonBy=connect3&PRMACCESS=Account';			
	} else {
		x.nmUID.value = x.AccessID.value;
		x.nmRTN.value = rtNum;
		x.action = 'https://web6.secureinternetbank.com/EBC_EBC1961/EBC1961.asp?WCI=Process&WCE=RemoteLogon&IRL=T&RT=272471085&mfa=2';
	}
}
function doLoginRefresh()
{
	var x = document.forms.Remote;
	
	if (x.AccessIDVisible.value != "") {
		x.AccessID.value = x.AccessIDVisible.value;
		x.AccessIDVisible.value = "";
		
		setAction();
		return true;
	} else {
		alert("Please Enter a valid Access ID.  Thank you!"); 
		return false;
	}	
}

