
/* centered popUp window */
function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

// get position of child node
function getPosition(main,spec) {
	var items = main.getElementsByTagName(spec.tagName);
	var found = 0;
	for (p = 0; p < items.length; p++) {
		if (items[p] == spec) {
			found = 1;
			break;
		}
	}
	if (found) {
		return p;
	}
	else {
		return -1;
	}
}

$(document).ready(function(){

// add page navigation to multiple
	addPageNavigation();
	
		
// our leadership pages
	
	$("a#bioPrevious").click(function(){
		if ( $(this).hasClass("inactiveArrow") )
		{
			return false;
		}
		else
		{
			$("a.bioArrow").removeClass("inactiveArrow");
			$(this).addClass("inactiveArrow");
			$("ul#leadershipThumbs").animate({marginLeft: "0px"}, 250);
			return false;
		}
	});
	
	$("a#bioNext").click(function(){
		if ( $(this).hasClass("inactiveArrow") )
		{
			return false;
		}
		else
		{
			$("a.bioArrow").removeClass("inactiveArrow");
			$(this).addClass("inactiveArrow");
			$("ul#leadershipThumbs").animate({marginLeft: "-63px"}, 250);
			return false;
		}
	});
	
	$("ul#leadershipThumbs li").click(function(){
		
		var leadershipPosition = getPosition(this.parentNode,this);
		
		$("ul#leadershipThumbs li a").removeClass("leaderHighlight");
		$(this).find("a").addClass("leaderHighlight");
		
		$("ul#leadershipThumbs li a").css({backgroundPosition: "0px 0px"});
		$(this).find("a").css({backgroundPosition: "0px -64px"});
		$("div.contentPages").hide();
		$("div#content" + (leadershipPosition + 1)).fadeIn(750);
		
		return false;
		
	});
	
// show/hide background photography
	$("div#viewBackground a").toggle(
		function(){
			$(this).text("show content");
			$("div#viewBackground").removeClass("defaultBG");
			$("div#viewBackground").addClass("showContentBG");
			$("div#footer").animate({opacity: 0}, 100);
			$("div#contentContainer").animate({
					marginTop: "-800px",
					marginLeft: "-962px"
				}, 1000);
			return false;
		},
		function(){
			$(this).text("view background");
			$("div#viewBackground").removeClass("showContentBG");
			$("div#viewBackground").addClass("defaultBG");
			$("div#footer").animate({opacity: 1}, 800);
			$("div#contentContainer").animate({
					marginTop: "0px",
					marginLeft: "0px"
				}, 1000);
			return false;
		}
	);	


// shut off last border on portfolio section list
$("div#portfolioProjectList div.project:last").css({border: "none"});
	
$("div.formRow input").focus(function(){ $(this).css({background: "#7a7a7a"}); });
$("div.formRow select").focus(function(){ $(this).css({background: "#7a7a7a"}); });
$("div.formRow textarea").focus(function(){ $(this).css({background: "#7a7a7a"}); });
$("div.formRow input").blur(function(){ $(this).css({background: "#666666"}); });
$("div.formRow select").blur(function(){ $(this).css({background: "#666666"}); });
$("div.formRow textarea").blur(function(){ $(this).css({background: "#666666"}); });

// form helpers

	$("div.formRow input").focus( function(){ $("div.formHelper").hide(); });
	$("div.formRow textarea").focus( function(){ $("div.formHelper").hide(); });
 
	$("div.withHelper input").focus(
		function(){
			$("div.formHelper").hide();
			$(this).prev("div.formHelper").fadeIn(500);
		}
	);
	
	$("div.formRow input").blur( function(){ $("div.formHelper").fadeOut(500); });

// set year in footer (for print)
	setYearInFooter();
});

function addPageNavigation()
{
	currentPage = 0;
	totalPages = $("div.contentPages").length;
	
	for ( addPages=0; addPages < totalPages; addPages++ )
	{
		$("ul#pagination").append("<li class=\"pages\">" + ( addPages + 1 ) + "</li>");
	}
	
	$("ul#pagination").prepend("<li class=\"pages pagesLabel\">Page:</li>");
	$("ul#pagination li.pages:eq(1)").addClass("pageHighlight");
	
	$("ul#pagination li").click(function(){
		
		if ( $(this).hasClass("pagesLabel") || $(this).hasClass("pageHighlight") )
		{
			// do nothing
			return false;
		}
		else
		{
			pageNumber = getPosition(this.parentNode,this)-1;
			currentPage = pageNumber;		
		
			$("div.contentPages").hide();
			$("div.contentPages:eq(" + pageNumber + ")").fadeIn(750);
			$("ul#pagination li").removeClass("pageHighlight");
			$(this).addClass("pageHighlight");
			$("a#continueReading").removeClass("inactive");
			
			// deactivate continue reading link when on last page of content
			if ( pageNumber == totalPages - 1 )
			{
				$("a#continueReading").addClass("inactive");
			}
		}
		
	});
	
	$("a#continueReading").click(function(){
		
		if ( $(this).hasClass("inactive") )
		{
			// do nothing
			return false;
		}
		if ( currentPage == ( totalPages - 2 ) )
		{
			currentPage++
			$(this).addClass("inactive");
			$("div.contentPages").hide();
			$("ul#pagination li").removeClass("pageHighlight");
			$("div.contentPages:eq(" + ( totalPages - 1 ) + ")").fadeIn(750);
			$("ul#pagination li:last").addClass("pageHighlight");
			return false;
		}
		else if ( currentPage == ( totalPages - 1 ) )
		{
			$(this).addClass("inactive");
			$("div.contentPages").hide();
			$("div.contentPages:eq(" + ( totalPages - 1 ) + ")").fadeIn(750);
			$("ul#pagination li:last").addClass("pageHighlight");
			return false;
		}
		else
		{
			currentPage++;
			$("div.contentPages").hide();
			$("ul#pagination li").removeClass("pageHighlight");
			$("ul#pagination li:eq(" + (currentPage + 1) + ")").addClass("pageHighlight");
			$("div.contentPages:eq(" + currentPage + ")").fadeIn(750);
			return false;
		}
	});
		
	// shut off border on last page
	$("ul#pagination li:last").addClass("noBorder");

	// don't do anything when the 'page' label is clicked
	$("ul#pagination li#pagesLabel").click(function(){ return false; });
	
}
 
function showContent(ID){
	$("div.contentPages").hide();
	$("div#content" + ID).fadeIn(1000);
}

function setYearInFooter(){
	var yy = new Date().getYear();
	var year = (yy < 1000) ? yy + 1900 : yy;
	$("span.yearWrapper").text(year);
}
