var imloaded = false;
var bodyloaded = false;
var oldbw = 0;
var oldbh = 0;
function fixbody() {
	if (!imloaded) {
		window.setTimeout("fixbody()", 50);
		return;
	}
	var w = pl.width;
	var h = pl.height;
	var bw;
	
	try {
		bw = document.body.clientWidth;
	}
	catch(e) {
		window.setTimeout("fixbody()", 100);
		return;
	}
		 // - (document.body.scrollHeight > document.body.clientHeight ? 16 : 0);
	var bh = document.body.clientHeight;
	var cn = document.body.className;
	if (document.documentElement) {
		if (document.documentElement.clientHeight > 0) bh = document.documentElement.clientHeight;
		else if (document.documentElement.offsetHeight > 0) bh = document.documentElement.offsetHeight;
		else if (window.innerHeight > 0) bh = window.innerHeight;
	}
	if (oldbw == bw && oldbh == bh) {
		if (document.getElementById("ieimg").src.indexOf(".jpg") == -1) {
		} else return;
	}
	oldbw = bw;
	oldbh = bh;
	setcookie("wall", pl.src + ";" + pl.width + ";" + pl.height, 1)
	var ncn = ((bw/bh > w/h) ? "h" : "v");
	if (!ie || iever >= 9) {
		if (cn != ncn) {
			document.body.className = ncn;
			if (document.body.style.backgroundImage.indexOf(".jpg") == -1) {
				document.body.style.backgroundImage = "url("+pl.src+")";
			}
			document.body.style.backgroundAttachment = "fixed";
		}
	} else {
		var im = document.getElementById("ieimg");
		if (ncn == "v") {
			nw = Math.ceil(w * (bh/h) + 1);
			nh = Math.ceil(h * (bh/h) + 1)
		} else {
			nw = Math.ceil(w * (bw/w) + 1);
			nh = Math.ceil(h * (bw/w) + 1);
		}
		im.style.width = nw + "px";
		im.style.height = nh + "px";
		im.style.left = Math.floor((bw - nw) / 2) + "px";
		im.style.top = Math.floor((bh - nh) / 2) + "px";
		if (im.src.indexOf(".jpg") == -1) im.src = pl.src;


	}
	if (safari) {
//		resizeBy(0,1);
//		resizeBy(0,-1);
	}
/*
	$('footer').style.display = "none";
	$('logo').innerHTML = (document.body.scrollHeight - document.body.clientHeight);
	$('footer').style.bottom = (0 - (document.body.scrollHeight - document.body.clientHeight)) + "px";
	$('footer').style.display = "block";
*/
}

var pl = new Image();
z = unescape(getcookie("wall") + "");
if (z.indexOf(";") != -1) {
	zz = z.split(";");
	if (wall != zz[0]) {
		pl.src = "/img/walls/"+wall+".jpg";
		setcookie("wall", "", 1)
	}
	else pl.src = zz[0];
	pl.width = zz[1];
	pl.height = zz[2];
	imloaded = true;
	fixbody();
} else {
//alert('1');
	pl.src = "/img/walls/"+wall+".jpg";
	pl.onload = function() { imloaded = true; fixbody() };
	
}


addevent(window, "resize", function() {
	fixbody();
});
addevent(window, "load", function() {
	fixbody();

});

