var $j=jQuery.noConflict();
var alertText = "Please be advised that you are leaving Gibsland Bank & Trust's website. This link is provided as a courtesy.  Gibsland Bank & Trust does not endorse or control the content of third party websites.";
var customFolder = "gibslandbank";
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;
			}
		}); 

// add hidden logo for print stylesheet
	$j('#logo a').after('<img src="/custom/' + customFolder + '/image/logo.png" alt="Gibsland Bank and Trust"/>');
	
// add class according to URL - Personal, Business, About Us
	if ((url.indexOf("personal/") != -1)) {
	$j("body").attr("class","personal");
	}
	if ((url.indexOf("business/") != -1)) {
	$j("body").attr("class","business");
	}
	if ((url.indexOf("about-us") != -1)) {
	$j("body").attr("class","aboutUs");
	}	
	
	
// Online banking login - focus and blur
    $j('form#obl input#username ').focus(function() {
        if ($j(this).attr('value') =='User ID'){
            $j(this).attr('value','');
        }
    });
    $j('form#obl input#username ').blur(function() {
        if ($j(this).attr('value') ==''){
        $j(this).attr('value', 'User ID');
        }
    });
	
	$j('ul#obNav li a.firstChild').click(function(){
		if ( $j('form#obl input#username').attr('value') == ''){
			alert("Please enter your User ID first.");
			return ( false );
		}
		else {
		top.frames.location.href="https://www2.bankdataprocessing.com/gibslandbank/Enrollment/ProjectFrame.aspx?mode=password&username=" + $j('form#obl input#username').val();
			return ( false );
		}

    });

	

// leftNav - delay and slidedown
	if ($j("#leftNav li ul.nthTier-2").length){
		$j("#leftNav li ul.nthTier-2").hide().delay(300).slideDown(400);
	};
	
	$j("ul#leftNav li:last, ul#leftNav li a:last").addClass("lastLastChild");
	
	
// clickable containers
	$j("#productCategory ul li, #locations li, #search.individualPage ul li").click(function(){
		window.location=$j(this).find("a").attr("href");
	}); 


// locations
	$j("#locations h2 a").hover(
		function(){
			Cufon.replace(this, { separate: "none" });
		},
		function(){
			Cufon.replace(this, { separate: "none" });
		}
	); 
	
	$j('#locations .locationInfo').hide();
	$j('#locations li:last').addClass('lastChild');
	
	$j("#locations li h2").click(function () {
		var thisLocation = $j(this).next("div");
		if (thisLocation.is(":hidden")) {
			$j(this).parent().addClass("open");
			thisLocation.slideDown("slow");
		} else {
			thisLocation.slideUp("normal");
			$j(this).parent().removeClass("open");
		}
	});
	
	$j("#locations .locationInfo .hours:not(:has('dl'))").hide();

// comparing checking accounts - ULs and LIs - adding the hover class
	$j('div#productCategory ul#checkingAccounts li').not('div#productCategory ul#comparisonNav li, div#productCategory ul#checkingAccounts li ul li').hover(function() {
		$j(this).addClass('hover');																		
	},
	function() {
		$j(this).removeClass('hover');	
	});

// comparing checking accounts - ULs and LIs - forced CSS based on content
	$j('body.personal div#productCategory ul#checkingAccounts li ul').show();
	$j('div#productCategory ul#checkingAccounts li ul li').css({ border: 'none', borderRadius: '0', opacity: '0.4' });
	
	var cat1 = "div#productCategory ul#checkingAccounts li"
	var cat2 = "div#productCategory ul#checkingAccounts li ul li"
	
	$j(cat2 + ":contains('Free Checking')").css({backgroundPosition : "0 -348px"}).parent().parent().addClass("freeChecking");
	$j(cat2 + ":contains('E-statements')").css({backgroundPosition : "0 -395px"}).parent().parent().addClass("eStatements");
	$j(cat2 + ":contains('Online Billpay')").css({backgroundPosition : "0 -445px"}).parent().parent().addClass("billPay");
	$j(cat2 + ":contains('Reward Points')").css({backgroundPosition : "0 -495px"}).parent().parent().addClass("rewards");	
	$j(cat2 + ":contains('Interest Bearing')").css({backgroundPosition : "0 -545px"}).parent().parent().addClass("interest");
	$j(cat2 + ":contains('Overdraft Protection')").css({backgroundPosition : "0 -595px"}).parent().parent().addClass("overDraft");
	$j(cat2 + ":contains('No Minimum Balance')").css({backgroundPosition : "0 -645px"}).parent().parent().addClass("minBalance");	
	
