/**
 * skrypty dodatkowe
 */

function windowHeight() {
	return self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0
}

function $id(id){
	if (typeof id == 'string'){
		return document.getElementById(id);
	}
	return id;
}

function getY(o){
	var y = 0;
	if (o.offsetParent) {
		while (o.offsetParent) {
			y += o.offsetTop;
			o = o.offsetParent;
		}
	}
	return y;
}

function footer() {
	var h = windowHeight();
	var footer = $id('footer');
	var bottom = getY($id('bottom'));
	var fh = footer.clientHeight || footer.offsetHeight // todo: why does IE report 0 for clientHeight?
	//alert("bottom: "+bottom+", h: "+h+", footer.style.marginTop: "+footer.style.marginTop);
	if (bottom != 0) {
		if (bottom < h - fh){
			footer.style.marginTop = ((h - fh)-bottom-3)+'px';
		} else {
			footer.style.marginTop = 0;
		}
	}
	footer.parentNode.style.visibility = 'visible'
}

function toggleLoginBar(){
	var bar = $id('login-form');
	if(window.Effect){
		if(bar.style.display == 'none')
			{Effect.Appear(bar); return false;}
		else
			{Effect.Fade(bar); return false;}
	}else{
		var replydisplay=bar.style.display ? '' : 'none';
		bar.style.display = replydisplay;
	}
}

function fetchImage(req, val){
	if(req == "request"){
		var imgid = 'img'+screensToDo[bId];
		var img = $id(imgid);
		img.style.background = "url('/indicator.gif')";
		loadXMLDoc('/image.php?bId='+screensToDo[bId]);
	}else{
		bId++;
		var obj = null;
		try{
			obj = eval("obj = "+val);
		}catch(e){
			obj = {status:'failed'};
		}

		var imgid = 'img'+obj.bId;
		var img = $id(imgid);

		img.style.background = "";

		if(obj.status == "ok"){
			var src = SCREENSHOT_URL+obj.url;
			img.src = src;
		}

		if(bId < screensToDo.length){
			fetchImage('request');
		}
	}
}