// JavaScript Document

function strStartsWith(str, test) {
	return (str.substr(0, test.length) === test);
}

$(document).ready(function(){
						   
		//new window for external links
		$('body').delegate("a","click",function() {
			var strUri = window.location.host;
			
			if(!strStartsWith(this.href, 'http://'+strUri) &&
								!strStartsWith(this.href, 'https://'+strUri) &&
								!strStartsWith(this.href, 'mailto:')
			 					) {
				event.preventDefault();
				event.stopPropagation();
				window.open(this.href, '_blank');
			}
		});
		
		/* eliminate border on first site nav link */
		$("#site_nav td:first-child").css("border", "none");
		
		/* arrow at the end of a right-justified link */
		$("a.right").append(" &gt;")
		
		/* arrow at the end of second right column link */
		$("a.right2").append(" &gt;")
		
		/* arrow at the end of a pagination next link */
		$("li.next").children().append(" &gt;")
		
		/* double arrow at the end of a pagination last link */
		$("li.end").children().append(" &gt;&gt;")
		
		/* back arrow at the start of a pagination previous link */
		$("li.previous").children().prepend("&lt; ")
		
		/* double arrow at the start of a pagination first link */
		$("li.beginning").children().prepend("&lt;&lt; ")

		/* bookend top text with quote gifs */
		$("p.toptext").prepend("<img src='/images/start_quote.gif'>");
		$("p.toptext").append("<img src='/images/end_quote.gif'>");
		
		/* bookend home top text with larger quote gifs */
		$("p.home_toptext").prepend("<img src='/images/start_quote_home.gif'>");
		$("p.home_toptext").append("<img src='/images/end_quote_home.gif'>");
		
		/* mark the current nav item with the yellow arrow */
		$("a.current").append("<img src='/images/current_marker.png' class='current_marker'>");
		
		/* enlarge one title image and shrink the other when rolling over 
		$("a.title_ld").hover( function() {
			$("a.title_ld").html('<img src="/images/title_ld_cur.png" alt="Living Downstream">');
			$("a.title_wu").html('<img src="/images/title_wu.png" alt="Walking Upstream">');
			$("div#wu_site_nav").hide();	
			$("div#ld_site_nav").show();
		});
		
		$("a.title_wu").hover( function() {
			$("a.title_ld").html('<img src="/images/title_ld.png" alt="Living Downstream">');
			$("a.title_wu").html('<img src="/images/title_wu_cur.png" alt="Walking Upstream">');
			$("div#ld_site_nav").hide();	
			$("div#wu_site_nav").show();	
		}); */

		/* cross-fade sub-nav and title replace when you click on ld title */
		$("a.title_ld").live('click', function() {	
		 	$("div#wu_site_nav").fadeOut('slow');	
			$("div#ld_site_nav").fadeIn('slow');
			$("a.title_ld").html('<img src="/images/title_ld_cur.png" alt="Living Downstream" class="title_ld_cur">');
			$("a.title_wu_cur").html('<img src="/images/title_wu.png" alt="Walking Upstream" class="title_wu">');
			$("a.title_ld").removeClass('title_ld').addClass('title_ld_cur');
			$("a.title_wu_cur").removeClass('title_wu_cur').addClass('title_wu');
			return false;
		});
		
		/* cross-fade sub-nav and title replace when you click on wu title */ 
		$("a.title_wu").live('click', function() {	
		 	$("div#ld_site_nav").fadeOut('slow');	
			$("div#wu_site_nav").fadeIn('slow');	
			$("a.title_ld_cur").html('<img src="/images/title_ld.png" alt="Living Downstream" class="title_ld">');
			$("a.title_wu").html('<img src="/images/title_wu_cur.png" alt="Walking Upstream" class="title_wu_cur">');
			$("a.title_wu").removeClass('title_wu').addClass('title_wu_cur');
			$("a.title_ld_cur").removeClass('title_ld_cur').addClass('title_ld');
			return false;
		});
		
		/* randomly choose from background images for inner pages */
		randNum = Math.floor ( Math.random ( ) * 3 + 1 );
		$("div#outerplank").css("background-image","url('/images/bg_ld"+randNum+".jpg')");

		/*$("#e2ma_signup").validationEngine();*/
});	