// account ref guide - the nav
	$j('#accountRefGuide').show();
	$j('#accountRefGuide li:last').addClass('lastChild');
	$j("#accountRefGuide h3").hide();
	$j("#accountRefGuide h4").show();
												
	$j("#accountRefGuide h2 a, #accountRefGuide h3 a, #accountRefGuide h4 a").click(function () {
		if ($j('#accountRefGuide ul, #accountRefGuide p, #accountRefGuide h4').is(":hidden")) {
			$j("#accountRefGuide h2 a").addClass("open");
			$j('#accountRefGuide ul, #accountRefGuide p').slideDown("slow");
			$j("#accountRefGuide h3").hide();
			$j("#accountRefGuide h4").show();
		} else {
			$j("#accountRefGuide h2 a").removeClass("open");
			$j('#accountRefGuide ul, #accountRefGuide p').slideUp("normal");
			$j("#accountRefGuide h3").show();
			$j("#accountRefGuide h4").hide();
			
			/*$j("#accountRefGuide a").parent().removeClass("active");
			$j("body.personal div#productCategory ul#checkingAccounts li").css({opacity: 1});
			$j("body.personal div#productCategory ul#checkingAccounts li ul li").css({opacity: 0.4});*/
		}
	});
	
	$j("#accountRefGuide h5 a").click(function () {
			$j("#accountRefGuide a").parent().removeClass("active");
			$j("body.personal div#productCategory ul#checkingAccounts li").removeClass("active").css({opacity: 1});
			$j("body.personal div#productCategory ul#checkingAccounts li ul li").css({opacity: 0.4});
	
	});
	
// account ref guide - the nav - a tags
	$j("#accountRefGuide a.nthChild-1").click(function () {
		$j("#accountRefGuide a").parent().removeClass("active");
		$j(this).parent().addClass("active");
		$j(cat1).css({opacity: "0.4"});
		$j(cat1 + ".freeChecking," + cat2).css({opacity: "1"});
		$j(cat2).css({ opacity: 0.4 });
		$j(cat2 + ":contains('Free Checking')").css({ opacity: 1 });
		return ( false );
		
	});
	
	$j("#accountRefGuide a.nthChild-2").click(function () {
		$j("#accountRefGuide a").parent().removeClass("active");
		$j(this).parent().addClass("active");
		$j(cat1).css({opacity: "0.4"});
		$j(cat1 + ".eStatements," + cat2).css({opacity: "1"});
		$j(cat2).css({ opacity: 0.4 });
		$j(cat2 + ":contains('E-statements')").css({ opacity : 1 });
		return ( false );
	});
	
	$j("#accountRefGuide a.nthChild-3").click(function () {
		$j("#accountRefGuide a").parent().removeClass("active");
		$j(this).parent().addClass("active");
		$j(cat1).css({opacity: "0.4"});
		$j(cat1 + ".billPay," + cat2).css({opacity: "1"});
		$j(cat2).css({ opacity: 0.4 });
		$j(cat2 + ":contains('Online Billpay')").css({ opacity : 1 });
		return ( false );
	});
	
	$j("#accountRefGuide a.nthChild-4").click(function () {
		$j("#accountRefGuide a").parent().removeClass("active");
		$j(this).parent().addClass("active");
		$j(cat1).css({opacity: "0.4"});
		$j(cat1 + ".rewards," + cat2).css({opacity: "1"});
		$j(cat2).css({ opacity: 0.4 });
		$j(cat2 + ":contains('Reward Points')").css({ opacity : 1 });												
		return ( false );
	});
	
	$j("#accountRefGuide a.nthChild-5").click(function () {
		$j("#accountRefGuide a").parent().removeClass("active");
		$j(this).parent().addClass("active");
		$j(cat1).css({opacity: "0.4"});
		$j(cat1 + ".interest," + cat2).css({opacity: "1"});
		$j(cat2).css({ opacity: 0.4 });
		$j(cat2 + ":contains('Interest Bearing')").css({ opacity : 1 });												
		return ( false );
	});
	
	$j("#accountRefGuide a.nthChild-6").click(function () {
		$j("#accountRefGuide a").parent().removeClass("active");
		$j(this).parent().addClass("active");
		$j(cat1).css({opacity: "0.4"});
		$j(cat1 + ".overDraft," + cat2).css({opacity: "1"});
		$j(cat2).css({ opacity: 0.4 });
		$j(cat2 + ":contains('Overdraft Protection')").css({ opacity : 1 });												
		return ( false );
	});
	
	$j("#accountRefGuide a.nthChild-7").click(function () {
		$j("#accountRefGuide a").parent().removeClass("active");
		$j(this).parent().addClass("active");
		$j(cat1).css({opacity: "0.4"});
		$j(cat1 + ".minBalance," + cat2).css({opacity: "1"});
		$j(cat2).css({ opacity: 0.4 });
		$j(cat2 + ":contains('No Minimum Balance')").css({ opacity : 1 });												
		return ( false );
	});		
	
	$j('#accountRefGuide li a.nthChild-4, #accountRefGuide li.active a.nthChild-4').parent().css({display: 'none'});
													
// 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('.questionsButton a').addClass('iframe');
	
	$j(".questionsButton a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 570,
		'frameHeight': 445,
		'overlayOpacity': 0.8
	});

// online banking link in ultratopnav
	$j('#ultraTopNav li a:contains("Online Banking"), #obLoginLink a').addClass('iframe');
	
	$j("#ultraTopNav li a.iframe, #obLoginLink 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
	}); 
	
// End of Fancybox jQuery

// hide homepage noscript link
var flashLink = $j("body#homepage #mainContent > a"); 
flashLink.children().insertBefore(flashLink);  
flashLink.remove(); 


}); // END doc ready

Cufon.set("selector", jQuery);
Cufon.replace("#locations h2", { separate: "none", 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="Gibsland Bank & Trust"/>');
$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');});

