top.usePopupScript = 1;
top.popopscriptIEmode = 0;//is set to ie automatically if IE, then handle Iframe as well.

function swichPopupOnOff(val){
	top.usePopupScript = val;
}

var compstatus=0,compimg,mX,mY,dW,dH,misc1,misc2,misc3=0,mes1,mes2,mes3,thehref;//status of comp; imageObject; mouseX, mouseY, imgDIV width; imgDIV height; timers for window; measurements for X, Y and width,height of div;

function mousemove(evt){//if mouse is moved outside the area of the original thumb, clear comp 
	mX = evt.clientX + document.body.scrollLeft;
	mY = evt.clientY + document.body.scrollTop;
}

function doMouseOver(img){//upon mouseover of the thumb
	if(top.usePopupScript==0)
		return true;
		
	if(compstatus==4 && compimg.src==img.getAttribute("compimgsrc")){//onmouseover of the currenly shown image, do not reset and show again, just keep it.
		unresetComp();
	}
	else if(compstatus==4){//onmouseover of another image than currently showing, reset and show the new image
		unresetComp();
		clearComp();
	}
	else if(compstatus!=0){//currently in the process of getting an image shown, reset and go the new image
		unresetComp();
		clearComp();
	}
	
	compimg = img;	
	compstatus = 1;
	clearTimeout(misc1);
	misc1=setTimeout(getComp,500);
}

function getComp(){//called 500ms after mouseover, to start loading comp
	if(compstatus!=1)return;
	compstatus = 2;
	theimg = document.getElementById("compIMG");
	theimg.src=compimg.getAttribute("compimgsrc");//load compimg into the empty imagetag
	theimg.onload=showComp;
	
	//get the url for onclick
	theimgid = compimg.getAttribute("id");
	theimgcuitemid = theimgid.substring(9, 100);
	thethumbimg = document.getElementById("thumb_"+theimgcuitemid);
	thehref = thethumbimg.parentNode.href;
}

function showComp(){//called upon load of comp, to start showing it
	if(compstatus!=2)return;
	compstatus = 3;
	fadeStart();
	fadeIn();
}

function resetComp(){//called to remove the comp
	misc2 = window.setTimeout(clearComp,250);
}

function unresetComp(){
	clearTimeout(misc2);
}

function clearComp(){
	clearTimeout(misc1);
	compstatus = 0;
	thediv = document.getElementById("compDIV");
	theimg = document.getElementById("compIMG");
	thediv.style.display = 'none';
	theimg.style.display = 'none';
	if(top.popopscriptIEmode==1){
		theiframe = document.getElementById("compIframe");
		theiframe.style.visibility = 'hidden';
	}
}

function gotoDetails(){
	window.location=thehref;
}

//internal functions for positioning and fading compimage and div
function fadeStart(){//set div and img to start position and visibitity for fading in
	if(compstatus!=3)return;
	
	thediv = document.getElementById("compDIV");
	theimg = document.getElementById("compIMG");
	thediv.style.left = mX;
	thediv.style.top = mY;
	thediv.style.width = '1px';
	thediv.style.height = '1px';
	thediv.style.display = 'block';
	theimg.style.display = 'block';
	mes1 = mX;
	mes2 = mY;
	mes3 = 0.1;
	if(top.popopscriptIEmode==1){
		theiframe = document.getElementById("compIframe");
		theiframe.style.left = mX;
		theiframe.style.top = mY;
		theiframe.style.width = '1px';
		theiframe.style.height = '1px';
		theiframe.style.visibility = 'visible';
	}
	//alert('start position:\mleft: '+mX+'\ntop:'+mY);
}

function fadeIn(){
	if(compstatus!=3)return;
	
//	alert('fadeIncall '+misc3+'\nthediv.style.left='+thediv.style.left+'\nthediv.style.width='+thediv.style.width);
	thediv = document.getElementById("compDIV");
	theimg = document.getElementById("compIMG");
	
	trgtwidth = theimg.width;
	trgtheight = theimg.height;
	
	if(mes3 < 1){
		mes3 = mes3 + 0.1;
		
		thediv.style.width = mes3 * trgtwidth;
		thediv.style.height = mes3 * trgtheight;
		
		theleft = mes1 - (mes3 * trgtwidth / 2);
		thetop = mes2 - (mes3 * trgtheight / 2);
		
		thediv.style.left = theleft>1?theleft:1;
		thediv.style.top = thetop>1?thetop:1;
		
		misc1 = window.setTimeout(fadeIn, 20);
	}
	else{
		compstatus = 4;
		if(top.popopscriptIEmode==1){
			theiframe = document.getElementById("compIframe");
			theiframe.style.left = thediv.style.left;
			theiframe.style.top = thediv.style.top;
			theiframe.style.width = trgtwidth;
			theiframe.style.height = trgtheight;
		}
	}
}


