function clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

var height,width;

function resize(){
	height=clientHeight();
	width=clientWidth();
	document.getElementById('header').style.width=(width-6)+"px";
	var content=document.getElementById('content');
	content.style.width=(width-6)+"px";
	content.style.height=(height-94)+"px";
	var cwidth=width-8,cheight=height-96;
	if(image!=null){
		//while(content.childNodes.length>0){content.removeChild(content.firstChild );}
		if(type==null)type="3D";
		if(type=="3D"){
			content.innerHTML="<img id=\"imid\" src=\"getImage.php?id="+image+"&x="+cwidth+"&y="+cheight+"\">";
		}else if(type=="P"){
			cwidth=cwidth/2;
			content.innerHTML="<img src=\"getImage.php?id="+image+"&x="+cwidth+"&y="+cheight+"&type=L\">"+"<img src=\"getImage.php?id="+image+"&x="+cwidth+"&y="+cheight+"&type=R\">";
		}else if(type=="2D"){
			content.innerHTML="<img id=\"imid\" src=\"getImage.php?id="+image+"&x="+cwidth+"&y="+cheight+"&type=L\">";
		}
		var d=document.getElementById('descriptionDiv'),dads=document.getElementById('ads'),db=document.getElementById('descriptionDivBack'),df=document.getElementById('descriptionDivFront');

		var hads=document.getElementById('headerads');
		a=728;b=1;
		if(type=="P")b=2;
		if(cwidth*b-410<728)a=cwidth*b-410;
		hads.style.left=((cwidth*b-410-a)/2+410)+"px";
		hads.style.width=a+"px";
		hads.style.visibility="visible";

		pic=document.getElementById("imid");
		var dwidth=210,dheight=cheight;
		
		d.style.left=(width-dwidth-4)+"px";
		d.style.width=dwidth+"px";
		d.style.height=dheight+"px";
		dads.style.top=(dheight-250)+"px";
		db.style.height=dheight+"px";
		df.style.height=(dheight-250)+"px";
	}else{
		var hads=document.getElementById('headerads');
		a=728;
		if(cwidth-297<728)a=cwidth-297;
		hads.style.left=((cwidth-297-a)/2+297)+"px";
		hads.style.width=a+"px";
		hads.style.visibility="visible";
	}
}
function start(){
	resize();
	document.getElementById("descriptionDiv").style.opacity=1;
	document.getElementById("descriptionDiv").style.visibility="visible";	
	if(autohide){
		zoomStep=-1;
		zooming=true;
		setTimeout("zoom()",8000);
	}
	if(!document.getElementById("showdescription").checked){
		var div=document.getElementById("descriptionDiv");
		div.style.opacity=0;
		div.style.filter="alpha(opacity=0)";
	}
}

function reload(){
	if(document.getElementById("image3D").checked)type="3D";
	else if(document.getElementById("imagePARALLEL").checked)type="P";
	else if(document.getElementById("imageMONO").checked)type="2D";
	document.location.href="showPicture.php?image="+image+"&type="+type+"&showdescription="+document.getElementById("showdescription").checked+"&autohide="+document.getElementById("autohide").checked;
}

function prevPage(){
	if(type==null)type="3D";
	window.location.href="showPicture.php?image="+(image-1)+"&type="+type+"&showdescription="+document.getElementById("showdescription").checked+"&autohide="+document.getElementById("autohide").checked;
}
function nextPage(){
	if(type==null)type="3D";
	window.location.href="showPicture.php?image="+(image+1)+"&type="+type+"&showdescription="+document.getElementById("showdescription").checked+"&autohide="+document.getElementById("autohide").checked;
}

var zoomStep=0,zooming=false;
function zoom(){
	if(zoomStep==0)return;
	var div=document.getElementById("descriptionDiv");
	var o=div.style.opacity*100;
	if(((o>0)&&(zoomStep==-1))||(o<100)&&(zoomStep==1)){
		o+=zoomStep;
		div.style.opacity=o/100;
		div.style.filter="alpha(opacity="+o+")";
		if(((o>0)&&(zoomStep==-1))||(o<100)&&(zoomStep==1))setTimeout("zoom()",5);
		else zooming=false;
	}else{
		zooming=false;
	}
}

function showDescription(){
	showdescription=document.getElementById("showdescription").checked;
	zooming=true;
	if(showdescription){
		zoomStep=1;
		document.getElementById("autohide").disabled=false;
		document.getElementById("autohide").checked=true;
	}else{
		zoomStep=-1;
		document.getElementById("autohide").disabled=true;
		document.getElementById("autohide").checked=false;
	}
	zoom();
}