// 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");
	
	// set selected navigation
	setMainNavSelected();
	setSubNavSelected();
	
	// main nav
	$("a.hoverFade span.label").before("<span class=\"normal\"></span><span class=\"hover\"></span>");
	
	$("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: 250});
			}
			
		},
		function(){
			$(this).find("span.normal").animate({opacity: 1}, {queue: false, duration: 250});
		}
	);
	
	// sub nav hover
	$("ul#sublevelNavigation li a").hover(
		function(){
			if ( $(this).hasClass("selectedSub") ) {
				// don't animate this button
			}
			else {
				$(this).find("span.normal").animate({opacity: 0}, {queue: false, duration: 250});
			}
			
		},
		function(){
			$(this).find("span.normal").animate({opacity: 1}, {queue: false, duration: 250});
		}
	);
	
	// remove border from last sub nav item
	$("ul#sublevelNavigation li:last").css({border: "none"});
	
	// assets map
	$("div#assetsListContainer ul.regions").hide();
	$("div#assetsListContainer ul.regions li:nth-child(1)").css({width: "151px", height: "22px", padding: "7px 10px 0 10px", borderRight: "1px solid #dbdbdb"});
	$("div#assetsListContainer ul.regions li:nth-child(2)").css({width: "225px", height: "22px", padding: "7px 10px 0 10px", borderRight: "1px solid #dbdbdb"});
	$("div#assetsListContainer ul.regions li:nth-child(3)").css({width: "233px", height: "22px", padding: "7px 0 0 10px"});
	
	$("div#assetsListContainer ul#headerRow li:nth-child(1)").css({width: "151px", height: "18px", padding: "0 10px 0 10px", borderRight: "1px solid #dbdbdb"});
	$("div#assetsListContainer ul#headerRow li:nth-child(2)").css({width: "225px", height: "18px", padding: "0 10px 0 10px", borderRight: "1px solid #dbdbdb"});
	$("div#assetsListContainer ul#headerRow li:nth-child(3)").css({width: "233px", height: "18px", padding: "0 0 0 10px"});
	
	$("div#assetsListContainer ul#mapTotal li:nth-child(1)").css({width: "151px", height: "22px", padding: "7px 10px 0 10px", borderRight: "1px solid #dbdbdb"});
	$("div#assetsListContainer ul#mapTotal li:nth-child(2)").css({width: "225px", height: "22px", padding: "7px 10px 0 10px", borderRight: "1px solid #dbdbdb"});
	$("div#assetsListContainer ul#mapTotal li:nth-child(3)").css({width: "233px", height: "22px", padding: "7px 0 0 10px"});
	
		$("map area").click(function(){ return false; });
		
		$("map area").hover(
			function(){ $("ul#mapTotal").animate({top: "47px"}, {queue: false, duration: 250}); },
			function(){ $("ul#mapTotal").show().animate({top: "18px"}, {queue: false, duration: 250}); }
		);
	
		// northeast
		$("area#mapNortheast").hover(
			function(){ $("ul#northEast").show().animate({top: "18px"}, {queue: false, duration: 250}); },
			function(){ $("ul#northEast").animate({top: "47px"}, {queue: false, duration: 250}); }
		);
		// mideast
		$("area#mapMideast").hover(
			function(){ $("ul#midEast").show().animate({top: "18px"}, {queue: false, duration: 250}); },
			function(){ $("ul#midEast").animate({top: "47px"}, {queue: false, duration: 250}); }
		);
		// southeast
		$("area#mapSoutheast").hover(
			function(){ $("ul#southEast").show().animate({top: "18px"}, {queue: false, duration: 250}); },
			function(){ $("ul#southEast").animate({top: "47px"}, {queue: false, duration: 250}); }
		);
		// east north central
		$("area#mapEastNorthCentral").hover(
			function(){ $("ul#eastNorthCentral").show().animate({top: "18px"}, {queue: false, duration: 250}); },
			function(){ $("ul#eastNorthCentral").animate({top: "47px"}, {queue: false, duration: 250}); }
		);
		// west north central
		$("area#mapWestNorthCentral").hover(
			function(){ $("ul#westNorthCentral").show().animate({top: "18px"}, {queue: false, duration: 250}); },
			function(){ $("ul#westNorthCentral").animate({top: "47px"}, {queue: false, duration: 250}); }
		);
		// southwest
		$("area#mapSouthwest").hover(
			function(){ $("ul#southWest").show().animate({top: "18px"}, {queue: false, duration: 250}); },
			function(){ $("ul#southWest").animate({top: "47px"}, {queue: false, duration: 250}); }
		);
		// mountain
		$("area#mapMountain").hover(
			function(){ $("ul#mountain").show().animate({top: "18px"}, {queue: false, duration: 250}); },
			function(){ $("ul#mountain").animate({top: "47px"}, {queue: false, duration: 250}); }
		);
		// pacific
		$("area#mapPacific").hover(
			function(){ $("ul#pacific").show().animate({top: "18px"}, {queue: false, duration: 250}); },
			function(){ $("ul#pacific").animate({top: "47px"}, {queue: false, duration: 250}); }
		);
		
	
	// bios
	$("ul.managementLinks li:first").css({border: "none", paddingLeft: "0px"});
	$("div.bio:last").css({border: "none"});
	
	// take over cases
	$("div.caseStudyContainer:last-child").css({border: "none"});
	$("div.caseStudyContainer div.caseStudyContent ul:last-child").css({background: "none", marginBottom: "0px"});
	
	$("div.caseStudyContainer a.caseStudyHeader").click(function(){
		
		if ( $(this).hasClass("selectedCaseStudy") )
		{
			$(this).removeClass("selectedCaseStudy");
			$(this).next("div.caseStudyContent").slideUp(500);
			return false;
		}
		else
		{
			$("div.caseStudyContainer a.caseStudyHeader").removeClass("selectedCaseStudy");
			$(this).addClass("selectedCaseStudy");
			$("div.caseStudyContainer div.caseStudyContent").slideUp(500);
			$(this).next("div.caseStudyContent").slideDown(500);
			return false;
		}
	});
	
	// right column focus areas
	$("div.focusContent:first").css({paddingTop: "0px"});
	$("div.focusContent:last").css({borderBottom: "none"});
	
	// footer links reset
	$("ul#footerLinks li a:first").css({paddingLeft: "0px"});
	$("ul#footerLinks li a:last").css({border: "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#sublevelNavigation li.sub" + pageName + " a").addClass("selectedSub");
	}
}