// 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(); }
}

// 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;
	}
}

// set date elements
var yy = new Date().getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
var dd = new Date().getDate();
var mm = new Array("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december");
var monthNumber = new Date().getMonth();
var monthLabel = mm[monthNumber];

// check dimensions of browser window
var windowWidth = $(window).width();
var windowHeight = $(window).height();
var halfWindowWidth = windowWidth / 2;
var halfWindowHeight = windowHeight / 2;

// get class name of element
$.fn.getClassNames = function(){
	if (name = this.attr("className")) {
		return name.split(" ");
	}
	else {
		return [];
	}
};
// get name of element
$.fn.getElementNames = function(){
	if (elementName = this.attr("name")) {
		return elementName.split(" ");
	}
	else {
		return [];
	}
};


$(document).ready(function(){

	// home page slideshow
	if ( $("body").hasClass("templateHome") ){
		homePageSlideShow();
	}
	// randomize home page photos
	if ( $("body").hasClass("templateHomeRefresh") ){
		var photoDisplay = Math.floor(Math.random()*3) + 1;
		$("div#mainPhoto div#photo" + photoDisplay).show();
	}
	
	// links with rel="external" will open in a new window
	$("a[rel=external]").click(function(){
		 window.open(this.href);
		 return false;
	});
	
	// display year in footer
	$("span.currentYear").text(year);
	
			
});


// simple delay function for home page slide show
function delay(countDown){
	$("div#mainPhoto div").animate({fontSize: 0}, countDown);
}

// simple home page slide show
function homePageSlideShow(){
	delay(4500);
	$("div#mainPhoto div:eq(1)").fadeIn(1500);
	delay(5500);
	$("div#mainPhoto div:eq(2)").fadeIn(1500);
}
