function _get(id) {
	return document.getElementById(id);
}

function _open(event, source)
{
	var newWindow = window.open(source);
	newWindow.focus();
	event.returnValue = false;
	return false;
}

function _urlParseQS (str) {
	str = str ? str : location.search;
	var query = str.charAt(0) == '?' ? str.substring(1) : str;
	var args = new Object();
	if (query) {
		var fields = query.split('&');
		for (var f = 0; f < fields.length; f++) {
			var field = fields[f].split('=');
			args[unescape(field[0].replace(/\+/g, ' '))] = unescape(field[1].replace(/\+/g, ' '));
		}
	}
		
	return args;
}

var mmTimeout;
var mmCurHover, mmTmpHover;

$(document).ready(function() {
	// h1 -> replace w/ image
	$("h1.h1img").each(function() {
		var h1Text =  $(this).html();
		$(this)
		// /g: global search
		.html('<img src="/images/h1/' + h1Text.toLowerCase().replace(/ /g, "") + '.jpg" alt="' + h1Text + '" />')
		.css("padding", "0");
	});
	
	// main menu hover functionality
	$("#menu li.wSub").hover(
		function () { 
			mmTmpHover = $(this).attr("id");
			if (mmCurHover == mmTmpHover)
				clearTimeout(mmTimeout); // don't hide if we're on the same menu item
			
			mmCurHover = mmTmpHover;
			$(this).find("ul.menuSub").fadeIn(300);
		}, 
		function () {
			var ulMenuHandle = $(this).find("ul.menuSub");
			mmTimeout = setTimeout(function() { hideMenuSub(ulMenuHandle);}, 300);
		}
	);

	// set new window functionality for all external links
	$("a[rel=external]").click(function(event) {
		event.preventDefault();
		
		var newWindow = window.open($(this).attr("href"));
		newWindow.focus();
	});
});

function hideMenuSub($this) {
	$this.hide();
}