/*jslint browser: true, eqeqeq: true, undef: true */
/*global $, window */
/******************************************************************************
Lines above are for jslint, the JavaScript verifier.
http://www.jslint.com/
******************************************************************************/

// This is the global JS file for the Galen College website (2008 redesign)

// global vars
var popupWin;
var scrnwidth = screen.width;
var scrnheight = screen.height;

function flashFixer() {
	var i;
	var theObjects = document.getElementsByTagName("object");
	for (i = 0; i < theObjects.length; i++) {
		theObjects[i].outerHTML = theObjects[i].outerHTML;
	}
}

/******************************************************************************
 "only 1 open at a time" popup function.

The fifth argument, windowname, is optional.  If specified, it is passed
as the second argument to window.open().  This is required in order to
leave the popup opener page (without closing the popup), come back to
it, and NOT have a duplicate popup window.

******************************************************************************/
function openPopUp (url, width, height, addloptions, windowname) {
	if (windowname === null) {
		windowname = "";
	}

	var xspot = Math.round((scrnwidth/2)-(width/2));
	var yspot = Math.round((scrnheight/2)-(height/2)-30);

	var features = "height=" + height + ",width=" + width +
		",top=" + yspot + ",screenY=" + yspot +
		",left=" + xspot + ",screenX=" + xspot;
	
	if (addloptions && addloptions !== "") {
		features += "," + addloptions;
	}
	
	if (!popupWin || popupWin.closed) {
		popupWin = window.open(url, windowname, features);
	} else {
		window.popupWin.close();	
		popupWin = window.open(url, windowname, features);
	}
}

/******************************************************************************
If one of the links in the left nav is the page you're on, highlight it.
******************************************************************************/
$(document).ready(function () {
	if ($("#left-nav").length < 1) {
		return;
	}
	if ($("#left-nav a.selected").length >= 1) {
		return;
	}
	var this_page_href =
		window.location.pathname.replace(/\/index\.[a-z]+$/, "/");
	$("#left-nav a").each(function () {
		var $this = $(this);
		var href = $this.attr("href");
		href = href.replace(/\/index\.[a-z]+$/, "/");
		if (href === this_page_href) {
			$this.addClass("selected");
			return false; // stops loop
		}
	});
});

