var image1 = new Image();
image1.src = "/images/left_act.png";
var image2 = new Image();
image2.src = "/images/pause_act.png";
var image3 = new Image();
image3.src = "/images/play_act.png";
var image4 = new Image();
image4.src = "/images/right_act.png";
var image5 = new Image();
image5.src = "/images/stop_act.png";
var image6 = new Image();
image6.src = "/images/top_act.png";
var image7 = new Image();
image7.src = "/images/bottom_act.png";


var slideShow=function(){
	var bxs,bxe,fxs,fxe,ys,ye,ta,ia,ie,st,ss,ft,fs,xp,yp,ci,t,tar,tarl,akt;
	ta=document.getElementById(thumbid); 
  ia=document.getElementById(imgid);
	t=ta.getElementsByTagName('li'); 
  ie=document.all?true:false;
	st=3; ss=3; ft=10; fs=5; xp,yp=0;
	return{
		init:function(){
			len=t.length;tar=[];
			for(i=0;i<len;i++){
				var id=t[i].value; tar[i]=id;
				t[i].onclick=new Function("slideShow.getimg('"+id+"')");
				if(i==0){this.getimg(id)}
			}
			tarl=tar.length;
			if (concrete > -1) {
         this.getimg(concrete);
         this.pause();
         auto = false;  
         document.getElementById("control-pause").src = "/images/pause.png";
         document.getElementById("control-stop").src = "/images/stop_act.png";
         document.getElementById("control-play").src = "/images/play.png";     
      }
		},
		scrl:function(d){ },
		mv:function(d,l){ },
		cncl:function(){ },
		getimg:function(id){
			if(auto){clearTimeout(ia.timer)}
			if(ci!=null){
				var ts,tsl,x;
				ts=ia.getElementsByTagName('img'); tsl=ts.length;x=0;
				for(x;x<tsl;x++){
					if(ci.id!=id){var o=ts[x]; clearInterval(o.timer); o.timer=setInterval(function(){slideShow.fdout(o)},fs)}
				}
			}
			if(!document.getElementById(id)){
				var i=document.createElement('img');
				ia.appendChild(i);
				i.id=id; i.av=0; i.style.opacity=0;
				i.style.filter='alpha(opacity=0)';
				i.src=imgdir+'/'+id+imgext;
			}else{
				i=document.getElementById(id); clearInterval(i.timer);
			}
			i.timer=setInterval(function(){slideShow.fdin(i)},fs);
			getText(id);
			akt = id;
		},
		nav:function(d){
			var c=0;
			for(key in tar){if(tar[key]==ci.id){c=key}}
			if(tar[parseInt(c)+d]){
				this.getimg(tar[parseInt(c)+d]);
			}else{
				if(d==1){
					this.getimg(tar[0]);
				}else{this.getimg(tar[tarl-1])}
			}
		},
		auto:function(){
           ia.timer=setInterval(function(){slideShow.nav(1)},autodelay*1000);
           document.getElementById("control-pause").src = "/images/pause.png";
           document.getElementById("control-play").src = "/images/play_act.png";
           document.getElementById("control-stop").src = "/images/stop.png";
    },
		fdin:function(i){
			if(i.complete){i.av=i.av+fs; i.style.opacity=i.av/100; i.style.filter='alpha(opacity='+i.av+')'}
			if(i.av>=100){if(auto){this.auto()}; clearInterval(i.timer); ci=i}
		},
		fdout:function(i){
			i.av=i.av-fs; i.style.opacity=i.av/100;
			i.style.filter='alpha(opacity='+i.av+')';
			if(i.av<=0){clearInterval(i.timer); if(i.parentNode){i.parentNode.removeChild(i)}}
		},
		lim:function(){ },
		pos:function(e){ },
		leftpos:function(t){ },
		toppos:function(t){	},
		speed:function(s){
      var obj = document.getElementById(autodelayid);
      var num = Number(obj.innerHTML);
      num = num + s;
      if (num > 0) {
        obj.innerHTML = String(num);
        autodelay = num;
      }
    },
    pause:function(){
      clearInterval(ia.timer);
      document.getElementById("control-pause").src = "/images/pause_act.png";
      document.getElementById("control-play").src = "/images/play.png";
    },
    stop:function() {
      this.getimg(tar[0]);
      this.pause();
      auto = false;
      document.getElementById("control-pause").src = "/images/pause.png";
      document.getElementById("control-stop").src = "/images/stop_act.png";
      document.getElementById("control-play").src = "/images/play.png";
    },
    linkuj:function() {
       prompt("Odkaz na aktuální fotografii:", urll + akt);
    }
    };
}();

window.onload=function(){slideShow.init(); };

function getText(id)
{
        if (window.ActiveXObject)
        {
          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
          httpRequest = new XMLHttpRequest();
        }
        httpRequest.open("GET", "/info/"+id, true);
        httpRequest.onreadystatechange= function () {processRequest(); } ;
        httpRequest.send(null);
}

function processRequest()
{
  if (httpRequest.readyState == 4)
  {
    if(httpRequest.status == 200)
    {
      var mistoZobrazeni = document.getElementById("image-popis");
      mistoZobrazeni.innerHTML = httpRequest.responseText;
    }
  }
}

