var TPSlideShowClass={initialize:function(b,a){this.setOptions({showMenu:true,showInfopane:true,embedLinks:true,fadeDuration:500,readMore:true,readMoreText:"Leggi...",showTitle:true,titleLink:true,showDescription:true,timed:false,delay:9000,preloader:true,preloaderImage:true,preloaderErrorImage:true,manualData:[],populateData:true,destroyAfterPopulate:true,elementSelector:"div.imageElement",titleSelector:"h3",subtitleSelector:"p",linkSelector:"a.open",imageSelector:"img.full",defaultTransition:"fade",slideInfoZoneOpacity:0.7,slideInfoZoneSlide:true,baseClass:"TPNiceSlideShowGallery",menuSlide:"TPNiceSlideShowMenu",menuSlideActive:"active",scrollBar:false,itemCount:1,scrollBarContent:false,scrollBarArea:false,scrollBarHandle:false},a);this.fireEvent("onInit");this.currentIter=0;this.lastIter=0;this.maxIter=0;this.galleryElement=b;this.galleryData=this.options.manualData;this.galleryInit=1;this.galleryElements=Array();this.galleryElement.addClass(this.options.baseClass);if(this.options.scrollBar){this.steps=this.options.scrollBarContent.getSize().scrollSize.y-this.options.scrollBarContent.getSize().size.y;var d=new Fx.Scroll(this.options.scrollBarContent,{wait:false});var c=new Slider(this.options.scrollBarArea,this.options.scrollBarHandle,{mode:"vertical",steps:this.steps,onChange:function(f){var e=0;var g=f;d.scrollTo(e,g)}}).set(0);this.slider=c;this.sliderHeight=this.options.scrollBarContent.getSize().scrollSize.y/this.options.itemCount;$$(this.options.scrollBarContent,this.options.scrollBarArea).addEvent("mousewheel",function(g){g=new Event(g).stop();var f=c.step-g.wheel*30;c.set(f)});$(document.body).addEvent("mouseleave",function(){c.drag.stop()})}this.options.default_timed=this.options.timed;if(this.options.showMenu){this.tpNav=$$("#"+this.options.menuSlide+" div.TPNiceSlideShowMenuContent ");this.tpNav.each(function(f,e){if(e==0){f.addClass(this.options.menuSlideActive)}f.addEvent("click",function(){this.goTo(e)}.bind(this,f,e))},this)}this.populateFrom=b;if(this.options.populateData){this.populateData()}b.style.display="block";if(this.options.embedLinks){this.galleryElement=b}this.constructElements();this.loadingElement=new Element("div").addClass("loadingElement").injectInside(b);if(this.options.showInfopane){this.initInfoSlideshow()}this.doSlideShow(1)},populateData:function(){currentArrayPlace=this.galleryData.length;options=this.options;var a=$A(this.galleryData);a.extend(this.populateGallery(this.populateFrom,currentArrayPlace));this.galleryData=a;this.fireEvent("onPopulated")},populateGallery:function(a,c){var b=[];options=this.options;currentArrayPlace=c;a.getElements(options.elementSelector).each(function(d){elementDict={image:d.getElement(options.imageSelector).getProperty("src"),number:currentArrayPlace,transition:this.options.defaultTransition};elementDict.extend=$extend;if(options.showInfopane){elementDict.extend({title:d.getElement(options.titleSelector).innerHTML,description:d.getElement(options.subtitleSelector).innerHTML})}elementDict.extend({link:d.getElement(options.linkSelector).href||false,linkTitle:d.getElement(options.linkSelector).title||false,linkTarget:d.getElement(options.linkSelector).getProperty("target")||false});b.extend([elementDict]);currentArrayPlace++;if(this.options.destroyAfterPopulate){d.remove()}});return b},constructElements:function(){el=this.galleryElement;this.maxIter=this.galleryData.length;var b;for(i=0;i<this.galleryData.length;i++){if(this.options.embedLinks){var a="a"}else{var a="div"}var b=new Fx.Styles(new Element(a).addClass("slideElement").setStyles({position:"absolute",left:"0px",right:"0px",margin:"0px",padding:"0px",backgroundPosition:"center center",opacity:"0"}).injectInside(el),"opacity",{duration:this.options.fadeDuration});if(this.options.embedLinks){b.element.setProperties({href:this.galleryData[parseInt(i)].link,title:this.galleryData[parseInt(i)].linkTitle})}if(this.options.preloader){b.source=this.galleryData[i].image;b.loaded=false;b.load=function(c){if(!c.loaded){new Asset.image(c.source,{onload:function(d){d.element.setStyle("backgroundImage","url('"+d.source+"')");d.loaded=true}.bind(this,c)})}}.pass(b,this)}else{b.element.setStyle("backgroundImage","url('"+this.galleryData[i].image+"')")}this.galleryElements[parseInt(i)]=b}},destroySlideShow:function(c){var d=c.className;var f=new Element("div").addClass("myClassName");this.clearTimer();this.options.timed=false;var e=c.getParent();var b=c.parentNode.getChildren();var a=0;for(a=0;a<b.length;a++){e.replaceChild(f,b[a])}},startSlideShow:function(){this.fireEvent("onStart");this.loadingElement.style.display="none";this.lastIter=this.maxIter-1;this.currentIter=0;this.galleryInit=0;this.galleryElements[parseInt(this.currentIter)].set({opacity:1});if(this.options.showInfopane){this.showInfoSlideShow.delay(0,this)}this.prepareTimer()},nextItem:function(){this.fireEvent("onNextCalled");this.nextIter=this.currentIter+1;if(this.nextIter>=this.maxIter){this.nextIter=0}this.galleryInit=0;this.goTo(this.nextIter)},prevItem:function(){this.fireEvent("onPreviousCalled");this.nextIter=this.currentIter-1;if(this.nextIter<=-1){this.nextIter=this.maxIter-1}this.galleryInit=0;this.goTo(this.nextIter)},goTo:function(a){if(this.options.scrollBar){this.slider.set(a*this.sliderHeight)}this.clearTimer();if(this.options.preloader){this.galleryElements[a].load();if(a==0){this.galleryElements[this.maxIter-1].load()}else{this.galleryElements[a-1].load()}if(a==(this.maxIter-1)){this.galleryElements[0].load()}else{this.galleryElements[a+1].load()}}if(this.options.showInfopane){this.hideInfoSlideShow().chain(this.changeItem.pass(a,this))}else{this.currentChangeDelay=this.changeItem.delay(0,this,a)}this.prepareTimer();if(this.options.showMenu){this.tpSlide=$$("#"+this.options.menuSlide+" div");this.tpSlide.each(function(c,b){if(b==a){c.addClass(this.options.menuSlideActive)}else{c.removeClass(this.options.menuSlideActive)}},this)}},changeItem:function(a){this.galleryInit=0;if(this.currentIter!=a){for(i=0;i<this.maxIter;i++){if((i!=this.currentIter)){this.galleryElements[i].set({opacity:0})}}TPSlideShowClass.Transitions[this.galleryData[a].transition].pass([this.galleryElements[this.currentIter],this.galleryElements[a],this.currentIter,a],this)();this.currentIter=a}this.doSlideShow.bind(this)();this.fireEvent("onChanged")},clearTimer:function(){if(this.options.timed){$clear(this.timer)}},prepareTimer:function(){if(this.options.timed){this.timer=this.nextItem.delay(this.options.delay,this)}},doSlideShow:function(a){if(this.galleryInit==1){imgPreloader=new Image();imgPreloader.onload=function(){this.startSlideShow.delay(10,this)}.bind(this);imgPreloader.src=this.galleryData[0].image;if(this.options.preloader){this.galleryElements[0].load()}}else{if(this.options.showInfopane){if(this.options.showInfopane){this.showInfoSlideShow()}}}},log:function(a){if(console.log){console.log(a)}},initInfoSlideshow:function(){this.slideInfoZone=new Fx.Styles(new Element("div").addClass("slideInfoZone").injectInside($(this.galleryElement))).set({opacity:0});this.galleryElement.addEvents({mouseover:function(a){this.options.timed=false;$clear(this.timer)}.pass(this.slideInfoZone,this)});this.galleryElement.addEvents({mouseleave:function(a){if(this.options.default_timed){this.options.timed=true;this.timer=this.nextItem.delay(this.options.delay,this)}}.pass(this.slideInfoZone,this)});this.slideInfoZoneDiv=new Fx.Styles(new Element("div").addClass("innerSlideInfoZone").injectInside($(this.slideInfoZone.element)));if(this.options.showTitle){this.slideInfoZoneTitle=new Element("div").addClass("slideInfoZoneTitle").injectInside(this.slideInfoZoneDiv.element)}if(this.options.showDescription){this.slideInfoZoneDescription=new Element("div").addClass("slideInfoZoneDescription").injectInside(this.slideInfoZoneDiv.element)}if(this.options.readMore){this.slideInfoZoneReadMore=new Element("div").addClass("slideInfoZoneReadMore").injectInside(this.slideInfoZoneDiv.element)}this.slideInfoZone.element.setStyle("opacity",0)},showInfoSlideShow:function(){this.fireEvent("onShowInfopane");this.slideInfoZone.clearTimer();if(this.options.showTitle){element=this.slideInfoZoneTitle;if(this.options.titleLink){this.slideInfoZoneTitle.setHTML('<a id="titlecarousel'+this.currentIter+'" href="'+this.galleryData[this.currentIter].link+'" title="'+this.galleryData[this.currentIter].linkTitle+'">'+this.galleryData[this.currentIter].title+"</a>");$("titlecarousel"+this.currentIter).removeEvent("click");$("titlecarousel"+this.currentIter).addEvent("click",function(a){a=new Event(a).stop();var b=linkannuncimanifestazioni(this.getProperty("href"))})}else{this.slideInfoZoneTitle.setHTML(this.galleryData[this.currentIter].title)}}if(this.options.showDescription){element=this.slideInfoZoneDescription;element.setHTML(this.galleryData[this.currentIter].description)}if(this.options.readMore){element=this.slideInfoZoneReadMore;this.slideInfoZoneReadMore.setHTML('<a id="hpr_sizrm'+this.currentIter+'" href="'+this.galleryData[this.currentIter].link+'" title="'+this.galleryData[this.currentIter].linkTitle+'">'+this.options.readMoreText+"</a>");$("hpr_sizrm"+this.currentIter).addEvent("click",function(a){a=new Event(a).stop();var b=linkannuncimanifestazioni(this.getProperty("href"))})}this.slideInfoZone.start({opacity:[0,this.options.slideInfoZoneOpacity]});return this.slideInfoZone},hideInfoSlideShow:function(){this.fireEvent("onHideInfopane");this.slideInfoZone.clearTimer();this.slideInfoZone.start({opacity:0});return this.slideInfoZone},flushGallery:function(){this.galleryElements.each(function(a){a.element.remove();a=a.element=null});this.galleryElements=[]},changeData:function(a){this.galleryData=a;this.clearTimer();this.flushGallery();this.constructElements();if(this.options.showInfopane){this.hideInfoSlideShow()}this.galleryInit=1;this.lastIter=0;this.currentIter=0;this.doSlideShow(1)},makeScrollbar:function(){}};TPSlideShowClass=new Class(TPSlideShowClass);TPSlideShowClass.implement(new Events);TPSlideShowClass.implement(new Options);TPSlideShowClass.Transitions=new Abstract({fade:function(c,d,a,b){c.options.transition=d.options.transition=Fx.Transitions.linear;c.options.duration=d.options.duration=this.options.fadeDuration;if(b>a){d.start({opacity:1})}else{d.set({opacity:1});c.start({opacity:0})}},crossfade:function(c,d,a,b){c.options.transition=d.options.transition=Fx.Transitions.linear;c.options.duration=d.options.duration=this.options.fadeDuration;d.start({opacity:1});c.start({opacity:0})},fadebg:function(c,d,a,b){c.options.transition=d.options.transition=Fx.Transitions.linear;c.options.duration=d.options.duration=this.options.fadeDuration/2;c.start({opacity:0}).chain(d.start.pass([{opacity:1}],d))}});var Preloader=new Class({Implements:[Events,Options],options:{root:"",period:100},initialize:function(a){this.setOptions(a)},load:function(a){this.index=0;this.images=[];this.sources=this.temps=a;this.total=this.sources.length;this.fireEvent("onStart",[this.index,this.total]);this.timer=this.progress.periodical(this.options.period,this);this.sources.each(function(c,b){this.images[b]=new Asset.image(this.options.root+c,{onload:function(){this.index++;if(this.images[b]){this.fireEvent("onLoad",[this.images[b],b,c])}}.bind(this),onerror:function(){this.index++;this.fireEvent("onError",[this.images.splice(b,1),b,c])}.bind(this),onabort:function(){this.index++;this.fireEvent("onError",[this.images.splice(b,1),b,c])}.bind(this)})},this)},progress:function(){this.fireEvent("onProgress",[Math.min(this.index,this.total),this.total]);if(this.index>=this.total){this.complete()}},complete:function(){$clear(this.timer);this.fireEvent("onComplete",[this.images])},cancel:function(){$clear(this.timer)}});Preloader.implement(new Events,new Options);