var woosh;
var wpic;
var wdesc;
var xoff=250;var yoff=380;
var theobj;
var zin;
var img;
var tmp;
var obj;

function doresize() // la resize
{
xoff=(document.body.clientWidth-765)/2;
}

function init()// on load la body
{
woosh=document.getElementById('woosh');
wpic=document.getElementById('wpic');
wdesc=document.getElementById('wdesc');
xoff=(document.body.clientWidth-750)/2;
}


function move2center()
{
    var w=parseInt(woosh.style.width);
	var h=parseInt(woosh.style.height);
	var l=parseInt(woosh.style.left);
	var t=parseInt(woosh.style.top);
	var change=false;
	if (zin)
	{
			if (l>RO(xoff+280)) { woosh.style.left=(l-5)+'px';change=true; }
				else if (l<RO(xoff+280)) { woosh.style.left=(l+5)+'px';change=true; }
			if (t>RO(yoff+180)) { woosh.style.top=(t-5)+'px';change=true; }
				else if (t<RO(yoff+180)) { woosh.style.top=(t+5)+'px';change=true; }
		
			if (change) setTimeout("move2center()", 2);
			else zoom();
	} else
	{
			if (l>RO(xoff+theobj%4*190)) { woosh.style.left=(l-5)+'px';change=true; }
				else if (l<RO(xoff+theobj%4*190)) { woosh.style.left=(l+5)+'px';change=true; }
			if (t>RO(yoff+Math.floor(theobj/4)*125)) { woosh.style.top=(t-5)+'px';change=true; }
				else if (t<RO(yoff+Math.floor(theobj/4)*125)) { woosh.style.top=(t+5)+'px';change=true; }
		
			if (change) setTimeout("move2center()", 2);
			else woosh.style.visibility='hidden';
	}
}


function zoom()
{
var w=parseInt(woosh.style.width);
var h=parseInt(woosh.style.height);
var l=parseInt(woosh.style.left);
var t=parseInt(woosh.style.top);
var change=false;
if (zin==true)
	{
		if (w<640) { woosh.style.left=(l-5)+'px';woosh.style.width=(w+10)+'px';change=true; }
		if (h<500)	{ woosh.style.top=(t-5)+'px'; woosh.style.height=(h+10)+'px';change=true; }
		
		if (change) setTimeout("zoom()", (640-w)/32);
		else wdesc.innerHTML=tmp;
	} 
	else //zout
	{
		if (w>180) { woosh.style.left=(l+5)+'px'; woosh.style.width=(w-10)+'px';change=true; }
		if (h>120)	{ woosh.style.top=(t+5)+'px';woosh.style.height=(h-10)+'px';change=true; }
		
		if (change) setTimeout("zoom()",w/32);
		else { move2center();
			 wdesc.innerHTML="&nbsp;";
			}
	}
}

function pnm(str)
{
	return parseInt(str.substring(2,str.length));
}

function undoclick()
{
zin=false;
zoom();
}

function RO(nr)
{
return Math.round(nr/10)*10;
}

function isLoaded(img)
{
	return (img && img.complete && img.width > 0);
}

function waitload()
{
if (!isLoaded(img)) setTimeout("waitload()",250);
else doclick2();
}

function doclick(e,objid,file)
{
obj=document.getElementById(objid);
tmp=obj.innerHTML;
obj.innerHTML="Loading...";
theobj=pnm(objid);
img=new Image();
img.src = file;
waitload();
}

function doclick2() // continuare la doclick
{
	wpic.src=img.src;
	obj.innerHTML=tmp;
	woosh.style.left=RO(xoff+theobj%4*190)+'px';
	woosh.style.top=RO(yoff+Math.floor(theobj/4)*125)+'px';
	woosh.style.width='180px';
	woosh.style.height='120px';
	woosh.style.visibility='visible';
	zin=true;
	move2center();
}
