
// 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(){
	
	// set all links with rel="external" to open in a new window
	$("a[rel=external]").click(function(){window.open(this.href); return false});
	
	// start home page featured projects
	var currentProject = 1;
	var totalProjects = $('div.features').length;
		
	$("div#focusFeaturedProjects h2 a#nextProject").click(function(){
		if( currentProject == totalProjects ){
			$("div.features").hide();
			$("div#feature1").fadeIn(500);
			currentProject = 1;
		} else {
			currentProject++
			$("div.features").hide();
			$("div#feature" + currentProject).fadeIn(500);
		}
		return false;
	});
	$("div#focusFeaturedProjects h2 a#previousProject").click(function(){
		if( currentProject == 1 ){
			currentProject = totalProjects;
			$("div.features").hide();
			$("div#feature" + totalProjects).fadeIn(500);
		} else {
			currentProject--
			$("div.features").hide();
			$("div#feature" + currentProject).fadeIn(500);
		}
		return false;
	});
	// end home page featured projects
	
	
	
	// contact list
	$("table#contactListTable tr:even").css({backgroundColor: "#e5e5e5"});
	$("table#contactListTable tr:even").addClass("evenRows");
	$("table#contactListTable tr:odd").addClass("oddRows");
	$("table#contactListTable tr th:nth-child(1)").css({paddingLeft: "10px"});
	$("table#contactListTable tr td:nth-child(1)").css({paddingLeft: "10px"});
	$("table#contactListTable tr th:nth-child(4)").css({background: "none"});
	$("table#contactListTable tr td:nth-child(4)").css({background: "none"});
	
	
	// set position of rightFocus icon
	setIconPosition();
	
	// set year in footer
	setYearInFooter();
});

function setIconPosition(){
	var rightFocusHeight = $("div.rightFocus").height();
	var lessHalfIconHeight = $("div.focusIcon").height() / 2;
	var cutInHalf = (rightFocusHeight / 2) - lessHalfIconHeight
	$("div.focusIcon").css({top: "" + cutInHalf + "px"});
}

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

/* centered pop up window */
function centeredPopUpWindow(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(); }
}

