/*
 * @version   $Id: mosaic.js 10889 2013-05-30 07:48:35Z btowles $
 * @author    RocketTheme http://www.rockettheme.com
 * @copyright Copyright (C) 2007 - 2014 RocketTheme, LLC
 * @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
 */
((function(){if(typeof this.RokSprocket=="undefined"){this.RokSprocket={};
}else{Object.merge(this.RokSprocket,{Mosaic:null,MosaicBuilder:null});}var b="onorientationchange" in window;var a=new Class({Implements:[Options,Events],options:{settings:{}},initialize:function(e){this.setOptions(e);
this.mosaics=document.getElements("[data-mosaic]");this.mosaic={};this.settings={};this.curve=Browser.opera?{equation:"ease-in-out"}:{curve:"cubic-bezier(0.37,0.61,0.59,0.87)"};
try{RokMediaQueries.on("every",this.mediaQuery.bind(this));}catch(d){if(typeof console!="undefined"){console.error('Error while trying to add a RokMediaQuery "match" event',d);
}}},attach:function(d,e){d=typeOf(d)=="number"?document.getElements("[data-mosaic="+this.getID(d)+"]"):d;e=typeOf(e)=="string"?JSON.decode(e):e;var f=(d?new Elements([d]).flatten():this.mosaics);
f.each(function(g){g.store("roksprocket:mosaic:attached",true);this.setSettings(g,e,"restore");var h={loadmore:g.retrieve("roksprocket:mosaic:loadmore",function(i,j){if(i){i.preventDefault();
}this.loadMore.call(this,i,g,j);}.bind(this)),ordering:g.retrieve("roksprocket:mosaic:ordering",function(j,i){this.orderBy.call(this,j,g,i);}.bind(this)),filtering:g.retrieve("roksprocket:mosaic:filtering",function(j,i){this.filterBy.call(this,j,g,i);
}.bind(this)),document:document.retrieve("roksprocket:mosaic:document",function(j,i){this.toggleShift.call(this,j,g,i);}.bind(this))};g.addEvent("click:relay([data-mosaic-loadmore])",h.loadmore);
g.addEvent("click:relay([data-mosaic-orderby])",h.ordering);g.addEvent("click:relay([data-mosaic-filterby])",h.filtering);g.retrieve("roksprocket:mosaic:ajax",new RokSprocket.Request({model:"mosaic",model_action:"getPage",onRequest:this.onRequest.bind(this,g),onSuccess:function(i){this.onSuccess(i,g,g.retrieve("roksprocket:mosaic:ajax"));
}.bind(this)}));document.addEvents({"keydown:keys(shift)":h.document,"keyup:keys(shift)":h.document});this.initializeMosaic(g,function(){this.mediaQuery.delay(5,this,RokMediaQueries.getQuery());
}.bind(this));},this);},detach:function(d){d=typeOf(d)=="number"?document.getElements("[data-mosaic="+this.getID(d)+"]"):d;var e=(d?new Elements([d]).flatten():this.mosaics);
e.each(function(f){f.store("roksprocket:mosaic:attached",false);var g={loadmore:f.retrieve("roksprocket:mosaic:loadmore"),ordering:f.retrieve("roksprocket:mosaic:ordering"),filtering:f.retrieve("roksprocket:mosaic:filtering"),document:document.retrieve("roksprocket:mosaic:document")};
f.removeEvent("click:relay([data-mosaic-loadmore])",g.loadmore);f.removeEvent("click:relay([data-mosaic-orderby])",g.ordering);f.removeEvent("click:relay([data-mosaic-filterby])",g.filtering);
document.removeEvents({"keydown:keys(shift)":g.document,"keyup:keys(shift)":g.document});},this);},mediaQuery:function(e){var d;for(var f in this.mosaic){d=this.mosaic[f];
d.resize("fast");}},setSettings:function(d,g,f){var h=this.getID(d),e=Object.clone(this.getSettings(d)||this.options.settings);if(!f||!this.settings["id-"+h]){this.settings["id-"+h]=Object.merge(e,g||e);
}},getSettings:function(d){var e=this.getID(d);return this.settings["id-"+e];},getContainer:function(d){if(!d){d=document.getElements("[data-mosaic]");
}if(typeOf(d)=="number"){d=document.getElement("[data-mosaic="+d+"]");}if(typeOf(d)=="string"){d=document.getElement(d);}return d;},getID:function(d){if(typeOf(d)=="number"){d=document.getElement("[data-mosaic="+d+"]");
}if(typeOf(d)=="string"){d=document.getElement(d);}return !d?d:d.get("data-mosaic");},loadMore:function(e,d,g){d=this.getContainer(d);g=(typeOf(g)=="number")?g:this.getSettings(d).page||1;
if(!d.retrieve("roksprocket:mosaic:attached")){return;}var f=d.retrieve("roksprocket:mosaic:ajax"),i=d.getElement("[data-mosaic-filterby].active"),h={moduleid:d.get("data-mosaic"),behavior:!g?"reset":"append",displayed:!g?[]:this.getSettings(d).displayed||[],filter:i?i.get("data-mosaic-filterby")||"all":"all",page:++g};
if(e&&e.shift){h.all=true;}if(!f.isRunning()){f.cancel().setParams(h).send();}},filterBy:function(f,d,e){d.getElements("[data-mosaic-filterby]").removeClass("active");
e.addClass("active");d.addClass("refreshing");this.loadMore(f,d,0);},nextAll:function(e,d){e=this.getContainer(e);if(typeOf(e)=="element"){return this.next(e,d);
}e.each(function(f){this.next(f,d);},this);},toggleShift:function(h,e,f){var g=h.type||"keyup",d=document.getElements("[data-mosaic-loadmore]");if(!d.length){return true;
}if(g=="keydown"){d.addClass("load-all");}else{d.removeClass("load-all");}},onRequest:function(e){var d=e.getElements("[data-mosaic-loadmore]");if(d){d.addClass("loader");
}this.detach(e);},onSuccess:function(k,f){var g="id-"+this.getID(f),q=f.retrieve("roksprocket:mosaic:ajax"),p=f.getElement("[data-mosaic-items]"),m=k.getPath("payload.html"),n=k.getPath("payload.page"),o=k.getPath("payload.more"),e=k.getPath("payload.behavior"),l=k.getPath("payload.displayed"),j=this.getSettings(f),s=j.animations,i;
this.setSettings(f,{page:(e=="reset"?1:n),displayed:l});f.removeClass("refreshing");var h=new Element("div",{html:m}),d=h.getChildren(),r={},t={};r=this.getAnimation(f,"_set").style;
moofx(d).style(r);p.adopt(d);i=new Elements(d.getElements("img").flatten());this._loadImages(i.get("src"),function(){if(e=="reset"){this.mosaic[g].bricks.each(function(v,u){(function(){r=this.getAnimation(f,"_out");
moofx(v).style(r.style);t=Object.merge({},this.curve,{duration:"250ms",callback:function(){v.dispose();}});moofx(v).animate(r.animate,t);}).delay(u*50,this);
},this);}this.mosaic[g][e](d,function(){loadmore=f.getElements("[data-mosaic-loadmore]");if(loadmore){loadmore.removeClass("loader");}d=this.mosaic[g].bricks.filter(function(u){return d.contains(u);
});d.each(function(v,u){(function(){r=this.getAnimation(f,"_in");t=Object.merge({},this.curve,{curve:"cubic-bezier(0.37,0.61,0.59,0.87)",duration:"300ms"});
moofx(v).animate(r.animate,t);}).delay(u*100,this);},this);this.attach(f);f.getElements("[data-mosaic-loadmore]").removeClass("load-all")[!o?"addClass":"removeClass"]("hide");
}.bind(this));}.bind(this));},getAnimation:function(d,i){var f=this.getSettings(d),e=f.animations||null,g={},h={_set:{style:{opacity:0},animate:{}},_out:{style:{opacity:1},animate:{opacity:0}},_in:{style:{},animate:{opacity:1}}};
e=e?e.erase("fade"):null;if(e&&e.contains("flip")){e=e.erase("scale").erase("rotate");}switch(e?e.join(","):null){case"scale":h._set["style"]=Object.merge(h._set["style"],{transform:"scale(0.5)"});
h._out["style"]=Object.merge(h._out["style"],{"transform-origin":"50% 50%"});h._out["animate"]=Object.merge(h._out["animate"],{transform:Browser.ie9?"scale(0.001)":"scale(0)"});
h._in["animate"]=Object.merge(h._in["animate"],{transform:Browser.ie9||Browser.opera?"matrix(1, 0, 0, 1, 0, 0)":"scale(1)"});break;case"rotate":h._set["style"]=Object.merge(h._set["style"],{"transform-origin":"0 0",transform:"rotate(-10deg)"});
h._out["style"]=Object.merge(h._out["style"],{"transform-origin":"0 0"});h._out["animate"]=Object.merge(h._out["animate"],{transform:"rotate(10deg)"});
h._in["animate"]=Object.merge(h._in["animate"],{transform:"rotate(0)"});break;case"rotate,scale":case"scale,rotate":h._set["style"]=Object.merge(h._set["style"],{"transform-origin":"0 0",transform:"scale(0.5) rotate(-10deg)"});
h._out["style"]=Object.merge(h._out["style"],{"transform-origin":"50% 50%"});h._out["animate"]=Object.merge(h._out["animate"],{transform:Browser.ie9?"scale(0.001) rotate(10deg)":"scale(0) rotate(10deg)"});
h._in["animate"]=Object.merge(h._in["animate"],{transform:Browser.ie9||Browser.opera?"matrix(1, 0, 0, 1, 0, 0)":"scale(1) rotate(0)"});break;case"flip":h._set["style"]=Object.merge(h._set["style"],{"transform-origin":"50% 50%",transform:"scale(0.5) rotateY(360deg)"});
h._out["style"]=Object.merge(h._out["style"],{"transform-origin":"50% 50%"});h._out["animate"]=Object.merge(h._out["animate"],{transform:Browser.ie9?"scale(0.0001) rotateY(360deg)":"scale(0.5) rotateY(360deg)"});
h._in["animate"]=Object.merge(h._in["animate"],{transform:"scale(1) rotateY(0)"});break;default:}return h[i];},orderBy:function(f,d,e){var h="id-"+this.getID(d);
if(!this.mosaic||!this.mosaic[h]){throw new Error("RokSprocket Mosaic: Mosaic class not available");}var g=e.get("data-mosaic-orderby");this.mosaic[h].order(g);
d.getElements("[data-mosaic-orderby]").removeClass("active");if(g!="random"){e.addClass("active");}},initializeMosaic:function(e,k){var f="id-"+this.getID(e),h;
if(this.mosaic&&this.mosaic[f]){if(typeof k=="function"){k.call(this.mosaic[f].bricks);}h=e.getElements("[data-mosaic-loadmore]");if(h){h.removeClass("loader");
}return this.mosaic[f];}var g=e.getElements("img"),d=e.getElement("[data-mosaic-items]"),j=e.getElement(".active[data-mosaic-orderby]"),l={container:e,animated:true,gutter:0,order:j?j.get("data-mosaic-orderby"):(e.getElements("[data-mosaic-orderby]").length?"random":"default")},i=d.getElements("[data-mosaic-item]");
if(!i.length){return this.mosaic[f];}if(k&&typeof k=="function"){l.callback=k;}moofx(d).style({"transform-style":"preserve-3d","backface-visibility":"hidden",opacity:1});
moofx(i).style(this.getAnimation(e,"_in").animate);if(!g.length){h=e.getElements("[data-mosaic-loadmore]");if(h){h.removeClass("loader");}this.mosaic[f]=new RokSprocket.MosaicBuilder(d,l);
}else{this._loadImages(g.get("src"),function(){h=e.getElements("[data-mosaic-loadmore]");if(h){h.removeClass("loader");}this.mosaic[f]=new RokSprocket.MosaicBuilder(d,l);
}.bind(this));}return this.mosaic[f];},_loadImages:function(d,e){return d.length?new Asset.images(d,{onComplete:e.bind(this)}):e.bind(this)();}});var c=new Class({Implements:[Options,Events],options:{container:null,resizeable:false,animated:false,gutter:0,fitwidth:false,order:"default",containerStyle:{position:"relative"}},initialize:function(e,d){this.setOptions(d);
this.element=document.id(e)||document.getElement(e)||null;if(!this.element){throw new Error('Mosaic Builder Error: Element "'+e+'" not found in the DOM.');
}this.styleQueue=[];this.curve=Browser.opera?{equation:"ease-in-out"}:{curve:"cubic-bezier(0.37,0.61,0.59,0.87)"};this.originalState=this.getBricks();this.build();
this.init(d.callback||null);},build:function(){var d=this.element.style;this.originalStyle={height:d.height||""};Object.each(this.options.containerStyle,function(e,f){this.originalStyle[f]=d[f]||"";
},this);moofx(this.element).style(this.originalStyle);this.offset={x:this.element.getStyle("padding-left").toInt(),y:this.element.getStyle("padding-top").toInt()};
this.isFluid=this.options.columnWidth&&typeof this.options.columnWidth==="function";this.reloadItems(this.options.order||null);},init:function(d){this.getColumns();
this.reLayout(d);},getBricks:function(d){return(d?d:this.element.getElements("[data-mosaic-item]")).setStyle("position","absolute");},reloadItems:function(d,e){this.bricks=this.getBricks(e);
if(d=="random"||d=="default"){if(d=="random"){this.bricks=this.bricks.shuffle();}if(d=="default"){this.bricks=this.originalState.clone();}return this.bricks;
}this.bricks=d?this.orderBy(d):this.bricks;return this.bricks;},orderBy:function(d){var e=false;return this.bricks.sort(function(h,g){var f=h.getElement("[data-mosaic-order-"+d+"]"),i=g.getElement("[data-mosaic-order-"+d+"]");
if(!f||!i){if(console&&console.error&&!e){console.error('RokSprocket MosaicBuilder: Trying to sort by "'+d+'" but no sorting rule has been found.');}e=true;
return 0;}f=f.get("data-mosaic-order-"+d);i=i.get("data-mosaic-order-"+d);return f==i?0:(f<i?-1:1);}.bind(this));},reload:function(d){this.reloadItems();
this.init(d);},layout:function(e,m,k){for(var j=0,l=e.length;j<l;j++){this.placeBrick(e[j]);}var d={},n={};d.height=Math.max.apply(Math,this.colYs);if(this.options.fitwidth){var g=0;
j=this.cols;while(--j){if(this.colYs[j]!==0){break;}g++;}d.width=(this.cols-g)*this.columnWidth-this.options.gutter;}this.styleQueue.push({element:this.element,style:d});
var f=!this.isLaidOut?"style":(this.options.animated&&!k?"animate":"style"),h;this.styleQueue.each(function(p,o){n=Object.merge({},this.curve,{duration:"400ms"});
if(o==this.styleQueue.length-1){if(m){n.callback=m.bind(m,e);}}moofx(p.element)[f](p.style,n);},this);this.styleQueue.empty();if(m&&f=="style"){m.call(e);
}this.isLaidOut=true;},getColumns:function(){var d=this.options.fitwidth?this.element.getParent():this.element,e=d.offsetWidth;this.columnWidth=this.isFluid?this.options.columnWidth(e):this.options.columnWidth||(this.bricks.length&&this.bricks[0].offsetWidth)||e;
this.columnWidth+=this.options.gutter;this.cols=Math.round((e+this.options.gutter)/this.columnWidth);this.cols=Math.max(this.cols,1);},placeBrick:function(j){j=document.id(j);
var l,p,f,n;l=Math.round(j.offsetWidth/(this.columnWidth+this.options.gutter));l=Math.min(l,this.cols);if(l==1){f=this.colYs;}else{p=this.cols+1-l;f=[];
(p).times(function(q){n=this.colYs.slice(q,q+l);f[q]=Math.max.apply(Math,n);},this);}var d=Math.min.apply(Math,f),o=0;for(var g=0,k=f.length;g<k;g++){if(f[g]===d){o=g;
break;}}var h={top:d+this.offset.y};h.left=o*(100/this.cols)+"%";this.styleQueue.push({element:j,style:h});var m=d+j.offsetHeight+((this.options.gutter||0)),e=this.cols+1-f.length;
(e).times(function(q){this.colYs[o+q]=m;},this);},resize:function(d){var e=this.cols;this.getColumns();if((this.isFluid||d)&&this.cols!==e||d){this.reLayout(null,d);
}},reLayout:function(f,d){var e=this.cols;this.colYs=[];while(e--){this.colYs.push(0);}this.layout(this.bricks,f,d);},reset:function(d,e){d=d.filter(function(f){return f.get("data-mosaic-item")!==null||f.getElement("data-mosaic-item");
});this.bricks=this.originalState=new Elements();d.setStyles({top:0,left:0,position:"absolute"});this.appendedBricks.delay(1,this,[d,d,e]);},append:function(d,e){d=d.filter(function(f){return f.get("data-mosaic-item")!==null||f.getElement("data-mosaic-item");
});if(!d){return;}d.setStyles({top:this.element.getSize().y,left:0,position:"absolute"});this.appendedBricks.delay(1,this,[d,null,e]);},appendedBricks:function(f,e,h){var d=this.options.container.getElement("[data-mosaic-orderby].active")||this.options.container.getElement("[data-mosaic-orderby=random]"),g=d?d.get("data-mosaic-orderby"):(this.options.container.getElements("[data-mosaic-orderby]").length?"random":"default");
this.originalState.append(f);this.order(g,e,h);},order:function(e,d,f){this.reloadItems(e,d||null);this.init(f);}});this.RokSprocket.Mosaic=a;this.RokSprocket.MosaicBuilder=c;
if(b){window.addEventListener("orientationchange",function(){if(typeof RokSprocket=="undefined"||typeof RokSprocket.instances=="undefined"||typeof RokSprocket.instances.mosaic=="undefined"){return;
}var d;for(var e in RokSprocket.instances.mosaic.mosaic){d=RokSprocket.instances.mosaic.mosaic[e];d.resize("fast");}});}Element.implement({mosaic:function(e){var d=this.retrieve("roksprocket:mosaic:builder");
if(!d){d=this.store("roksprocket:mosaic:builder",new RokSprocket.MosaicBuilder(this,e));}return d;}});if(MooTools.version<"1.4.4"&&(Browser.name=="ie"&&Browser.version<9)){((function(){var d=["rel","data-next","data-mosaic","data-mosaic-items","data-mosaic-item","data-mosaic-content","data-mosaic-page","data-mosaic-next","data-mosaic-order","data-mosaic-orderby","data-mosaic-order-title","data-mosaic-order-date","data-mosaic-filterby","data-mosaic-loadmore"];
d.each(function(e){Element.Properties[e]={get:function(){return this.getAttribute(e);}};});})());}})());