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

$j(document).ready( function() {
	
	// This will round the corner for any image with the class of .teamMemeberImage instead of having to use the comp to make the images round. 
	if( $j('.teamMemberImage').length > 0 ){
		$j(".teamMemberImage").each(function() { 
			$j(this).wrap('<div class="roundedImage" />');
			var imgSrc = $j(this).attr("src");
			$j(this).parent()
			.css("background-image", "url(" + imgSrc + ")")
			.css("background-repeat","no-repeat")
			.css("height", "152px")
			.css("width", "228px");
			$j(this).remove();
		});
	}

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

// primaryNav
	if ($j.browser.msie && !($j.browser.version.substr(0,1) < 7) || !($j.browser.msie)){
		$j('#primaryNav li a').blend();
	}

// clickable containers
	$j("li.featuredContainer, li.featuredContainerLastChild, #featuredProduct, #secondaryProducts li, #locations ul#locList li").click(function(){
	window.location=$j(this).find("a").attr("href");
	});
	
	$j("li.featuredContainer a, li.featuredContainerLastChild a").css({textDecoration: "none"});
	
//container hovers
	$j("li.featuredContainer, li.featuredContainerLastChild")
	.css( {backgroundPosition: "0 0"} )
	.mouseover(function(){
		$j(this).stop().animate(
			{backgroundPosition:"(0 -275px)"}, 
			{duration:400})
			.addClass("hover")
		})
	
	.mouseout(function(){
		$j(this).stop().animate(
			{backgroundPosition:"(0 0)"}, 
			{duration:400})
			.removeClass("hover")
		}) 
	
	
	$j("#secondaryProducts ul li").hover(
		function(){
			$j(this).addClass("hover");
			Cufon.replace("#secondaryProducts ul li.hover h2 a", { separate: "none" });
		},
		function(){
			$j(this).removeClass("hover");
			Cufon.replace("#secondaryProducts ul li h2 a", { separate: "none" });
		}
	);
	
	$j("#secondaryProducts ul li:only-child").css({borderBottom: "1px solid #C8C4C1"});
	
	$j("#featuredProduct").hover(
		function(){
			$j(this).addClass("hover");
			Cufon.replace("#featuredProduct h1", { separate: "none" });
		},
		function(){
			$j(this).removeClass("hover");
			Cufon.replace("#featuredProduct h1", { separate: "none" });
		}
	);

	$j('ul#leftNav ul.nthTier-2').hide().delay(500).slideDown('slow');	
	$j('ul#leftNav li:has(ul.nthTier-2)').addClass('hasUl');
	
// PAGE Specific
	$j('#news.individualPage h2:first, #executiveTeam.individualPage h2:first').css({borderTop: '0', margin: '0', padding: '0'});
	$j('#locList .hours dt:empty').parent().prev('h3').hide();
	


// obl forms
	//$j('#obLogin').wrapInner('<div class="obLoginInner"></div>');
	$j('#obLogin input.form1, #obLogin input#password, #obLogin input#BusinessPassword').val("");
	$j('label.overlabel').css({display: 'block'}).overlabel();
	
	if ($j.browser.msie && !($j.browser.version.substr(0,1) < 7) || !($j.browser.msie)){
		
		$j('#businessLoginForm, #obLogin h3').hide();
		$j('#obLogin select#oblChoice').css({display: 'block'});
		$j('#obLogin #personalLoginForm').css({width: 295, position: "absolute", top: 3, left: 280, margin: 0});
		$j("#obLogin #businessLoginForm").css({width: 295, position: "absolute", top: 3, left: 280, margin: 0});
		$j("#businessBanking").hide();
		
		$j("select#oblChoice").change(function(){							   
			if ($j(this).attr("value") == "Personal Banking" || $j(this).attr("value") == "Select Login" || $j(this).attr("value") == "Business Banking") {
					$j("#businessLoginForm").hide("slow");
					$j("#personalLoginForm").show("slow").css({width: 295, position: "absolute", top: 3, left: 280, margin: 0});
					$j("#oblPopup #personalLoginForm").show("slow").css({width: 295, position: "absolute", top: 20, left: 30, margin: 0});
			}
			/*else if ($j(this).attr("value") == "Business Banking"){
				$j("#businessLoginForm").show("slow").css({width: 295, position: "absolute", top: 3, left: 280, margin: 0});
				$j("#oblPopup #businessLoginForm").show("slow").css({width: 295, position: "absolute", top: 20, left: 30, margin: 0});
				$j("#personalLoginForm").hide("slow");
			}*/
		});
		
	}
	
// obl popup	
	$j('#oblPopup #businessLoginForm').hide();
	
	$j("#oblPopup select#oblChoice").change(function(){							   
			if ($j(this).attr("value") == "Personal Banking" || $j(this).attr("value") == "Select Login" || $j(this).attr("value") == "Business Banking") {
					$j("#businessLoginForm").hide("slow");
					$j("#oblPopup #personalLoginForm").show("slow").css({width: 295, position: "absolute", top: 20, left: 30, margin: 0});
			}
			/*else {
				$j("#oblPopup #businessLoginForm").show("slow").css({width: 295, position: "absolute", top: 20, left: 30, margin: 0});
				$j("#personalLoginForm").hide("slow");
			}*/
		});
	
	//$j('#businessDownstreamOBL #oblPopup #businessLoginForm').css({display: 'block'});
	//$j('#businessDownstreamOBL #oblPopup #personalLoginForm').hide();
	
	$j("#secondaryProducts h2 a").mouseover(function(){
		Cufon.replace("#secondaryProducts h2 a:hover", { separate: "none" });
		}
	);
	$j("#secondaryProducts h2 a").mouseout(function(){
		Cufon.replace("#secondaryProducts h2 a", { separate: "none" });
		}
	);
	
	
// fancybox popup on apps
	$j("a#ssnWhy").fancybox({
		'frameWidth': 300,
		'frameHeight': 190
	});
	
// Tell Me More - Calculators - OBL Popup provided by FancyBox 
	$j('#tellMeMoreButton a').addClass('iframe');
	
	$j("#tellMeMoreButton a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 570,
		'frameHeight': 445,
		'overlayOpacity': 0.8,
		'padding': 0
	});

// 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,
		'padding': 0
	});
	
