$(document).ready(function() {
	$("a[ref^='popup']").click(function(event) {
		ref = $(this).attr("ref").split(/\|/);
		popUp($(this).attr("href"), ref[1], ref[2]);
		event.preventDefault();
	});
	$("a[ref^='blank']").click(function(event) {
		openPage($(this).attr("href"));
		event.preventDefault();
	});
	$("a[lang]").click(function(event) {
		$("form#quick_language_form").attr("action", $(this).attr("href"));
		$("form#quick_language_form input#quick_language").val($(this).attr("lang"));
		$("form#quick_language_form").submit();
		event.preventDefault();
	});
});

function popUp(url, width, height) {
	popWin = window.open(url, "popWin", "width=" + width + ", height=" + height + ", scrollbars=no, status=no, resizable=no, location=no");
	popWin.focus();
}

function openPage(url) {
	newWin = window.open(url, "newWin");
	newWin.focus();
}

function loadPage(page)
{
	// handle home page redirection
	if ( page == "" || typeof(page) == "undefined" ) {
		location.href = $("#header #logo a").attr('href');
		return true;
	}
	var target = $("ul[id^=menu] li a[href$="+page+"]");
	if ( $(target) && $(target).attr('ref') && $(target).attr('ref') != "" ) {
		$(target).click();
	}
	else {
		location.href = $(target).attr('href');
	}
}
