var myInterval;
var maxH;
var maxW;
var actualY;
var DivForBc,DivForImg;
var myImage, myImageS;
function winH() {
   if (window.innerHeight)
      /* NN4 a kompatibilní prohlížeče */
      return window.innerHeight;
   else if
   (document.documentElement &&
   document.documentElement.clientHeight)
      /* MSIE6 v std. režimu - Opera a Mozilla
      již uspěly s window.innerHeight */
      return document.documentElement.clientHeight;
   else if
   (document.body && document.body.clientHeight)
      /* starší MSIE + MSIE6 v quirk režimu */
      return document.body.clientHeight;
   else
      return null;
}
function winW() {
   if (window.innerWidth)
      /* NN4 a kompatibilní prohlížeče */
      return window.innerWidth;
   else if
   (document.documentElement &&
   document.documentElement.clientWidth)
      /* MSIE6 v std. režimu - Opera a Mozilla
      již uspěly s window.innerHeight */
      return document.documentElement.clientWidth;
   else if
   (document.body && document.body.clientWidth)
      /* starší MSIE + MSIE6 v quirk režimu */
      return document.body.clientWidth;
   else
      return null;
}
function clearAjaxImage()
{
/*mybody=document.getElementsByTagName("BODY")[0];*/
DBc=document.getElementById("axDivBc");
DImg=document.getElementById("axDivI");
/*mybody.removeChild(DBc);
mybody.removeChild(DImg);*/
var myparent=DBc.parentNode;
myparent.removeChild(DBc);
myparent=DImg.parentNode;
myparent.removeChild(DImg);
}
function setAjaxDiv(){
		myImage=document.createElement("IMG");
		myImage.setAttribute("src","/styles/ajxi/moover.gif");
		myImageS=document.createElement("IMG");
		myImageS.setAttribute("src",imgPath);
		if(document.all)
			{
			myImageS.attachEvent("onload", setDivParas);
			}
		else
	   {
			myImageS.addEventListener("load", setDivParas, false);
		 }	
		myImage.setAttribute("id","AjaxImage");
		DivForBc=document.createElement("DIV");
		DivForImg=document.createElement("DIV");
		DivForBc.style.position="absolute";
		DivForBc.setAttribute("id","axDivBc");
		DivForImg.setAttribute("id","axDivI");
		DivForImg.style.width=bodyW+"px";
		DivForImg.style.top=actualY+"px";
		DivForImg.style.left=0+"px";
		DivForImg.style.padding="50px 0px 0px 0px";
		myTop=parseInt(((maxH-30)/2));
		myLeft=parseInt((maxW-30)/2);
		DivForBc.style.left=myLeft+"px";
		DivForBc.style.top=myTop+"px";
		myTable=document.createElement("TABLE");
		myTable.className="axImageTable";
		myTr=document.createElement("TR");
		myTd=document.createElement("TD");
		myTd.setAttribute("colspan","4");
		myTd.className="axImgTd";
		tbBody=document.createElement("TBODY");
		myTrtool=document.createElement("TR");
		myTrtool.style.background="white";
		myTrtool.style.color="black";
		myTdPrev=document.createElement("TD");
		myTdPrev.setAttribute("id","toolTdPrev");
		myTdPrev.style.textAlign="left";
		if(imgPrev>0)
		{
			myTdPrev.setAttribute("title",imgPrev);
			if(!window.addEventListener)
		       {
				myTdPrev.attachEvent("onclick",axPrevImage);      
		       }
		       else
		       {     
		    	myTdPrev.addEventListener("click",axPrevImage, false);      
		       }
			prevImage=document.createElement("IMG");
			prevImage.src="/styles/ajxi/prev.png";
			myTdPrev.appendChild(prevImage);
			myTdPrev.className="clsPointer";
		}
		myTdPrev.style.width="30px";
		myTrtool.appendChild(myTdPrev);	
		myTdNAme=document.createElement("TD");
		myTdNAme.setAttribute("id","toolTdName");
		myTxtNAme=document.createTextNode(imgName);
		myTdNAme.appendChild(myTxtNAme);
		myTrtool.appendChild(myTdNAme);
		myTdNext=document.createElement("TD");
		myTdNext.setAttribute("id","toolTdNext");
		myTdNext.style.width="30px";
		if(imgNext>0)
		{
			myTdNext.setAttribute("title",imgNext);
			if(!window.addEventListener)
		       {
				myTdNext.attachEvent("onclick",axNextImage);      
		       }
		       else
		       {     
		    	myTdNext.addEventListener("click",axNextImage, false);      
		       }
			prevImage=document.createElement("IMG");
			prevImage.src="/styles/ajxi/next.png";
			myTdNext.appendChild(prevImage);
			myTdNext.className="clsPointer";
		}
		myTrtool.appendChild(myTdNext);
		
		myTdTerminate=document.createElement("TD");
		myTdTerminate.style.width="30px";
		prevImage=document.createElement("IMG");
		prevImage.src="/styles/ajxi/terminate.png";
		myTdTerminate.appendChild(prevImage);
		if(!window.addEventListener)
	       {
				myTdTerminate.attachEvent("onclick",clearAjaxImage);      
	       }
	       else
	       {     
	    	   myTdTerminate.addEventListener("click",clearAjaxImage, false);      
	       }
		myTdTerminate.setAttribute("id","toolTerminate");
		myTrtool.appendChild(myTdTerminate);
		myTd.style.height=imgH+"px";
		myTd.style.widtht=imgW+"px";
		myTd.appendChild(myImage);
		
		//myImage.style.display="none";
		myTr.appendChild(myTd);
		tbBody.appendChild(myTrtool);
		tbBody.appendChild(myTr);
		
		
		myTable.appendChild(tbBody);
		DivForImg.appendChild(myTable);
		mybody.appendChild(DivForBc);
		mybody.appendChild(DivForImg);
		//myInterval= window.setTimeout("setDivParas()",1);
		//myTable.style.backgroundColor="silver";
		//myTable.style.margin="0px auto";
		myTable.style.width=imgW+"px";
}

