function resizeWorkAreas() {
	var wh = $(window).height();
	var ww = $(window).width();
	var hh = $('header').outerHeight(true);
	var th = $('#content > h1, #content > div.grid_9 > h1').outerHeight(true) + $('#schemetabs').outerHeight(true);
	//alert(wh + ', ' + hh + ', ' + th);
	$('#help').css('max-height', wh - hh - 5);
	$('#tabpage').css('max-height', wh - hh - th - 20);
	$('#adminform').css('max-height', wh - hh - th - 20);
}

function resizeBackground() {
	var ph = $(window).height();
	var pw = $(window).width();

	asp = bg.data('h') / bg.data('w');
	pasp = ph / pw;
	
    if (pasp < asp) {
        bg.css({
            top: -0.5 * ((pw * asp) - ph),
            left: 0,
            width: pw,
            height: pw * asp
        });
    } else if (pasp > asp) {
        bg.css({
            top: 0,
            left: -0.5 * ((ph / asp) - pw),
            width: ph / asp,
            height: ph
        });
    } else {
        bg.css({
            top: 0,
            left: 0,
            width: pw,
            height: ph
        });
    }
}

$(function() {
	$(window).load(resizeWorkAreas);
	$(window).resize(resizeWorkAreas);
});

$(window).load(function() {
	bg = $('#windowbg');
	$("<img/>") // Make in memory copy of image to avoid css issues
	.attr("src", bg.attr("src"))
	.load(function() {
	    bg.data('w', this.width);   // Note: $(this).width() will not
	    bg.data('h', this.height);  // work for in memory images.
	
		resizeBackground();
		$(window).resize(resizeBackground);
    })
	/* disable img drag drop to emulate background */
	.bind("contextmenu",function(){
		return false;
	})
	.bind("mousedown",function(){
			return false;
	});
});

