var disableGalleryCarouselNav=false,timerGalleryCarousel,timeAfterSwichGalleryCarouselNav=5E3,timeAfterSwichGalleryCarouselNavData,inicializeGalleryCarousel=function(a){a=$(a);var c=a.getElement("div.gallery_carousel_content").getElements("div");c.each(function(d){d.hasClass("selected")?d.setStyle("opacity",1):d.setStyle("opacity",0);d.setStyle("display","block")});a=a.getElement("div.links");var b=a.getElement("span.numbers").getElements("a");b.each(function(d){d.addEvent("click",function(e){e.stop();
galleryCarouselSwitchTo(parseInt(d.rel),c)})});a.getElement("a.nav_left").addEvent("click",function(d){d.stop();galleryCarouselSwitchByNav("preview",c,b,b.length)});a.getElement("a.nav_right").addEvent("click",function(d){d.stop();galleryCarouselSwitchByNav("next",c,b,b.length)});timeAfterSwichGalleryCarouselNavData=new Hash({numbersTimer:b,itemsTimer:c});galleryCarouselActivateTimer()},galleryCarouselSwitchTo=function(a,c){a--;galleryCarouselActivateLink(a);c.each(function(b){b.hasClass("selected")&&
(new Fx.Tween(b,{link:"chain",duration:300,onStart:function(){disableGalleryCarouselNav=true},onComplete:function(d){d.removeClass("selected");(new Fx.Tween(c[a],{link:"chain",duration:300,onComplete:function(e){e.addClass("selected");disableGalleryCarouselNav=false}})).start("opacity","1")}})).start("opacity","0")});galleryCarouselActivateTimer()},galleryCarouselActivateNext=function(){var a=this.numbersTimer,c=this.itemsTimer,b=1,d=1;a.each(function(e){if(e.hasClass("selected")){b=d;e.removeClass("selected")}d++});
b++;b<=a.length?galleryCarouselSwitchTo(b,c):galleryCarouselSwitchTo(1,c)},galleryCarouselActivateLink=function(a){var c=$("gallery_carousel").getElement("div.links").getElement("span.numbers").getElements("a");if(a>=0&&a<=c.length-1){c.each(function(b){b.hasClass("selected")&&b.removeClass("selected")});c[a].addClass("selected")}},galleryCarouselSwitchByNav=function(a,c,b,d){if(!disableGalleryCarouselNav){var e=1,f=1;b.each(function(g){if(g.hasClass("selected"))e=f;f++});switch(a){case "next":e+
1<=d&&galleryCarouselSwitchTo(e+1,c);break;case "preview":e-1>=1&&galleryCarouselSwitchTo(e-1,c);break}galleryCarouselActivateTimer()}},galleryCarouselActivateTimer=function(){$clear(timerGalleryCarousel);timerGalleryCarousel=galleryCarouselActivateNext.periodical(timeAfterSwichGalleryCarouselNav,timeAfterSwichGalleryCarouselNavData)};