// change to business online banking link
	if ((url.indexOf("business/") != -1)) {
		$j("#ultraTopNav li a.iframe").attr("href", "/business-downstream-obl.html");
	}

	$j('#financialCalculators li a').addClass('iframe');

	$j("#financialCalculators li a").fancybox({	
		'hideOnContentClick': false,
        'frameWidth': 650,
        'frameHeight': 394,
        'padding': 0,
        'overlayOpacity': 0.8
	}); 

// target="_blank"
	$j("a[href*='http://']:not([href*='"+location.hostname+"']),[href*='https://']:not([href*='"+location.hostname+"'])")
	.attr("target","_blank").attr("title","Opens new window");
	
	$j("a[href*=.pdf]").click(function(){
		window.open(this.href);
		return false;
	});

	
	$j("select#oblChoice, #oblPopup select#oblChoice").change(function(){							   
		if ($j("select#oblChoice option:selected, #oblPopup select#oblChoice option:selected").attr("value") == "Cash Management") {
			if ($j.browser.msie && !($j.browser.version.substr(0,1) == 7) || !($j.browser.msie)){
				window.open("https://www.newdominionbankonline.com/onlineserv/CM/");
			}
			else{
				location.href = "https://www.newdominionbankonline.com/onlineserv/CM/";
			}
		}
	});

// 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("#featuredProduct h1, #secondaryProducts h2 a, #productSummary #productHead h1, .individualPage h1.pageHead, .individualPage h1, #contactUs.individualPage h2, #breadCrumbs ul h2, #breadCrumbs ul h3", { 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="BANK NAME"/>');
$j('#footer #firstROI').after('<img class="froiLogo" src="/custom/' + customFolder + '/image/firstroi-logo.png" alt="First ROI"/>');*/
