text: /*
  ---
  description: moogallery creates an interactive gallery of images, videos and audios. Given the thumbs paths and some information, the thumbs are loaded sequentially and inserted in a table structure automatically sized according to the size of the container, then events are added in order to manage tips, lightbox widget (and navigation through media) and show media's meta information. Videos can be hosted on youtube or vimeo, audio files are inserted following html5 specifications. If used with cpoyer's mootools-mobile (https://github.com/cpojer/mootools-mobile) supports swipe gestures on mobile (android, ios) to change media in the lightbox view (activate the support_mobile option).
  
  license: MIT-style
  
  authors:
  - abidibo <dev@abidibo.net>
  
  requires:
  - core/1.3
  
  provides:
  - moogallery
  
  ...
  
  For documentation, demo and download link please visit http://www.abidibo.net/projects/js/moogallery
  
  */
  var moogallery=new Class({Implements:[Options,Events],options:{show_bullets:true,support_mobile:false,onComplete:function(){}},initialize:function(b,a,c){this.container=typeOf(b)=="element"?b:$(b);this.container.setStyle("padding","0");this.items_opt=a;this.setOptions(c);this.mobile=this.options.support_mobile&&(Browser.Platform.ios||Browser.Platform.android)?true:false;this.video_base_link={youtube:"http://www.youtube.com/embed/",vimeo:"http://player.vimeo.com/video/"};this.items=[];this.thumbs=[];this.max_z_index=this.getMaxZindex();this.table=new Element("table",{"class":"moogallery"}).inject(this.container);this.tr=new Element("tr").inject(this.table);this.first_row=true;this.cols=0;this.actual_col=1;this.tr_width=0;this.container_width=this.container.getCoordinates().width;this.addEvent("item_rendered",function(d){if(typeOf(this.items_opt[d])!="null"){this.renderItem(this.items_opt[d])}else{this.fireEvent("complete")}});this.renderItem(this.items_opt[0])},getMaxZindex:function(){var a=0;$$("body *").each(function(b){if(b.getStyle("z-index").toInt()){a=Math.max(a,b.getStyle("z-index").toInt())}});return a},getViewport:function(){var b,a,d,c,f,e;if(typeof window.innerWidth!="undefined"){b=window.innerWidth,a=window.innerHeight}else{if(typeof document.documentElement!="undefined"&&typeof document.documentElement.clientWidth!="undefined"&&document.documentElement.clientWidth!=0){b=document.documentElement.clientWidth,a=document.documentElement.clientHeight}}c=typeof self.pageYOffset!="undefined"?self.pageYOffset:(document.documentElement&&document.documentElement.scrollTop)?document.documentElement.scrollTop:document.body.clientHeight;d=typeof self.pageXOffset!="undefined"?self.pageXOffset:(document.documentElement&&document.documentElement.scrollTop)?document.documentElement.scrollLeft:document.body.clientWidth;f=d+b/2;e=c+a/2;return{width:b,height:a,left:d,top:c,cX:f,cY:e}},renderItem:function(a){var b=new Element("img");b.onload=function(){var e=new Element("td");b.inject(e);if(!this.first_row){if(this.actual_col>=this.cols){this.tr=new Element("tr").inject(this.table);this.actual_col=1}else{this.actual_col++}e.inject(this.tr)}else{e.inject(this.tr);if(this.table.getCoordinates().width>=this.container_width){e.dispose();this.tr=new Element("tr").inject(this.table);e.inject(this.tr);this.first_row=false}else{this.cols++}}this.fireEvent("item_rendered",this.items_opt.indexOf(a)+1)}.bind(this);b.src=a.thumb;this.setTip(b,a);this.setLightbox(b,a);this.thumbs.push(b);if(typeOf(a.img)!="null"){var d=new Element("img");d.src=a.img}else{if(typeOf(a.youtube)!="null"||typeOf(a.vimeo)!="null"){var c=typeOf(a.youtube)!="null"?"youtube":"vimeo";var d=new Element("iframe");d.src=this.video_base_link[c]+a[c];d.setProperty("frameborder","0");d.setProperty("allowfullscreen","");d.setProperty("width",a.video_width);d.setProperty("height",a.video_height)}else{if(typeOf(a.mpeg)!="null"||typeOf(a.ogg)!=null){var d=new Element("audio",{text:"Your browser does not support the audio element"}).addEvent("click",function(f){f.stopPropagation()});d.setProperty("controls","controls");["mpeg","ogg"].each(function(e){if(typeOf(a[e])!="null"){var f=new Element("source",{src:a[e],type:"audio/"+e});f.inject(d,"top")}})}}}this.items.push(d)}.protect(),setTip:function(b,a){var c=new Element("div",{"class":"moogallery_tip"});c.set("html","<b>"+a.title+"</b>");b.addEvents({mousemove:function(d){c.setStyles({position:"absolute",top:(d.page.y+10)+"px",left:(d.page.x+10)+"px","z-index":this.max_z_index++});c.inject(document.body)}.bind(this),mouseout:function(d){c.dispose()}})}.protect(),setLightbox:function(b,a){b.addEvent("click",function(){this.renderOverlay(this.renderLightbox.bind(this,a))}.bind(this))}.protect(),renderOverlay:function(b){var a=document.getScrollSize();this.overlay=new Element("div",{"class":"moogallery_overlay"});this.overlay.setStyles({position:"absolute",top:0,left:0,"z-index":this.max_z_index++,width:a.x,height:a.y,opacity:0});this.overlay.inject(document.body);var c=new Fx.Tween(this.overlay,{property:"opacity"});c.start(0,0.9).chain(b)},renderLightbox:function(a){this.lightbox_container=new Element("div.moogallery_lightbox_container").setStyles({visibility:"hidden",position:"absolute",overflow:"hidden",margin:"0"});this.lightbox_container.inject(document.body);this.lightbox_container.addEvent("click",function(c){if(c.target.get("tag")=="a"){return true}var b=this.lightbox_container.getCoordinates();if(c.page.x<b.left+b.width/2){if(this.index==0){return false}this.changeItem(this.index-1)}else{if(this.index==this.items.length-1){return false}this.changeItem(this.index+1)}}.bind(this));this.lightbox_container.addEvent("mouseover",function(c){var b=this.lightbox_container.getCoordinates();if(c.page.x<b.left+b.width/2){if(this.arrow_next.getStyle("opacity")!="0"){this.arrow_next.fade("hide")}if(this.index==0){return false}this.arrow_prev.fade("in")}else{if(this.arrow_prev.getStyle("opacity")!="0"){this.arrow_prev.fade("hide")}if(this.index==this.items.length-1){return false}this.arrow_next.fade("in")}}.bind(this));this.lightbox_container.addEvent("mouseleave",function(b){this.arrow_next.fade("hide");this.arrow_prev.fade("hide")}.bind(this));this.index=this.items_opt.indexOf(a);this.renderLightboxContainer();if(this.mobile&&Browser.Features.Touch){document.body.addEvent("swipe",function(b){Element.disableCustomEvents();(function(){Element.enableCustomEvents()}).delay(1000);if(b.direction=="left"){if(this.index==this.items.length-1){return false}this.changeItem(this.index+1)}else{if(this.index==0){return false}this.changeItem(this.index-1)}}.bind(this))}},renderLightboxContainer:function(){item_opt=this.items_opt[this.index];var p=this.items[this.index];var o=new Element("div.moogallery_lightbox_info");var b=new Element("p.moogallery_lightbox_info_title").set("html",item_opt.title);var k=typeOf(item_opt.description)==="null"?"":item_opt.description;var q=new Element("div.moogallery_lightbox_info_description").set("html",k);var n=typeOf(item_opt.credits)==="null"?"":item_opt.credits;var i=new Element("p.moogallery_lightbox_info_credits").set("html",n);o.adopt(b,q,i);var f=this.renderNavigation(item_opt);var l=new Element("div").setStyle("opacity","0").inject(this.lightbox_container);l.adopt(p,f,o);var e=this.lightbox_container.getStyle("padding").toInt()*2+this.lightbox_container.getStyle("border-width").toInt()*2;var h=p.getCoordinates().width;if(this.lightbox_container.getStyle("visibility")=="hidden"){var m=20;var g=20+e;var d=this.getViewport();this.lightbox_container.setStyles({width:m+"px",height:m+"px",top:(d.cY-g/2)+"px",left:(d.cX-g/2)+"px",visibility:"visible","z-index":this.max_z_index++})}var j=this.lightbox_container.getCoordinates().width;var a=this.lightbox_container.getCoordinates().height;var c=new Fx.Morph(this.lightbox_container,{duration:"short"});c.start({width:h,left:this.lightbox_container.getStyle("left").toInt()-(h+e-j)/2}).chain(function(){l.adopt(f,o);var r=l.getCoordinates().height;c.start({height:r,top:this.lightbox_container.getStyle("top").toInt()-(r+e-a)/2,}).chain(function(){l.fade("in")})}.bind(this));this.overlay.addEvent("click",function(s){var r=new DOMEvent(s);if(r.target!=this.container){this.lightbox_container.dispose();var t=new Fx.Tween(this.overlay,{property:"opacity"});t.start(0.9,0).chain(function(){this.overlay.dispose()}.bind(this));if(this.mobile&&Browser.Features.Touch){document.body.removeEvent("swipe")}}}.bind(this))},renderNavigation:function(b){var e=this.items_opt.indexOf(b);var g=new Element("div.moogallery_nav");this.arrow_next=new Element("div",{"class":"arrow arrow_next"}).setStyle("opacity","0");this.arrow_prev=new Element("div",{"class":"arrow arrow_prev"}).setStyle("opacity","0");var c=new Element("div.nav_arrows").adopt(this.arrow_next,this.arrow_prev);var h=(e+1)+"/"+this.items_opt.length;var a=new Element("div.moogallery_nav_info").set("text",h);g.grab(c);if(this.options.show_bullets){var d=new Element("table.moogallery_nav_table");var f=new Element("tr").inject(d);this.items.each(function(l,k){var m=new Element("td").inject(f);var j=new Element("div.moogallery_nav_bullet").inject(m);if(k==e){j.addClass("bullet_selected")}else{j.addEvent("click",function(i){i.stopPropagation();this.changeItem(k)}.bind(this))}}.bind(this));d.inject(g)}g.grab(a);return g}.protect(),changeItem:function(a){this.index=a;var b=new Fx.Tween(this.lightbox_container.getChildren("div")[0],{property:"opacity",duration:"short"});b.start(1,0).chain(function(){this.lightbox_container.empty();this.renderLightboxContainer()}.bind(this))}});
  