// get position of child node
// var snoogans = getPosition(this.parentNode,this);
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;
	}
}

// current year
var yy = new Date().getYear();
var year = (yy < 1000) ? yy + 1900 : yy;

$(document).ready(function(){
	
	secondaryNavigation();
	positionFooter();
	cssResets();
	
	// 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; });
	
	// write current year in footer
	$("span.current-year").text(year);
	
});

function cssResets()
{
	$("div#left-column div.bio:last").css({background: "none"});
}


function secondaryNavigation()
{
	// when a navigation item is in it's seleced state (.selected-secondary)
	// turn off previous items bottom-border
	var body_id = $("body").attr("id");
	if ( body_id == "section-investor-relations" )
	{
		// do nothing
	}
	else
	{
		$("ul#secondary-navigation li.selected-secondary").prev("li").css({borderBottom: "none"});
	}
}


function acquisitionContactsMap()
{

	$("div#contacts-map img.map-hover").css({ opacity: 0 }).show();
	
	$("area.blue").hover(
		function()
		{
			$("div#contacts-map img.map-blue").animate(
				{opacity: 1},
				{
					queue: false,
					duration: 250,
					easing: "easeInSine"
				}
			);
		},
		function()
		{
			$("div#contacts-map img.map-blue").animate(
				{opacity: 0},
				{
					queue: false,
					duration: 250,
					easing: "easeInSine"
				}
			);
		}
	);
	
	$("area.green").hover(
		function()
		{
			$("div#contacts-map img.map-green").animate(
				{opacity: 1},
				{
					queue: false,
					duration: 250,
					easing: "easeInSine"
				}
			);
		},
		function()
		{
			$("div#contacts-map img.map-green").animate(
				{opacity: 0},
				{
					queue: false,
					duration: 250,
					easing: "easeInSine"
				}
			);
		}
	);

}


function propertyDetailsTable()
{
	
	// property portfolio navigation
	$("ul.link-list-arrow li").click(function(){
		
		$("table.property-details").hide();
		var nav_position = getPosition(this.parentNode,this);
		$("table.property-details:eq(" + nav_position + ")").fadeIn();
		
		$("ul.link-list-arrow li").removeClass("selected-state");
		$(this).addClass("selected-state");
		
		// adjust table header label
		selected_state_text = $("ul.link-list-arrow li.selected-state a").text();
		$("p#state-label span").text(selected_state_text);
		
		return false;
		
	});

	// table row striping, removing dots from first data row
	$("table.property-details tr:nth-child(2)").addClass("row-one");
	$("table.property-details tr:nth-child(2n-1)").addClass("even");
		
}


// if window is taller than the content, position the footer to the bottom of the window
function positionFooter()
{
	var footer_height = $("div#footer-container").height();
	var page_height = $("div#envelope").height();
	var adjusted_page_height = page_height + footer_height;
	var screen_height = $(window).height();
	
	// alert(page_height + " // " + adjusted_page_height + " // " + screen_height);
	
	if ( adjusted_page_height > screen_height )
	{
		// do nothing
	}
	else
	{
		// position the footer to the bottom of the window
		$("div#footer-container").css({position: "absolute", bottom: "0px"});	
	}
	
}
