var $j=jQuery.noConflict();
var alertText = "Please be advised that you are leaving D.L. Evans Bank's website. This link is provided as a courtesy. D.L. Evans does not endorse or control the content of third party websites.";
var url=window.location.pathname;

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

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

	$j(".confirm").click( function() {						   
		if (!confirmAlert($j(this).attr('href'))){
			return false;			
		}
	});

	$j("#obLogin form ol li.text label").overlabel();
	
	$j("#homeFeaturedProducts ul li.first").hover(function () {
			$j("#homeFeatured1").stop().animate({marginLeft: "215px"}, 500)
		},
		function () {
			$j("#homeFeatured1").stop().animate({marginLeft: "0"}, 500)
		}
	);
	
	$j("#homeFeaturedProducts ul li.second").hover(function () {
			$j("#homeFeatured2").stop().animate({marginLeft: "215px"}, 500)
		},
		function () {
			$j("#homeFeatured2").stop().animate({marginLeft: "0"}, 500)
		}
	);
	
	$j("#homeFeaturedProducts ul li.third").hover(function () {
			$j("#homeFeatured3").stop().animate({marginLeft: "215px"}, 500)
		},
		function () {
			$j("#homeFeatured3").stop().animate({marginLeft: "0"}, 500)
		}
	);
	
	$j("#homeFeaturedProducts ul li, #featuredProduct, #secondaryProducts ul li").click(function(){
		window.location=$j(this).find("a").attr("href");
	});

	// FancyBox popup on apps
	$j("a#ssnWhy").fancybox({
		'frameWidth': 300,
		'frameHeight': 190
	});
	
	// Tell Me More - Send to a Friend - Calculators - provided by FancyBox
	$j('#tellMeMoreButton a').addClass('iframe');
	
	$j("#tellMeMoreButton a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 540,
		'frameHeight': 340,
		'overlayOpacity': 0.8
	});
	
	$j('#shareButton a').addClass('iframe');
	
	$j("#shareButton a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 570,
		'frameHeight': 520,
		'overlayOpacity': 0.8
	});

	if (((url.indexOf("personal/loans") != -1)) || ((url.indexOf("mortgage") != -1))) {
		$j("a[href*='financial-calculators/mortgage-loan']").addClass("iframe").parent().addClass("mortgageCalculator");
	}
	
	$j('#financialCalculators li a').not('#financialCalculators li a.lastChild').addClass('iframe');

	$j("#financialCalculators li a, .mortgageCalculator a.iframe").not('#financialCalculators li a.lastChild').fancybox({
		'hideOnContentClick': false,
		'frameWidth': 650,
		'frameHeight': 394,
		'padding': 10,
		'overlayOpacity': 0.8
	});
	// End of FancyBox jQuery
	   
	var sa = [];
	var classes = [];
	var locality = [];
	$j('#locations 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;
		locality[spot] = $j(this).find(".locality").text();
		
		sa.push( $(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('#locations ul#locList').append('<li><ul></ul></li>');
			$j('#locations ul#locList li:last').prepend('<h2>' + locality[i] + '</h2>');
		}
		$j('#locations ul#locList ul:last').append(sa.pop());
	}
	// End resort locations

	$j('#locations ul#locList>li>ul').hide();

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

	$j("#locations .hours dl dt:contains('No drive up window')").addClass("noDriveThrough");

	$j("#featuredProduct, #secondaryProducts ul li, #locations h2").hover(
		function(){
			$j(this).addClass("active");
		},
		function(){
			$j(this).removeClass("active");
		}
	);

		$j('#Logon input[name="loginTo"]').change(function() {
		if ($j(this).val() == 'Access my Account') {
        $j('form#Logon').attr('action','https://ecom1.itechcorporation.com/pbi_pbi1961/pbi1961.asp?WCI=RemoteLogin&Rt=124103582&LogonBy=Connect3');
        $j('form#Logon label[for="nmUID"]').attr('for','AccessID');
        $j('form#Logon input#nmUID').attr('name','AccessID').attr('id','AccessID');
        $j("ul#obNav li.nthChild-2").show("slow");
        $j("ul#obNav li.nthChild-1").show("slow");
		} else if ($j(this).val() == 'Business') {
        $j('form#Logon').attr('action','https://ecorp1.itechcorporation.com/EBC_EBC1961/EBC1961.ASP?WCI=Process&WCE=RemoteLogon&RID=3000&RTN=124103582&MFA=2');
				$j('form#Logon label[for="AccessID"]').attr('for','nmUID');
				$j('form#Logon input#AccessID').attr('name','nmUID').attr('id','nmUID');
        $j("ul#obNav li.nthChild-1").hide("slow");
		} else {
			$j('form#Logon').attr('action','https://ecorp1.itechcorporation.com/EBC_EBC1961/EBC1961.ASP?WCI=Process&WCE=RemoteLogon&RID=3000&RTN=124103582&MFA=2');
			$j('form#Logon label[for="AccessID"]').attr('for','nmUID');
			$j('form#Logon input#AccessID').attr('name','nmUID').attr('id','nmUID');
			$j("ul#obNav li.nthChild-1").hide("slow");
		}
	});
	

	if (url.indexOf("mortgage/government-and-minimum-down-payment-programs.html") != -1) {
		$j("body").attr("id","governmentAndMinimumDownPaymentPrograms");
	}

	if (url.indexOf("business/services") != -1) {
		$j("#productHead ul.nthTier-2 li a").html("Services");
	}

	/* target="_blank" */	
	$j("a[href*='http://']:not([href*='"+location.hostname+"']),[href*='https://']:not([href*='"+location.hostname+"'])").attr("target","_blank").attr("title","Opens new window");
});

Cufon.set("selector", jQuery);
Cufon.replace("#productHead h1, fieldset#newApplication div#introduction h1, #enrollmentAgreement h1, #landingPage p.summary span");
Cufon.replace("#homeFeaturedProducts h2, #featuredProduct h1, #newPopUpForm h1, .individualPage h1, #enrollmentAgreement h2, #ourHistory h2, #careers h2", { separate: "none" });