function sleep (seconds) {
    // http://kevin.vanzonneveld.net
    // +   original by: Christian Doebler
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // %          note: For study purposes. Current implementation could lock up the user's browser. 
    // %          note: Consider using setTimeout() instead.
    // *     example 1: sleep(1);
    // *     returns 1: 0
    
    var start = new Date().getTime();
    while (new Date() < start + seconds*1000) {}
    return 0;
}

function Swap(main,tcls,ms){
 var imgs=document.getElementById(main).getElementsByTagName('IMG');
 var thumbs=zxcByClassName(tcls);
 this.oops=[]
 for (var z0=imgs.length-1;z0>=0;z0--){
  imgs[z0].style.zIndex=z0!=imgs.length-1?'0':'1';
  this.oops.push(zxcBAnimator('opacity',imgs[z0],50,z0!=imgs.length-1?0:100,10));
  this.addevt(thumbs[z0],'mouseover','swap',z0);
 }
 this.lst=0;
 this.ms=ms||1000;
 document.getElementById('stocaricando').style.display="none"
 document.getElementById('freccettagiu').style.display="inline"
}

Swap.prototype.swap=function(e,nu){
 this.oops[this.lst].obj.style.zIndex='0';
 this.oops[this.lst].update([this.oops[this.lst].data[0],0],this.ms);
 this.lst=nu;
 this.oops[this.lst].obj.style.zIndex='1';
 this.oops[this.lst].update([this.oops[this.lst].data[0],100],this.ms);
}


Swap.prototype.addevt=function(o,t,f,p){
 var oop=this;
 if (o.addEventListener) o.addEventListener(t,function(e){ return oop[f](e,p);}, false);
 else if (o.attachEvent) o.attachEvent('on'+t,function(e){ return oop[f](e,p); });
 else {
  var prev=o['on'+t];
  if (prev) o['on'+t]=function(e){ prev(e); oop[f](e,p); };
  else o['on'+t]=o[f];
 }
}

function zxcByClassName(nme,el,tag){
 if (typeof(el)=='string') el=document.getElementById(el);
 el=el||document;
 for (var tag=tag||'*',reg=new RegExp('\\b'+nme+'\\b'),els=el.getElementsByTagName(tag),ary=[],z0=0; z0<els.length;z0++){
  if(reg.test(els[z0].className)) ary.push(els[z0]);
 }
 
 return ary;
}

