/**
 * Cast the bless spell on donkey 6-
 * Fix PNG transparency, background image cache and hover on dl in main menu as well as first dd element styling
 */

var blank = new Image();
blank.src = '/school/img/spacer.gif';

$(document).ready(function() {
	var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
	if (badBrowser) {
		$('img[class=png]').each(function() {
			if (!this.complete) {
				this.onload = function() { fixPng(this) };
			} else {
				fixPng(this);
			}
		});

		try {
			document.execCommand("BackgroundImageCache", false, true);
		} catch(err) {}

		$('#menu li dl').hover(
			function () {
				$(this).toggleClass('hover');
			},
			function () {
				$(this).toggleClass('hover');
			}
		);

		$('#menu dt + dd').addClass('first');
	}
});

function fixPng(png) {
	var src = png.src;
	if (!png.style.width) { png.style.width = $(png).width(); }
	if (!png.style.height) { png.style.height = $(png).height(); }
	png.onload = function() { };
	png.src = blank.src;
	png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}

function changeHomeCity(id) {
	var params = window.location.search;
	if (params == "") {
		params = "?home=" + id;
	} else {
		params += "&home=" + id;
	}
	window.location.href = window.location.pathname + params;
}

function popup(obj, width, height, title) {
	var x = Math.round((screen.availWidth - width) / 2),
	    y = Math.round((screen.availHeight - height) / 2);
	var scrollbars = 0;
	
	if (x < 0) x = 0;
	if (y < 0) y = 0;
	
	if (width > screen.availWidth) width = screen.availWidth, scrollbars = 1;
	if (height > screen.availHeight) height = screen.availHeight, scrollbars = 1;
	
	var wnd = window.open("", "popup", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + scrollbars + ",resizable=0,copyhistory=0,width=" + width + ",height=" + height + ",top=" + y + ",left=" + x);
	wnd.document.open();
	wnd.document.write("<html><head><title>" + title + "</title></head><body bgcolor=#fff leftmargin=0 topmargin=0 marginheight=0 marginwidth=0><a href='javascript:window.close()'><img src='" + obj.href + "' border=0></a></body></html>");
	wnd.document.close;
	wnd.focus();
	
	return false;
}

