// Copyright (c) 2007-2008 WoollySheep
// <http://www.woolly-sheep.net>

var FotoScroller=new Class({Implements:[Events,Options],options:{fix:0,duration:1300,thumbs:false,transition:"quad:in:out"},initialize:function(B,A){this.setOptions(A);
this.element=$(B);this.gallery=this.element.getFirst();$$([this.element,this.gallery]).setStyles({"overflow":"hidden","position":"relative"});
this.full=Math.ceil(this.gallery.getScrollSize().x-this.element.getStyle("width").toInt())+this.options.fix;
this.steps=(this.gallery.getScrollSize().x/this.element.getOffsetSize().x).toInt();this.step=(this.full/this.steps);
this.current=0;this.preloads(this.element.getElements("img"));this.build().attachEvents()
},build:function(){var A=this;this.left=new Element("a",{"class":"left","href":"#"}).inject(this.element,"top");
this.right=new Element("a",{"class":"right","href":"#"}).inject(this.element,"bottom");this.scroller=new Fx.Scroll(this.gallery,{link:"cancel",duration:this.options.duration,transition:this.options.transition});
return this.updateArrows()},attachEvents:function(){var A=this;$$(this.right,this.left).addEvent("click",function(C){var B=(this==A.right)?+1:-1;
C.stop();A.current=Math.ceil(A.current+(A.step*B)).limit(0,A.full);A.updateArrows().scroller.start(A.current,0)
});return this},updateArrows:function(){if(this.gallery.getOffsetSize().x==this.gallery.getScrollSize().x){$$(this.right,this.left).setStyle("visibility","hidden")
}else{this.left.setStyle("visibility",(!this.current)?"hidden":"visible");this.right.setStyle("visibility",(this.current==this.full)?"hidden":"visible")
}return this},preloads:function(A){var B=this.options.thumbs;A.each(function(F,E){var D={"width":(B.x||F.width),"height":(B.y||F.height)};
var G=F.src;F.setStyle("display","none");var C=new Element("div",{"styles":{"width":D.width,"height":D.height,"margin":"0 auto","opacity":0.6},"class":"preload"}).inject(F,"before");
new Asset.image(G,{onload:function(){F.setStyle("display","");C.dispose()}})});return this}});Gallery={"filtersStyles":{"height":(Browser.Engine.trident)?60:40,"padding-top":12,"opacity":0.8,"margin":0},"detailsRadius":{"out":{"-moz-border-radius-bottomleft":"9px","-moz-border-radius-bottomright":"9px","-webkit-border-bottom-left-radius":"10px","-webkit-border-bottom-right-radius":"10px"},"in":{"-moz-border-radius":"9px","-webkit-border-radius":"10px"}},init:function(){Gallery["container"]=$("df_container"),Gallery["filters"]=$("topAction"),Gallery["filtersFoto"]=$("foto_filter");
return Gallery},start:function(){Gallery.animate(Gallery.action());Gallery.init();Gallery["filtersFoto"].getElement("input[type=submit]").dispose();
return Gallery},action:function(){Gallery.actions=[];var B=new Hash({"position":"absolute","left":0,"width":748,"height":100,"overflow":"hidden"});
if(Browser.Engine.trident){B.set("background","url(/assets/styles/blank.gif)")}var A=["filters","df_details"];
["topAction","bottomAction"].each(function(F,D){var G=(!D)?"top":"bottom";var H=(!D)?-52:-103;if(!D){B.set("top",0)
}else{B.remove("top").set("bottom",0)}if(!$(F)){var E=new Element("div",{id:F,styles:B}).inject(document.body).wraps(A[D])
}$(A[D]).set("tween","bottom",H,{duration:300,link:"cancel",transition:"quad:out"});if(!D){if(!Cookie.get("diderotGallery")){Cookie.set("diderotGallery",0)
}$("filters").setStyle("top",Cookie.get("diderotGallery").toInt());new Element("a",{id:"filtersButton",styles:{"display":"block","background":"url(/assets/images/filters.gif) top center no-repeat","opacity":0.8,"z-index":1000,"cursor":"pointer","position":"absolute","bottom":(Browser.Engine.trident)?0:-18,"left":0,"width":43,"height":18},"class":"tips","title":"Filtri :: Clicka per visualizzare i filtri per le foto","events":{"click":function(K){K.stop();
var J=$("filters"),I=Gallery.actions[0].get("tween","top");if(!J.getStyle("top").toInt()){Cookie.set("diderotGallery",-52);
I.start(-52)}else{Cookie.set("diderotGallery",0);I.start(0)}}}}).inject($("filters"));if(!D){$(A[D]).setStyle("top",Cookie.get("diderotGallery"))
}}else{var C=$(A[D]).get("tween","bottom").set(H);$(F).addEvents({"mouseenter":function(){$clear(Gallery.delayed[1]);
$clear(Gallery.delayed[2]);C.start(0)},"mouseleave":function(){$clear(Gallery.delayed[1]);$clear(Gallery.delayed[2]);
C.start(H)}})}Gallery.actions.push($(A[D]))});return Gallery.actions},animate:function(){var A=Gallery.actions[1].get("tween","bottom");
var B={"start":0,"end":-103};A.cancel();Gallery.delayed=[];Gallery.delayed[1]=A.start.delay(50,A,B["start"]);
Gallery.delayed[2]=A.start.delay(2000,A,B["end"]);return Gallery},filtersFix:function(){if(Gallery["filters"]&&Gallery["container"]){Gallery["filters"].inject(Gallery["container"],"top").getFirst().setStyles(Gallery.filtersStyles);
Gallery["filters"]=Gallery["filters"].clone(true).set("id",Gallery["filters"].id)}var B=$("foto_filter");
if(B){var A=B.getElements("select");A.addEvent("change",function(){B.submit()})}return Gallery},forms:function(){var B=$("getfoto_form");
if(B){var A=$("scroller").getElements("a");A.addEvent("click",function(C){C.stop();var D=this.get("href").split("/");
D=D[D.length-1];$("getfoto_field").value=D;B.fireEvent("submit")});B.addEvent("submit",function(C){Gallery.actions[1].get("tween","bottom").cancel();
$clear(Gallery.delayed[1]);$clear(Gallery.delayed[2]);var D=$("fotobiggosa").empty().addClass("ajax-loading");
this.set("send",{"onComplete":function(F){D.removeClass("ajax-loading").set("html",F).getElement("#df_details").setStyle("opacity",0.8);
var E=$("df_container");Gallery["filters"].clone(true).inject(E,"top").set("id","topAction").getFirst().set("id","filters").getElement("form").set("id","foto_filter");
Gallery.filtersFix();Gallery.animate(Gallery.action());Site.tips();if(Site.admin){Site.conferma()}}}).send()
})}return Gallery},details:function(){var B=$("df_details"),A=$("scroller");if(B){B.setStyle("opacity",0.8)
}if(!A){return Gallery}A.setStyles(Gallery["detailsRadius"]["out"]).getFirst().setStyles(Gallery["detailsRadius"]["in"]);
var D=A.getElements("li");D.getParent("ul").setStyle("width",D.length*110);var C=new FotoScroller(A,{steps:2,fix:60,duration:700,transition:"quad:in:out",thumbs:{x:80,y:80}});
return Gallery}};window.addEvent("domready",function(){Gallery.start().filtersFix().forms().details()
})