//old code=================================================================================================
/*var cS='W',tX,tY,tW,tH,mX,mY,pX,pY,pW,pH,pu,cT,nT,sB,sC,ms,pT,eP,eT;

cS is general status of handler:
W: none, startup position
I: upon mouseover
L: 500ms after mouseover, setting styles
U: upon load of comp, making the div visible and growin
S: image fully visible


function thumb_mouseover(i){
	switch(cS){
		case'W':case'L':case'I':case'D':
			I(i);
			break;
		default:
			nT=i;
	}
}

function oPT(){//called 500ms after mouseover, set styles to image
	switch(cS){
		case'I':L();break;
		case'D':U();break;
	}
}

function comp_load(){//called onload of comp
	switch(cS){
		case'I':D();break;
		case'L':U();break;
	}
}

function comp_click(){
	window.location=cT.parentNode.href;
}

function I(image){//start calls to load new compimg
	cS='I';
	cT=image;
	nT=null;
	pu=document.getElementById("pu");// empty imagetag
	sB=document.getElementById("sB");// table 3x3 with some shadowing images
	sC=document.getElementById("sC");// centre cell in Sb
	ms=document.getElementById("ms");// div with some image in it
	clearTimeout(pT);
	pT=setTimeout(oPT,500);//set style information on the image tag
	pu.src=image.getAttribute("compsrc");//load compimg into the empty imagetag
	pu.onload=comp_load;//onload of comp, start making it visible
	tX=tY=0;
	var offset=image;
	while(offset!=null){
		tX+=offset.offsetLeft;
		tY+=offset.offsetTop;
		offset=offset.offsetParent;
	}
	tW=image.offsetWidth;
	tH=image.offsetHeight;
}

function L(){//set styleinformation on the imageobject
	cS='L';
	cT.style.cursor="wait";
	ms.style.left=mX+10;
	ms.style.top=mY+10;
	ms.style.display="block";
}

function D(){//do nothing
	cS='D';
}

function U(){//set sizes of the imagediv
	cS='U';
	pu.style.display="block";
	pW=pu.width;
	pH=pu.height;
	pX=tX+(tW/2)-(pW/2);
	pY=tY+(tH/2)-(pH/2);
	pX=Math.max(pX,document.body.scrollLeft);
	pY=Math.max(pY,document.body.scrollTop);
	pX=Math.min(pX,document.body.scrollLeft+document.body.clientWidth-pW);
	pY=Math.min(pY,document.body.scrollTop+document.body.clientHeight-pH);
	cT.style.cursor="auto";
	ms.style.display="none";
	pu.style.display="block";
	eP=0.2;
	itU();
}

function itU(){//iterative let div grow
	clearTimeout(eT);
	if(eP<1){
		eP+=0.2;
		sE();
		eT=setTimeout(itU,40);
	}
	if(eP==1)
		S();
}

function itO(){//iterative let div shrink
	clearTimeout(eT);
	if(eP>.25){
		eP-=0.25;
		sE();
		eT=setTimeout(itO,40);
	}
	else 
		W();
}

function sE(){//set size of the image
	pu.style.width=tW+(pW-tW)*eP;
	pu.style.height=tH+(pH-tH)*eP;
	pu.style.left=tX+(pX-tX)*eP;
	pu.style.top=tY+(pY-tY)*eP;
}

function S(){//set final size of div
	cS='S';
	sC.width=pW-40;
	sC.height=pH-47;
	sB.style.left=pu.style.left;
	sB.style.top=pu.style.top;
	sB.style.display="block";
	var ief=document.getElementById("ief");
	ief.style.width=sB.offsetWidth;
	ief.style.height=sB.offsetHeight;
	ief.style.left=pu.style.left;
	ief.style.top=pu.style.top;
	ief.style.display="block";
}

function O(){
	cS='O';
	document.getElementById("ief").style.display="none";
	sB.style.display="none";
	itO();
}

function W(){
	cS='W';
	pu.style.display="none";
	ms.style.display="none";
	pu.style.width="auto";
	pu.style.height="auto";
	if(nT!=null)
		I(nT);
}
*/
