var $j=jQuery.noConflict();
var message	= "You are about to leave Seattle Bank's website for that of one of our partner companies. As Seattle Bank does not control any content beyond this point, we encourage you to read the privacy and security policies of the site you are entering. Thank you for your interest in the Seattle Bank!";
var intervalID;

$j(document).ready(function(){
	var slideSpeed = 500;
	var primaryNavExpanded = false;
	
	if( $j('a.warn').length > 0 ){
		$j('a.warn').click( function(){
			alert( message );
		});
	}
	
	if( $j('a.confirm').length > 0 ){
		$j('a.confirm').click( function( event ){
			event = new Event(event);
			if( confirm(message) ) {
				return true;
			} else {
				event.stop();
				return false;
			}
		});
	}
	
	//$j('#waves').css({backgroundPosition: '(560px 15px)'});
	//Commented out just in case we ever want to use it in the future.
	/*$j('#primaryNav li.nthChild-1 a').mouseenter(
    	function () {
        	$j('#waves').stop()
				.animate({backgroundPosition: '(265px 76px)'}, 'slow')
				.animate({backgroundPosition: '(263px 74px)'}, 100)
				.animate({backgroundPosition: '(261px 72px)'}, 100)
				.animate({backgroundPosition: '(259px 70px)'}, 100)
				.animate({backgroundPosition: '(257px 68px)'}, 100)
				.animate({backgroundPosition: '(255px 66px)'}, 100);
      	}
	);
	
	$j('#primaryNav li.nthChild-2 a').mouseenter(
    	function () {
        	$j('#waves').stop()
				.animate({backgroundPosition: '(430px 76px)'}, 'slow')
				.animate({backgroundPosition: '(428px 74px)'}, 100)
				.animate({backgroundPosition: '(426px 72px)'}, 100)
				.animate({backgroundPosition: '(424px 70px)'}, 100)
				.animate({backgroundPosition: '(422px 68px)'}, 100)
				.animate({backgroundPosition: '(420px 66px)'}, 100);
      	}
	);
	
	$j('#primaryNav li.nthChild-3 a').mouseenter(
    	function () {
        	$j('#waves').stop()
				.animate({backgroundPosition: '(590px 76px)'}, 'slow')
				.animate({backgroundPosition: '(588px 74px)'}, 100)
				.animate({backgroundPosition: '(586px 72px)'}, 100)
				.animate({backgroundPosition: '(584px 70px)'}, 100)
				.animate({backgroundPosition: '(582px 68px)'}, 100)
				.animate({backgroundPosition: '(580px 66px)'}, 100);
      	}
	);
	$j('#primaryNav li.nthChild-1, #primaryNav li.nthChild-2, #primaryNav li.nthChild-3').mouseleave(
      	function () {
        	returnSwoosh();
      	}
    );*/
	

	$j('#primaryNav h2').click( function(){
		var holdThis = $j(this);
		var theHeight = $j(this).next().height() + 105;
		if( holdThis.parent().hasClass('inPath2') ){
			var toggleNav = true;
		}
	
		if(primaryNavExpanded){
			$j('#primaryNav li').removeClass("inPath2");
			$j('#primaryNav li ul').slideUp(slideSpeed);
			if( !toggleNav ){
				$j('#waves').stop().animate({ height : theHeight + "px" }, slideSpeed);
				holdThis.next().slideDown(slideSpeed);
				holdThis.parent().addClass("inPath2");
			}
			else{
				$j('#waves').stop().animate({ height : "99px" }, slideSpeed);
			}
		}
		else{
			$j('#waves').stop().animate({ height : theHeight + "px" }, slideSpeed);
			holdThis.next().slideDown(slideSpeed);
			holdThis.parent().addClass("inPath2");
			primaryNavExpanded = true;
		}
		if( $j(holdThis).children('a').text() != 'Ambassador Club'){
			return false;
		}
	});
	
	if( $j('#obLogin h3').length > 0){
		$j('#obLogin h3').after('<h3 class="notActive">Business</h3>');
		$j('#obLogin h3').click( function(){
			if( $j(this).hasClass('notActive') ){
				$j(this).removeClass('notActive').prev().addClass('notActive');
				$j(this).next().addClass('notActive');
				$j('#obLogin form').hide().fadeIn('slow');
			}
		});
	}
	
	if( $j('#seattleSwitch img').length > 0){
		$j('#seattleSwitch img').after('<img src="/custom/seattlebank/image/UChoose-Rewards.jpg" alt="Check your UChoose Rewards!" />');
		$j('#seattleSwitch img:eq(1)').hide();
		intervalID = setInterval( function(){seattleSwitch();}, 8000 );
	}
	
	$j('#olbLogin').submit( function(){
		$j('#hiddenT').attr('value', $j('#userID').attr('value'));
		$j('#userID').attr('value', '');
		return true; 
	});
});

function returnSwoosh(){
	$j('#waves').stop().animate({ backgroundPosition : '(560px 15px)' }, 'slow');
}

function seattleSwitch(){
	var whichImage = $j('#seattleSwitch img').attr('src');
	if( whichImage.indexOf('UChoose-Rewards') != -1 ){
		$j('#seattleSwitch').animate({width: 'toggle'}, 500, function(){
			$j(this).children('img').attr('src', '/custom/seattlebank/image/switchToSeattleBank.jpg').parent().attr({href: '/personal/switch-kit.html'}).animate({width: 'toggle'}, 500);
		});
	}
	else{
		$j('#seattleSwitch').animate({width: 'toggle'}, 500, function(){
			$j(this).children('img').attr('src', '/custom/seattlebank/image/UChoose-Rewards.jpg').parent().attr({href: 'https://www.uchooserewards.com/members/home.php?sid=40XXdKrlo40&popup=t'}).animate({width: 'toggle'}, 500);
		});
	}
}

$j(document).ready(function(){
	if( $j('ul#sitemapNav').length > 0 ){
		$j('ul#sitemapNav').columnize({ columns: 2 });
	}
});