// 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(){
	
	// get body ID
	pageTemplate = $("body").attr("id");
	pageName = $("body").attr("className");
	
	// navigation
	setMainNavSelected();
	setSubNavSelected();
	$("ul#sublevelNavigation li:last").css({border: "none"});
	$("ul#tertiaryNavigation li:last").css({background: "none"});
	
	// home page
	$("div#intro p:last").css({margin: "0 0 10px 0"});
	$("div#longviewNews ul li:last").css({background: "none", margin: "0px"});
	
	// content focus areas
	$("div.focusArea:last").css({background: "none", margin: "0", padding: "0"});
	
	$("ul.contentLists.withDots li:first").css({backgroundPosition: "0px -1px", paddingTop: "8px"});
	
	
	// faqs
	$("div.faqContainer h3.question").toggle(
		function(){
			$("div.faqContainer h3.question").removeClass("faqHighlight");
			$(this).addClass("faqHighlight");
			$(this).next("div.answer").slideDown(200);
			return false;
		},
		function(){
			$(this).removeClass("faqHighlight");
			$(this).next("div.answer").slideUp(200);
			return false;
		}
	);
	
	// milestones
	$("div.milestoneContent:last-child").css({background: "none"});
	$("div.milestoneContent p:last-child").css({margin: "0"});
	
		// create list item for each photo
		$("div.galleryContainer ul.milestonePhotos").each(function(n){
			getSize = $(this).find("li").size();
			for( i = 0; i < getSize; i++ ){
				$(this).parent().find("ul.galleryNav").append("<li class=\"photo" + ( i + 1 ) + "\">" + ( i + 1 ) + "</li>");
			}		
		});
		
		$("div.galleryContainer ul.galleryNav li:nth-child(1)").addClass("highlight");
		
		$("div.galleryContainer ul.galleryNav li").click(function(){
			
			thisClass = $(this).attr("className");
			
			if ( $(this).hasClass("highlight") )
			{
				// disable current nav
			}
			else
			{
				$(this).closest("div.galleryContainer").find("ul.milestonePhotos li").hide();
				$(this).parent().find("li").removeClass("highlight");
				$(this).addClass("highlight");
				$(this).closest("div.galleryContainer").find("ul.milestonePhotos li." + thisClass).fadeIn();
			}
		});
	// end milestones gallery functionality
	
	
	// footer links reset
	$("ul#footerLinks li a:first").css({paddingLeft: "0px"});
	$("ul#footerLinks li a:last").css({background: "none"});
	
	// 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);
		
});


function setMainNavSelected() {
	if ( $("body#" + pageTemplate + "") ) {
		$("ul#mainNavigation li.main" + pageTemplate + " a").addClass("selectedMain");
	}
}

function setSubNavSelected() {
	if ( $("body").hasClass("" + pageName + "") ) {
		$("ul#secondaryNavigation li.sub" + pageName + " a:eq(0)").addClass("selectedSub");
	}
}