// centered pop up window
// <a href="filename.htm" onclick="centeredPopUpWindow(this.href,'windowname','600','400','yes'); return false;">sample popup</a>
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;
	}
}

// get current year
var yy = new Date().getYear();
var year = (yy < 1000) ? yy + 1900 : yy;

// header text replacements
Cufon.replace('h1', { color: '#203342', textShadow: '0 2px 2px 0 #dfe1e3' });
Cufon.replace('h1 span', { color: '#ffffff', textShadow: '0 2px 2px 0 #dfe1e3' });
Cufon.replace('h2', { color: '#203342' });
Cufon.replace('h3', { color: '#697c8b' });

$(document).ready(function(){
	
	// get body ID
	section_label = $("body").attr("id");
	
	// set selected navigation
	setMainNavSelected();
	setFooterNavSelected();
	
	// set fading hover elements
	$("a.hoverFade span.label").before("<span class=\"normal\"></span><span class=\"hover\"></span>");
	
	cssResets();
	mainNavHover();
		
	// select input text on click
	$("input").click(function(){$(this).select();});
	
	// 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);
	

}); // <-- $(document).ready


// check the body id and set the matching main navigation item in its selected state
function setMainNavSelected() {
	if ( $("body#" + section_label + "") ) {
		$("ul#mainNavigation li." + section_label + " a").addClass("selectedMain");
	}
}
// check the body id and set the matching footer navigation item in its selected state
function setFooterNavSelected() {
	if ( $("body#" + section_label + "") ) {
		$("ul#footerNav li.footer" + section_label + " a").addClass("selectedFooter");
	}
}

// fading hover treatment on main navigation
function mainNavHover()
{
	$("ul#mainNavigation li a").hover(
		function(){
			if ( $(this).hasClass("selectedMain") ) {
				// don't animate this button
			}
			else {
				$(this).find("span.normal").animate({ opacity: 0 }, { queue: false, duration: 150 });
			}	
		},
		function(){
			$(this).find("span.normal").animate({ opacity: 1 }, { queue: false, duration: 150 });
		}
	);
}


// css resets
function cssResets()
{
	$("div#footer ul#footerNav li:first").addClass("firstFooter");
	$("div#footer ul#footerNav li:last").addClass("lastFooter");
	$("ul.subjectIconList li:last-child").addClass("noBorder");
}

