/* $Id: lightbox.js,v 1.12 2008/06/08 20:06:44 Mario Exp $ */
// -----------------------------------------------------------------------------------
//
//  Lightbox v2.02
//  by Lokesh Dhakar - http://www.huddletogether.com
//  3/31/06
//
//  For more information on this script, visit:
//  http://huddletogether.com/projects/lightbox2/
//
//  Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//
//  Credit also due to those who have helped, inspired, and made their code available to the public.
//  Including: Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.org), Thomas Fuchs(mir.aculo.us), and others.
//
//
// -----------------------------------------------------------------------------------
var basedir="../js/lightbox/images/";var fileLoadingImage=basedir+"loading.gif";var fileBottomNavCloseImageOn=basedir+"close_on.gif";var fileBottomNavCloseImageOff=basedir+"close_off.gif";var fileBottomNavNextImageOn=basedir+"next_on.gif";var fileBottomNavNextImageOff=basedir+"next_off.gif";var fileBottomNavPrevImageOn=basedir+"prev_on.gif";var fileBottomNavPrevImageOff=basedir+"prev_off.gif";var fileBottomNavZoomImageOn=basedir+"zoom_on.gif";var fileBottomNavZoomImageOff=basedir+"zoom_off.gif";var resizeSpeed=7;var borderSize=10;var imageArray=new Array;var activeImage;if(resizeSpeed>10){resizeSpeed=10}if(resizeSpeed<1){resizeSpeed=1}resizeDuration=(11-resizeSpeed)*0.15;Object.extend(Element,{getWidth:function(A){A=$(A);return A.offsetWidth},setWidth:function(B,A){B=$(B);B.style.width=A+"px"},setHeight:function(A,B){A=$(A);A.style.height=B+"px"},setTop:function(B,A){B=$(B);B.style.top=A+"px"},setSrc:function(A,B){A=$(A);A.src=B},getSrc:function(A){A=$(A);return A.src},setHref:function(B,A){B=$(B);B.href=A},setInnerHTML:function(A,B){A=$(A);A.innerHTML=B}});Array.prototype.removeDuplicates=function(){for(i=1;i<this.length;i++){if(this[i][0]==this[i-1][0]){this.splice(i,1)}}};Array.prototype.empty=function(){for(i=0;i<=this.length;i++){this.shift()}};var Lightbox=Class.create();Lightbox.prototype={initialize:function(){if(!document.getElementsByTagName){return }var M=document.getElementsByTagName("a");for(var f=0;f<M.length;f++){var F=M[f];var d=String(F.getAttribute("rel"));if(F.getAttribute("href")&&(d.toLowerCase().match("lightbox"))){F.onclick=function(){myLightbox.start(this);return false}}}var G=document.getElementsByTagName("body").item(0);var h=document.createElement("div");h.setAttribute("id","overlay");h.style.display="none";h.onclick=function(){myLightbox.end();return false};G.appendChild(h);var Y=document.createElement("div");Y.setAttribute("id","lightbox");Y.style.display="none";G.appendChild(Y);var K=document.createElement("div");K.setAttribute("id","outerImageContainer");Y.appendChild(K);var P=document.createElement("div");P.setAttribute("id","imageContainer");K.appendChild(P);var T=document.createElement("img");T.setAttribute("id","lightboxImage");P.appendChild(T);var A=document.createElement("div");A.setAttribute("id","hoverNav");P.appendChild(A);var O=document.createElement("a");O.setAttribute("id","prevLink");O.setAttribute("href","#");A.appendChild(O);var U=document.createElement("a");U.setAttribute("id","nextLink");U.setAttribute("href","#");A.appendChild(U);var l=document.createElement("div");l.setAttribute("id","loading");P.appendChild(l);var B=document.createElement("a");B.setAttribute("id","loadingLink");B.setAttribute("href","#");B.onclick=function(){myLightbox.end();return false};l.appendChild(B);var N=document.createElement("img");N.setAttribute("id","fileLoadingImageId");B.appendChild(N);var j=document.createElement("div");j.setAttribute("id","imageDataContainer");j.className="clearfix";Y.appendChild(j);var b=document.createElement("div");b.setAttribute("id","imageData");j.appendChild(b);var L=document.createElement("div");L.setAttribute("id","imageDetails");b.appendChild(L);var a=document.createElement("span");a.setAttribute("id","caption");L.appendChild(a);var n=document.createElement("span");n.setAttribute("id","numberDisplay");L.appendChild(n);var E=document.createElement("div");E.setAttribute("id","numberNavDiv");L.appendChild(E);var g=document.createElement("span");g.setAttribute("id","numberNavText");g.innerHTML="vai alla";E.appendChild(g);var V=document.createElement("input");V.setAttribute("id","numberNavInput");V.setAttribute("type","text");V.setAttribute("value","1");V.onkeyup=function(){textCounter(this,null,4,1)};E.appendChild(V);var c=document.createElement("input");c.setAttribute("id","numberNavSubmit");c.setAttribute("type","submit");c.setAttribute("value","vedi");c.onclick=function(){myLightbox.changeImage(parseInt($("numberNavInput").value)-1);return false};E.appendChild(c);var H=document.createElement("select");H.setAttribute("id","numberNavSelect");H.onchange=function(){myLightbox.changeImage($("numberNavSelect").options.selectedIndex);return false};E.appendChild(H);var D=document.createElement("div");D.setAttribute("id","bottomNav");b.appendChild(D);var R=document.createElement("a");R.setAttribute("id","bottomNavClose");R.setAttribute("href","#");R.setAttribute("title","chiudi [x]");R.onclick=function(){myLightbox.end();return false};R.onmouseover=function(){$("fileBottomNavCloseImageId").setAttribute("src",fileBottomNavCloseImageOn);return false};R.onmouseout=function(){$("fileBottomNavCloseImageId").setAttribute("src",fileBottomNavCloseImageOff);return false};D.appendChild(R);var Z=document.createElement("img");Z.setAttribute("id","fileBottomNavCloseImageId");R.appendChild(Z);var S=document.createElement("a");S.setAttribute("id","bottomNavNext");S.setAttribute("href","#");S.setAttribute("title","successiva [s]");S.onclick=function(){myLightbox.changeImage(activeImage+1);return false};S.onmouseover=function(){$("fileBottomNavNextImageId").setAttribute("src",fileBottomNavNextImageOn);return false};S.onmouseout=function(){$("fileBottomNavNextImageId").setAttribute("src",fileBottomNavNextImageOff);return false};D.appendChild(S);var W=document.createElement("img");W.setAttribute("id","fileBottomNavNextImageId");S.appendChild(W);var J=document.createElement("a");J.setAttribute("id","bottomNavPrev");J.setAttribute("href","#");J.setAttribute("title","precedente [p]");J.onclick=function(){myLightbox.changeImage(activeImage-1);return false};J.onmouseover=function(){$("fileBottomNavPrevImageId").setAttribute("src",fileBottomNavPrevImageOn);return false};J.onmouseout=function(){$("fileBottomNavPrevImageId").setAttribute("src",fileBottomNavPrevImageOff);return false};D.appendChild(J);var Q=document.createElement("img");Q.setAttribute("id","fileBottomNavPrevImageId");J.appendChild(Q);var X=document.createElement("a");X.setAttribute("id","bottomNavZoom");X.setAttribute("href","#");X.setAttribute("title","zoom [z]");X.onclick=function(){myLightbox.zoomImage(activeImage);return false};X.onmouseover=function(){$("fileBottomNavZoomImageId").setAttribute("src",fileBottomNavZoomImageOn);return false};X.onmouseout=function(){$("fileBottomNavZoomImageId").setAttribute("src",fileBottomNavZoomImageOff);return false};D.appendChild(X);var e=document.createElement("img");e.setAttribute("id","fileBottomNavZoomImageId");X.appendChild(e);var k=document.createElement("div");k.setAttribute("id","objArchiveDiv");b.appendChild(k);var m=document.createElement("span");m.setAttribute("id","objArchive");m.innerHTML="";k.appendChild(m);var I=document.createElement("div");I.setAttribute("id","objTitleDiv");b.appendChild(I);var C=document.createElement("span");C.setAttribute("id","objTitle");C.innerHTML="";I.appendChild(C)},start:function(C){var H=getPageSize();Element.setHeight("overlay",H[1]);new Effect.Appear("overlay",{duration:0.2,from:0,to:0.8});imageArray=[];$("numberNavSelect").options.length=0;imageNum=0;if((typeof (C)=="object")&&(typeof (C[0])=="object")&&(typeof (C[0][0])=="string")&&(C[0][0]=="lightboxGallery")){if(typeof (C.lightbox_basedir)=="string"){var K=C.lightbox_basedir}else{var K="../js/lightbox/images/"}var L=K+"loading.gif";$("fileLoadingImageId").setAttribute("src",L);var J=K+"close_on.gif";var Q=K+"close_off.gif";$("bottomNavClose").onmouseover=function(){$("fileBottomNavCloseImageId").setAttribute("src",J);return false};$("bottomNavClose").onmouseout=function(){$("fileBottomNavCloseImageId").setAttribute("src",Q);return false};$("fileBottomNavCloseImageId").setAttribute("src",Q);var M=K+"next_on.gif";var P=K+"next_off.gif";$("bottomNavNext").onmouseover=function(){$("fileBottomNavNextImageId").setAttribute("src",M);return false};$("bottomNavNext").onmouseout=function(){$("fileBottomNavNextImageId").setAttribute("src",P);return false};$("fileBottomNavNextImageId").setAttribute("src",P);var N=K+"prev_on.gif";var F=K+"prev_off.gif";$("bottomNavPrev").onmouseover=function(){$("fileBottomNavPrevImageId").setAttribute("src",N);return false};$("bottomNavPrev").onmouseout=function(){$("fileBottomNavPrevImageId").setAttribute("src",F);return false};$("fileBottomNavPrevImageId").setAttribute("src",F);var O=K+"zoom_on.gif";var B=K+"zoom_off.gif";$("bottomNavZoom").onmouseover=function(){$("fileBottomNavZoomImageId").setAttribute("src",O);return false};$("bottomNavZoom").onmouseout=function(){$("fileBottomNavZoomImageId").setAttribute("src",B);return false};$("fileBottomNavZoomImageId").setAttribute("src",B);for(var E=1;E<C.length;E++){if(C.path){imageArray.push(new Array(C.path+trim(C[E][0]),C[E][1]))}else{imageArray.push(new Array(trim(C[E][0]),C[E][1]))}if(!imageArray[E-1][1].length){imageArray[E-1][1]=imageArray[E-1][0].substring(imageArray[E-1][0].lastIndexOf("/")+1,imageArray[E-1][0].lastIndexOf("."))}$("numberNavSelect").options[E-1]=new Option(E+" - "+imageArray[E-1][1],(E-1))}imageArray.removeDuplicates();if(typeof (C.archive)=="object"){imageArchiveLnk=C.archive[0];imageArchiveSize=C.archive[1];ih='<a href="'+imageArchiveLnk;ih+='" style="font-family:Verdana;font-size:8pt;font-weight:bold;color:#0000ff;">';ih+="archivio completo("+imageArchiveSize+")</a>";$("objArchive").innerHTML=ih}if(C.title){$("objTitle").innerHTML='<font face="Verdana" size="1" color="#000000"><b>'+C.title+"</b></font>"}imageArray.prebuilt=1}else{hideSelectBoxes();imageArray.prebuilt=0;if(!document.getElementsByTagName){return }var A=document.getElementsByTagName("a");if((C.getAttribute("rel")=="lightbox")){imageArray.push(new Array(C.getAttribute("href"),C.getAttribute("title")))}else{for(var E=0;E<A.length;E++){var D=A[E];if(D.getAttribute("href")&&(D.getAttribute("rel")==C.getAttribute("rel"))){imageArray.push(new Array(D.getAttribute("href"),D.getAttribute("title")))}}imageArray.removeDuplicates();while(imageArray[imageNum][0]!=C.getAttribute("href")){imageNum++}}}var H=getPageSize();var G=getPageScroll();var I=G[1]+(H[3]/15);Element.setTop("lightbox",I);Element.show("lightbox");this.enableKeyboardNav();this.changeImage(imageNum)},changeImage:function(A){if((A<0)||(A>(imageArray.length-1))||(A==activeImage)){$("numberNavInput").value=activeImage+1;return }activeImage=A;$("numberNavInput").value=activeImage+1;$("numberNavSelect").options.selectedIndex=activeImage;Element.show("loading");Element.hide("lightboxImage");Element.hide("hoverNav");Element.hide("prevLink");Element.hide("nextLink");Element.hide("imageDataContainer");Element.hide("numberDisplay");imgPreloader=new Image();imgPreloader.onload=function(){var C=imgPreloader.width;var E=imgPreloader.height;var F=imgPreloader.width;var D=imgPreloader.height;var B=0;Element.setSrc("lightboxImage",imageArray[activeImage][0]);if(C>Math.round(E*(4/3))){if(C>640){C=640;F=640;D=Math.round(F*(imgPreloader.height/imgPreloader.width))}}else{if(E>480){E=480;D=E;C=Math.round(E*(imgPreloader.width/imgPreloader.height));F=C}}if(C<465){F=465;if(E>480){E=480;Element.setHeight("lightboxImage",E)}}Element.setWidth("lightboxImage",C);myLightbox.resizeImageContainer(F,D)};imgPreloader.src=imageArray[activeImage][0]},zoomImage:function(A){if((A<0)||(A>(imageArray.length-1))){return }window.open(imageArray[activeImage][0],"_blank","width="+screen.availWidth+",height="+screen.availHeight+",resizable=1,status=0,scrollbars=1,location=0,top=0,left=0")},resizeImageContainer:function(B,A){this.wCur=Element.getWidth("outerImageContainer");this.hCur=Element.getHeight("outerImageContainer");this.xScale=((B+(borderSize*2))/this.wCur)*100;this.yScale=((A+(borderSize*2))/this.hCur)*100;wDiff=(this.wCur-borderSize*2)-B;hDiff=(this.hCur-borderSize*2)-A;if(!(hDiff==0)){new Effect.Scale("outerImageContainer",this.yScale,{scaleX:false,duration:resizeDuration,queue:"front"})}if(!(wDiff==0)){new Effect.Scale("outerImageContainer",this.xScale,{scaleY:false,delay:resizeDuration,duration:resizeDuration})}if((hDiff==0)&&(wDiff==0)){if(navigator.appVersion.indexOf("MSIE")!=-1){pause(250)}else{pause(100)}}Element.setHeight("prevLink",A);Element.setHeight("nextLink",A);Element.setWidth("imageDataContainer",B+(borderSize*2));this.showImage()},showImage:function(){Element.hide("loading");new Effect.Appear("lightboxImage",{duration:0.5,queue:"end",afterFinish:function(){myLightbox.updateDetails()}});this.preloadNeighborImages()},updateDetails:function(){if(!imageArray.prebuilt){Element.show("caption");Element.setInnerHTML("caption",imageArray[activeImage][1])}if(imageArray.length>1){Element.show("numberDisplay");ih='<table width="100%" cellpadding="0" cellspacong="0" style="font-family:Verdana; font-size:8pt;">';ih+='<td width="150" align="left">Immagine '+eval(activeImage+1)+" di "+imageArray.length+"</td>";ih+='<td align="center" style="font-size:11pt; font-family:Arial;color:#cc0000;"><b>'+imageArray[activeImage][1]+"</b></td>";ih+="</table>";Element.setInnerHTML("numberDisplay",ih)}new Effect.Parallel([new Effect.SlideDown("imageDataContainer",{sync:true,duration:resizeDuration+0.25,from:0,to:1}),new Effect.Appear("imageDataContainer",{sync:true,duration:1})],{duration:0.65,afterFinish:function(){myLightbox.updateNav()}})},updateNav:function(){Element.show("hoverNav");if(activeImage!=0){Element.show("prevLink");document.getElementById("prevLink").onclick=function(){myLightbox.changeImage(activeImage-1);return false}}if(activeImage!=(imageArray.length-1)){Element.show("nextLink");document.getElementById("nextLink").onclick=function(){myLightbox.changeImage(activeImage+1);return false}}this.enableKeyboardNav()},enableKeyboardNav:function(){document.onkeydown=this.keyboardAction},disableKeyboardNav:function(){document.onkeydown=""},keyboardAction:function(A){if(A==null){keycode=event.keyCode}else{keycode=A.which}if(keycode>90){return }if(keycode==13){myLightbox.changeImage(parseInt($("numberNavInput").value)-1);return }key=String.fromCharCode(keycode).toLowerCase();if((key=="x")||(key=="o")||(key=="c")){myLightbox.end()}else{if((key=="p")||(keycode==37)){if(activeImage!=0){myLightbox.disableKeyboardNav();myLightbox.changeImage(activeImage-1)}}else{if((key=="s")||(keycode==39)){if(activeImage!=(imageArray.length-1)){myLightbox.disableKeyboardNav();myLightbox.changeImage(activeImage+1)}}else{if((key=="z")){myLightbox.zoomImage(activeImage)}}}}},preloadNeighborImages:function(){if((imageArray.length-1)>activeImage){preloadNextImage=new Image();preloadNextImage.src=imageArray[activeImage+1][0]}if(activeImage>0){preloadPrevImage=new Image();preloadPrevImage.src=imageArray[activeImage-1][0]}},end:function(){this.disableKeyboardNav();Element.hide("lightbox");new Effect.Fade("overlay",{duration:0.2});showSelectBoxes()}};function getPageScroll(){var A;if(self.pageYOffset){A=self.pageYOffset}else{if(document.documentElement&&document.documentElement.scrollTop){A=document.documentElement.scrollTop}else{if(document.body){A=document.body.scrollTop}}}arrayPageScroll=new Array("",A);return arrayPageScroll}function getPageSize(){var C,A;if(window.innerHeight&&window.scrollMaxY){C=document.body.scrollWidth;A=window.innerHeight+window.scrollMaxY}else{if(document.body.scrollHeight>document.body.offsetHeight){C=document.body.scrollWidth;A=document.body.scrollHeight}else{C=document.body.offsetWidth;A=document.body.offsetHeight}}var B,D;if(self.innerHeight){B=self.innerWidth;D=self.innerHeight}else{if(document.documentElement&&document.documentElement.clientHeight){B=document.documentElement.clientWidth;D=document.documentElement.clientHeight}else{if(document.body){B=document.body.clientWidth;D=document.body.clientHeight}}}if(A<D){pageHeight=D}else{pageHeight=A}if(C<B){pageWidth=B}else{pageWidth=C}arrayPageSize=new Array(pageWidth,pageHeight,B,D);return arrayPageSize}function getKey(A){if(A==null){keycode=event.keyCode}else{keycode=A.which}key=String.fromCharCode(keycode).toLowerCase();if(key=="x"){}}function listenKey(){document.onkeypress=getKey}function showSelectBoxes(){selects=document.getElementsByTagName("select");for(i=0;i!=selects.length;i++){selects[i].style.visibility="visible"}}function hideSelectBoxes(){selects=document.getElementsByTagName("select");for(i=0;i!=selects.length;i++){selects[i].style.visibility="hidden"}}function pause(B){var A=new Date();var C=A.getTime()+B;while(true){A=new Date();if(A.getTime()>C){return }}}function textCounter(C,A,B,D){if(D&&isNaN(C.value)){C.value="";return }if(C.value.length>B){C.value=C.value.substring(0,B)}else{if(A!=null){A.value=B-C.value.length}}}function myLightboxStart(A){if(typeof (myLightbox)!="undefined"){myLightbox.start(A)}else{alert("Occorre attendere il caricamento completo della pagina\n\nSe continui a vedere questo messaggio premi F5 ed attendi il caricamento completo prima di cercare di aprire il link")}}function LTrim(B){var A=/\s*((\S+\s*)*)/;return B.replace(A,"$1")}function RTrim(B){var A=/((\s*\S+)*)\s*/;return B.replace(A,"$1")}function trim(A){return LTrim(RTrim(A))}function initLightbox(){myLightbox=new Lightbox()}Event.observe(window,"load",initLightbox,false)
