var _imgSrc="",_imgW="",_imgH="",_imgAlt="",_imgID=0,_imgPrec=0,_imgSucc=0;

function calcola(a)
{
 _imgID=parseInt(a.id.substr(3),10);
 _imgSrc=a.href;
 var psd=a.rel.split(",");
 var dim=psd[0].split("-");
 _imgPrec=parseInt(psd[1],10); _imgSucc=parseInt(psd[2],10);
 _imgW=parseInt(dim[0],10); _imgH=parseInt(dim[1],10);
 var img=a.firstChild;
 _imgAlt=img.getAttribute("alt");
}

function zoom(e)
{
 if(!e) var e=window.event;
 var a;
 if(e.target) a=e.target;
 else if(e.srcElement) a=e.srcElement;
 if(a && a.nodeType==1 && (a.nodeName.toLowerCase()=="img" || n.nodeName=="html:img")) a=a.parentNode;
 if(!a || a.nodeType!=1 || (a.nodeName.toLowerCase()!="a" && n.nodeName!="html:a")) return true;
 calcola(a);
 apriZoom();
 if(e.preventDefault) e.preventDefault();
 if(e.stopPropagation) e.stopPropagation();
 else if(e.cancelBubble) e.cancelBubble();
 return false;
}

function precedente(e)
{
 if(!e) var e=window.event;
 if(_imgPrec>0)
 {
  var a=document.getElementById("img"+_imgPrec);
  calcola(a);
  apriZoom();
 }
 if(e.preventDefault) e.preventDefault();
 if(e.stopPropagation) e.stopPropagation();
 else if(e.cancelBubble) e.cancelBubble();
 return false;
}

function successiva(e)
{
 if(!e) var e=window.event;
 if(_imgSucc>0)
 {
  var a=document.getElementById("img"+_imgSucc);
  calcola(a);
  apriZoom();
 }
 if(e.preventDefault) e.preventDefault();
 if(e.stopPropagation) e.stopPropagation();
 else if(e.cancelBubble) e.cancelBubble();
 return false;
}

function apriZoom()
{
 var wh,offset=0;
 if(window.innerHeight) wh=window.innerHeight;
 else wh=document.documentElement.clientHeight;
 if(wh>_imgH+30) offset=(wh-_imgH-30)/2;
 var body=document.getElementsByTagName("body").item(0);
 var z=document.getElementById("zoomsfondo");
 z.style.display="block";
 z=document.getElementById("zoom");
 if(window.pageYOffset) offset+=window.pageYOffset;
 else if(document.documentElement && document.documentElement.scrollTop) offset+=document.documentElement.scrollTop;
 z.style.top=offset+"px";
 var img=z.getElementsByTagName("img").item(0);
 img.src=_imgSrc;
 var p=document.getElementById("zoomriquadro");
 p.style.width=_imgW+"px";
 z.style.display="block";
 if(_imgAlt)
 {
  var span=z.getElementsByTagName("span").item(1);
  if(span.firstChild) span.removeChild(span.firstChild);
  span.appendChild(document.createTextNode(_imgAlt));
 }
 if(_imgPrec>0) document.getElementById("zoomprec").style.visibility="visible";
 else document.getElementById("zoomprec").style.visibility="hidden";
 if(_imgSucc>0) document.getElementById("zoomsucc").style.visibility="visible";
 else document.getElementById("zoomsucc").style.visibility="hidden";
}

function chiudi(e)
{
 if(!e) var e=window.event;
 var z=document.getElementById("zoomsfondo");
 z.style.display="none";
 z.style.filter="alpha(opacity=90)";
 z=document.getElementById("zoom");
 z.style.display="none";
 _imgSrc=""; _imgW=""; _imgH=""; _imgAlt=""; _imgID=0; _imgPrec=0; _imgSucc=0;
 if(e.preventDefault) e.preventDefault();
 if(e.stopPropagation) e.stopPropagation();
 else if(e.cancelBubble) e.cancelBubble();
 return false;
}

function inizializza()
{
 var a=document.getElementsByTagName("a");
 for(var n=0; n<a.length; n++)
  if(a[n].className=="zoom")
  {
   if(document.addEventListener)
    a[n].addEventListener("click",zoom,false);
   else
    a[n].onclick=zoom;
  }
 var body=document.getElementsByTagName("body").item(0);
 var div=document.createElement("div");
 div.id="zoomsfondo";
 div.style.width=body.clientWidth+"px";
 div.style.height=body.clientHeight+"px";
 body.appendChild(div);
 div=document.createElement("div");
 div.id="zoom";
 div.style.width=body.clientWidth+"px";
 div.style.height=body.clientHeight+"px";
 var p=document.createElement("p");
 p.id="zoomriquadro";
 var span=document.createElement("span");
 span.id="zoomprecsucc";
 span.appendChild(document.createTextNode("."));
 var a=document.createElement("a");
 a.appendChild(document.createTextNode("Precedente"));
 a.setAttribute("href","#");
//  a.setAttribute("style","visibility:hidden;");
 a.id="zoomprec";
 if(document.addEventListener) a.addEventListener("click",precedente,false);
 else a.onclick=precedente;
 span.appendChild(a);
 a=document.createElement("a");
 a.appendChild(document.createTextNode("Successiva"));
 a.setAttribute("href","#");
//  a.setAttribute("style","visibility:hidden;");
 a.id="zoomsucc";
 if(document.addEventListener) a.addEventListener("click",successiva,false);
 else a.onclick=successiva;
 span.appendChild(a);
 p.appendChild(span);
 var img=document.createElement("img");
 p.appendChild(img);
 a=document.createElement("a");
 a.appendChild(document.createTextNode("Chiudi"));
 a.setAttribute("href","#");
 if(document.addEventListener) a.addEventListener("click",chiudi,false);
 else a.onclick=chiudi;
 p.appendChild(a);
 span=document.createElement("span");
 p.appendChild(span);
 div.appendChild(p);
 body.appendChild(div);
 var dazoomare
 try
 {
  dazoomare=parseInt(document.getElementsByTagName("h1").item(0).className,10);
  if(dazoomare)
   if(document.getElementById("img"+dazoomare))
   {
    calcola(document.getElementById("img"+dazoomare));
    apriZoom();
   }
 } catch(e) {}
}

if(document.getElementsByTagName)
{
 if(document.addEventListener) document.addEventListener("DOMContentLoaded",inizializza,false);
 else window.onload=inizializza;
}

