var imgid='image';var thumbid='thumbs';var auto=false;var autodelay=5;var slideShow=function(){var bxs,bxe,fxs,fxe,ys,ye,ta,ia,ie,st,ss,ft,fs,xp,yp,ci,t,th,tar,tarl;return{init:function(speed){ta=document.getElementById(thumbid);ia=document.getElementById(imgid);th=ta.getElementsByTagName('input');t=ta.getElementsByTagName('li');ie=document.all?true:false;st=10;ss=speed||10;ft=3;fs=3;xp,yp=0;document.onmousemove=this.pos;window.onresize=function(){setTimeout("slideShow.lim()",300)};ys=this.toppos(ta);ye=ys+ta.offsetHeight;len=t.length;tar=[];for(i=0;i<len;i++){var id=th[i].value;tar[i]=id;t[i].onclick=new Function("slideShow.getimg('"+id+"')");if(i==0){this.getimg(id)}}tarl=tar.length;},scrl:function(d){clearInterval(ta.timer);var l=(d==-1)?0:(t[tarl-1].offsetLeft-(ta.parentNode.offsetWidth-t[tarl-1].offsetWidth)+10);ta.timer=setInterval(function(){slideShow.mv(d,l)},st);},mv:function(d,l){ta.style.left=ta.style.left||'0px';var left=ta.style.left.replace('px','');if(d==1){if(l-Math.abs(left)<=ss){this.cncl(ta.id);ta.style.left='-'+l+'px';}else{ta.style.left=left-ss+'px'}}else{if(Math.abs(left)-l<=ss){this.cncl(ta.id);ta.style.left=l+'px';}else{ta.style.left=parseInt(left)+ss+'px'}}},cncl:function(){clearTimeout(ta.timer)},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)){while(ia.firstChild){ia.removeChild(ia.firstChild);}var div1=document.createElement("div");ia.appendChild(div1);var center=document.createElement("center");ia.appendChild(center);newlink=document.createElement('a');var ref="javascript:popImg('"+id+"')";newlink.setAttribute('href',ref);center.appendChild(newlink);var i=document.createElement('img');i.id=id;i.av=0;i.style.opacity=0;i.style.filter='alpha(opacity=0)';i.border=0;i.title='Enlarge';i.src='http://sapc12.epfl.ch/cgi-bin/slideshow2.pl?ref='+id;newlink.appendChild(i);var div2=document.createElement("div");div2.setAttribute('id','legende');ia.appendChild(div2);var html='<a href="javascript:slideShow.nav(-1)" class="imgnav" id="previmg"></a><a href="javascript:slideShow.nav(1)" class="imgnav " id="nextimg"></a>';div1.innerHTML=html;var thumbarea=document.getElementById('thumbarea');var wat=thumbarea.getAttribute("wat");legend(id,div2,wat);}else{i=document.getElementById(id);clearInterval(i.timer);}i.timer=setInterval(function(){slideShow.fdin(i)},fs);},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)},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(){var taw,taa,len;taw=ta.parentNode.offsetWidth;taa=taw/4;bxs=slideShow.leftpos(ta);bxe=bxs+taa;fxe=bxs+taw;fxs=fxe-taa;},pos:function(e){xp=ie?event.clientX+document.documentElement.scrollLeft:e.pageX;yp=ie?event.clientY+document.documentElement.scrollTop:e.pageY;if(xp>bxs+10&&xp<bxe&&yp>ys&&yp<ye){slideShow.scrl(-1);}else if(xp>fxs&&xp<fxe-10&&yp>ys&&yp<ye){slideShow.scrl(1);}else{slideShow.cncl()}},leftpos:function(t){var l=0;if(t.offsetParent){while(1){l+=t.offsetLeft;if(!t.offsetParent){break};t=t.offsetParent}}else if(t.x){l+=t.x}return l;},toppos:function(t){var p=0;if(t.offsetParent){while(1){p+=t.offsetTop;if(!t.offsetParent){break};t=t.offsetParent}}else if(t.y){p+=t.y}return p;}};}();function add(img){var thumbarea=document.getElementById('thumbarea');thumbarea.setAttribute("wat",img);while(thumbarea.firstChild){thumbarea.removeChild(thumbarea.firstChild);}dojo.xhrGet({url:"/wat1/slideshow5.pl?id="+img,load:function(response,ioArgs){var len=response.items.length;var html='<ul id="thumbs">';var src,ref,title,num;for(i=0;i<len;i++){if(i%4==0){src='http://sapc12.epfl.ch'+response.items[i].thumb;}else{src=response.items[i].thumb;}ref=response.items[i].large;title=response.items[i].title;num=i+1;html+='<li value="'+i+'"><input type="hidden" id="hidden1" value="'+ref+'" /><img align="top" src="'+src+'"  title="'+title+'" />'+num+'</li>';}html+='</ul>';dojo.byId('thumbarea').innerHTML=html;slideShow.init(3);slideShow.lim();return response;},error:function(response,ioArgs){dojo.byId('thumbarea').innerHTML="An error occurred, with response: "+response;return response;},handleAs:"json"});}function legend(id,node,wat){dojo.xhrGet({url:"/wat1/slideshow3.pl?ref="+id+'&wat='+wat,load:function(response,ioArgs){html=response;dojo.byId(node).innerHTML=html;return response;},error:function(response,ioArgs){dojo.byId('thumbarea').innerHTML="An error occurred, with response: "+response;return response;},handleAs:"text"});}function add_auto(){auto=true;slideShow.init();slideShow.lim();}function remove_auto(){window.location.href=window.location.href;}