function setDivParas()
{
	blnInterva=new Boolean(myInterval);
if(blnInterva)
   {
	 window.clearTimeout(myInterval);
   }

userW=bodyW-4;
userH=(bodyH>maxH)?(bodyH-2):(maxH-10);
actualDivW=DivForBc.clientWidth;
actualDivH=DivForBc.clientHeight;
DivForBc.style.left=0+"px";
DivForBc.style.top=0+"px";
DivForBc.style.width=userW+"px";
DivForBc.style.height=userH+"px";
/*if(actualDivW>=userW && actualDivH>=userH)
   {
	 //alert(actualDivW+","+actualDivH);
	 //myImage.style.display="";
	if(!myImageS || !myImage)return false;
	 myImage.src=myImageS.src;
	 myImage.width=myImageS.width;
	 myImage.height=myImageS.height;
	// alert( myImage.src);
	 return false;
	 }*/
if(!myImageS || !myImage)return false;
	 myImage.src=myImageS.src;
	 myImage.width=myImageS.width;
	 myImage.height=myImageS.height;	 
/*actualDivW=(actualDivW>=userW)?userW:actualDivW+15;
actualDivH=(actualDivH>=userH)?userH:actualDivH+10;
DivForBc.style.width=actualDivW+"px";
DivForBc.style.height=actualDivH+"px";
myTop=parseInt(((userH-actualDivH)/2));
myLeft=parseInt((userW-actualDivW)/2);
DivForBc.style.left=myLeft+"px";
DivForBc.style.top=myTop+"px";*/
//myInterval= window.setTimeout("setDivParas()",1);
return false;
}
function axPrevImage(ev)
{
	el=document.getElementById("toolTdPrev");
	imgId=el.title;
	myImage=document.getElementById("AjaxImage");
	//myImage.setAttribute("src","/styles/ajxi/moover.gif");
	//myImage.width=50;
	//myImage.height=50;
	os=document.createElement("script");
	os.setAttribute("type","text/javascript");
	scriptPath="/lbr/ajaximg.php?prev="+imgId;
	os.setAttribute("src",scriptPath);
	document.getElementsByTagName("body")[0].appendChild(os);
	return true;
}
function axNextImage(ev)
{
el=document.getElementById("toolTdNext");
imgId=el.title;
myImage=document.getElementById("AjaxImage");
//myImage.setAttribute("src","/styles/ajxi/moover.gif");
//myImage.width=50;
//myImage.height=50;
os=document.createElement("script");
os.setAttribute("type","text/javascript");
scriptPath="/lbr/ajaximg.php?next="+imgId;
os.setAttribute("src",scriptPath);
document.getElementsByTagName("body")[0].appendChild(os);
return true;
}
function switchImage()
{
myImage=document.getElementById("AjaxImage");	
myImage.setAttribute("src",imgPath);
myImage.width=imgW;
myImage.height=imgH;
myTable=document.getElementById("axDivI").getElementsByTagName("table")[0];
myTable.style.width=imgW+"px";
	if(imgNext==0)
	{
		mytd=document.getElementById("toolTdNext");
		mytds=mytd.getElementsByTagName("img");
		mytd.className="";
		if(mytds.length>0)mytd.removeChild(mytds[0]);
		
		if(!window.addEventListener)
	       {
			mytd.detachEvent("onclick",axNextImage);      
	       }
	       else
	       {     
	    	mytd.removeEventListener("click",axNextImage,false);      
	       }
		
	}
	else
	{
		mytd=document.getElementById("toolTdNext");
		document.getElementById("toolTdName").firstChild.data=imgName;
		mytd.title=imgNext;
		mytd.className="clsPointer";
		mytds=mytd.getElementsByTagName("img");
		if(mytds.length==0)
		{
			ni=document.createElement("img");
			ni.setAttribute("src","/styles/ajxi/next.png");
			mytd.appendChild(ni);
			if(!window.addEventListener)
		       {
				mytd.attachEvent("onclick",axNextImage);      
		       }
		       else
		       {     
		    	 mytd.addEventListener("click",axNextImage);      
		       }
		}
		
	}
	
	if(imgPrev==0)
	{
		mytd=document.getElementById("toolTdPrev");
		mytds=mytd.getElementsByTagName("img");
		mytd.className="";
		if(mytds.length>0)mytd.removeChild(mytds[0]);
		if(!window.addEventListener)
	       {
			mytd.detachEvent("onclick",axPrevImage);      
	       }
	       else
	       {     
	    	mytd.removeEventListener("click",axPrevImage,false);      
	       }
		
	}
	else
	{
		mytd=document.getElementById("toolTdPrev");
		mytd.setAttribute("title",imgPrev);
		mytd.className="clsPointer";
		//alert(mytd.getAttribute("title"));
		mytds=mytd.getElementsByTagName("img");
		
		if(mytds.length==0)
		{
			ni=document.createElement("img");
			ni.setAttribute("src","/styles/ajxi/prev.png");
			mytd.appendChild(ni);
			if(!window.addEventListener)
		       {
				mytd.attachEvent("onclick",axPrevImage);      
		       }
		       else
		       {     
		    	 mytd.addEventListener("click",axPrevImage, false);      
		       }
		}
		
	}
	//document.getElementById("toolTdNext").style.width="30px";	
	//document.getElementById("toolTerminate").style.width="30px";
	
}
function setAjaxGallery(){
	
	myIframe=document.createElement("iframe");
	myIframe.setAttribute("src",imgPath);
	myIframe.setAttribute("allowtransparency","true");
	
	myIframe.style.width=(maxW-100)+"px";
	myIframe.style.height=(maxH-50)+"px";
	myIframe.style.border="0px none";
	//myIframe.style.background="transparent";
	setCookie("uWinW",(maxW-100));
	setCookie("uWinH",(maxH-50));
	DivForBc=document.createElement("DIV");
	DivForImg=document.createElement("DIV");
	DivForBc.style.position="absolute";
	
	DivForBc.setAttribute("id","axDivBc");
	DivForImg.setAttribute("id","axDivI");
	
	DivForImg.style.width=bodyW+"px";
	DivForImg.style.top=actualY+"px";
	DivForImg.style.left=0+"px";
	DivForImg.style.padding="5px 0px 0px 0px";
	
	myTop=parseInt(((maxH-30)/2));
	myLeft=parseInt((maxW-30)/2);
	
	DivForBc.style.left=myLeft+"px";
	DivForBc.style.top=myTop+"px";
	myTable=document.createElement("TABLE");
	myTable.className="axImageTable";
	
	myTr=document.createElement("TR");
	myTd=document.createElement("TD");
	
	myTd.className="axImgTd";
	
	tbBody=document.createElement("TBODY");
	
	myTrtool=document.createElement("TR");
	myTrtool.style.background="black";
	myTrtool.style.color="white";
	
	
	
	
	
	myTdTerminate=document.createElement("TD");
	
	prevImage=document.createElement("IMG");
	prevImage.src="/styles/ajxi/terminate.png";
	myTdTerminate.appendChild(prevImage);
	if(!window.addEventListener)
       {
			myTdTerminate.attachEvent("onclick",clearAjaxImage);      
       }
       else
       {     
    	   myTdTerminate.addEventListener("click",clearAjaxImage, false);      
       }
	myTdTerminate.setAttribute("id","toolIfTerminate");
	myTrtool.appendChild(myTdTerminate);
	myTd.style.height=(maxH-50)+"px";
	myTd.style.widtht=(maxW-300)+"px";
	myTd.appendChild(myIframe);
	
	//myImage.style.display="none";
	myTr.appendChild(myTd);
	tbBody.appendChild(myTrtool);
	tbBody.appendChild(myTr);
	
	
	myTable.appendChild(tbBody);
	DivForImg.appendChild(myTable);
	mybody.appendChild(DivForBc);
	mybody.appendChild(DivForImg);
	myInterval= window.setTimeout("setDivParas()",5);
	myTable.style.widtht=(maxW-100)+"px";
	//myTable.style.margin="0px auto";
	
}

