// JavaScript Document

function recalc_iframe_height(par)
{
  var iframe = par?par:document.getElementById('ArticleFrame');
  if (iframe) {
    iframe.height=563;
    iframe.height=iframe.contentWindow.document.body.scrollHeight+10;
  }
}

$(document).ready( function() {
	
	highlightNav();
	initHeaderRollovers();
	if ($("div#home").size()) $("div#home ul").cycle();
	initPopups();
	initDayInLife();
	initToggle();
	
	});


function highlightNav() {
	
	var menu = $("#leftnav ul");
	menu.find("li").addClass("hidden_item");
	
	var fileName = location.pathname;
	
	var menuItems = $("#leftnav ul li a");
	
	menuItems.each( function() {
		var thisItem = $(this);
		if (thisItem.attr("href") == fileName) {
			thisItem.parent().toggleClass("active_item").toggleClass("hidden_item").parents("li").toggleClass("hidden_item");
			}
		});
	
	}
	
function initHeaderRollovers() {
	
	var menuItems = $("#topnav_right li a");
	var text = $("#topnav_left");
	
	menuItems.mouseover( function() {
		text.text($(this).text()).css({visibility: "visible"});
		});
	
	menuItems.mouseout( function() {
		text.css({visibility: "hidden"});
		});
	
	}
	

function initPopups() {
	// get all elements with class="new_window" (*** do NOT specify <a> only as <area> can also be used ***)
	$("a.new_window, area.new_window").each( function() {
		// update the title string
		this.title ? this.title += " (this link will open in a new browser window)" : this.title = "This link will open in a new browser window";
		$(this).click( function() {
			popup(this.href);
			return false;
			});
		});
	}

function popup(url) {
	// open url in new window, focus and return false to cancel underlying link element action
	var win = window.open(url, "Arcadia_popup");
	// focus on the window in case it's already open
	win.focus();
	}
	
function initDayInLife() {
	
	staff = $("#day_in_life_staff");
	
	if (! staff.size()) return;
	menu = $("<ul>");
	
	menu.insertAfter(staff);

	staff.cycle ({ 
		fx: "fade",
		speed: 500,
		timeout: 0,
		pager: menu, 
		pagerEvent: "click",
		pagerAnchorBuilder: buildDayInLifeMenu
		});

	}
	
function buildDayInLifeMenu(index, DOMElement) {
	var profiles = $("#day_in_life_staff").find("div");
	var person = $(profiles.get(index));
	var text = person.find("h3").text();
	return $("<li><a href=\"#\" title=\"" + text + "\" class=\"thumb_" + (index + 1) + " replace\">" + text + "</a></li>");
	}
	
function initToggle() {
	
	var els = $(".toggle_detail");
	var divs = els.find("div").hide();
	
	els.click( function() {
		var div = $(this).find("div");
		divs.each( function() {
			if ($(this) != div) $(this).slideUp();
			});
		div.stop().slideDown();
		});

	}

