/*
 * @author    RocketTheme http://www.rockettheme.com
 * @copyright Copyright (C) 2007 - 2012 RocketTheme, LLC
 * @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
 */
((function(){this.RokGallery.Edit=new Class({Implements:[Events,Options],options:{imageSize:{width:0,height:0},scroll:{duration:400,transition:"expo:in:out",wheelStops:false}},initialize:function(a){this.setOptions(a);
this.fileSettings=RokGallery.blocks.editFileSettings;this.id=null;this.isOpen=false;this.scale=100;this.container=document.id("file-edit");this.scroll=new Fx.Scroll(window,this.options.scroll);
this.wrapper=this.container.getElement(".image-wrapper");this.image=this.wrapper.getElement("img");this.loader=document.getElement("#file-edit .panel-actions .loader");
this.scaleInfo=this.container.getElement(".scale span");this.inputs={marquee:this.container.getElements(".edit-image .resize .marquee input"),image:this.container.getElements(".edit-image .resize .size input")};
this.infoInputs=this.container.getElements(".info input, .info textarea").filter(function(c){return !c.hasClass("add-input")&&c.id!="slice-linkdata";});
this.defaultThumb=this.container.getElement("#reset-thumb-sizes");this.attachSliceLink();this.attachInputs();this.actions=this.container.getElements(".panel-actions .button");
var b={save:"saveRequest",publish:"beforePublish","delete":"deleteRequest",close:"close"};this.actions.each(function(d){var c=d.className.split(" ");if(c.length){c=c[0].replace(/file\-edit\-/,"");
if(b[c]&&this[b[c]]){d.addEvent("click",this[b[c]].bind(this));}}},this);this.navigation={arrows:this.container.getElements(".previous-slice, .next-slice"),current:this.container.getElement(".slice-current-no"),total:this.container.getElement(".slice-total-no")};
this.attachNavigation();this.imageSize=this.options.imageSize;this.gallery=null;this.bounds={resize:this.setSize.bind(this),load:{onRequest:function(){this.loader.setStyle("display","block");
}.bind(this),onSuccess:this.save.bind(this)},remove:{onRequest:function(){this.loader.setStyle("display","block");}.bind(this),onSuccess:this.remove.bind(this)}};
this.ajax=new Request({url:RokGallery.url,method:"post"}).addEvents(this.bounds.load);this.deleteAjax=new Request({url:RokGallery.url,method:"post"}).addEvents(this.bounds.remove);
this.publishAjax=new Request({url:RokGallery.url,method:"post",data:{model:"Slice",action:"update"},onRequest:this.publishRequest.bind(this,this.container.getElement(".file-edit-publish, .file-edit-unpublish")),onSuccess:this.publishSuccess.bind(this,this.container.getElement(".file-edit-publish, .file-edit-unpublish"))});
this.build();return this;},build:function(){var a=document.body.getSize(),b={width:a.x,height:"100%",position:"absolute",right:-a.x,top:0,display:"none"};
this.container.setStyles(b);this.container.inject(document.body);this.scrollbar=[new Scrollbar(this.wrapper,{fixed:true,resizeWrapper:false,wrap:true}),new Scrollbar(this.wrapper,{direction:"horizontal",resizeWrapper:false,wrap:false,fixed:true})];
},setSliderRanges:function(b,d){var c=Math.min(b,d),a=Math.max(b,d);this.slider.setRange([c*12/100,c*600/100]);},attachInputs:function(){var d=this,c=document.getElement("#file-edit .file-edit-apply"),b=document.getElement("#file-edit .file-edit-revert");
this.defaultThumb.removeEvents("click").addEvent("click",this.resetThumbDefaults.bind(this));c.removeEvents("click");b.removeEvents("click");b.addEvent("click",this.revert.bind(this));
c.addEvent("click",function(){var j={image:[],marquee:[]};for(var l in this.inputs){var i=this.inputs[l];i.each(function(n){j[l].push(n.get("value").toInt());
});}var m={width:j.image[0],height:j.image[1]};this.resize(m);var k=j.marquee;var h=this.image.retrieve("realScale");m={left:k[0]*h/100,top:k[1]*h/100,width:k[2]*h/100,height:k[3]*h/100};
this.crop(m);}.bind(this));for(var f in this.inputs){var a=this.inputs[f];a.removeEvents("blur");if(f=="marquee"){var e=a;e.addEvent("blur",function(){var h=e.get("value"),i=this.inputs.image.get("value");
h.each(function(k,j){h[j]=k.toInt();});i[0]=i[0].toInt();i[1]=i[1].toInt();if(h[0]<0){h[0]=0;}if(h[1]<0){h[1]=0;}if((h[0]+h[2])>i[0]){h[0]=i[0]-h[2];}if((h[1]+h[3])>i[1]){h[1]=i[1]-h[3];
}this.toolbar.marquee.box.setCoords(h);}.bind(this));}else{if(f=="image"){var g=a;g.addEvent("blur",function(){var j=g.get("value"),m=d.image.retrieve("size"),k=a.indexOf(this),i=k==0?1:0,n=["width","height"][k],h=["width","height"][i];
var l=Math.round(j[k]*m[h]/m[n]);a[i].set("value",l);});}}}},attach:function(){window.addEvent("resize",this.bounds.resize);},detach:function(){window.removeEvent("resize",this.bounds.resize);
},setSize:function(){var b=document.body.getSize().x,c=window.getScrollSize().x,a=0;this.container.setStyles({width:b,right:-b});if(Browser.ie||Browser.opera){this.wrapper.getParent().setStyle("width","auto");
}document.getElements("#file-edit .edit-header, #file-edit .edit-block").each(function(d){if(d.getStyle("display")!="none"){a+=d.getSize().y;}});this.wrapper.setStyle("max-height",window.getSize().y-a-150);
window.scrollTo(c,0);this.updateScrollbars();},setTags:function(a){a=a.map(function(b){return b.tag;});this.container.getElements(".tags-list .tag").dispose();
delete this.tags;this.tags=new Tags.Slice("#file-edit .column.tags");this.tags.insertMany(a,true);this.tags.list.inject(this.tags.container);if(!a.length){this.tags.fireEvent("emptyList");
}else{this.tags.fireEvent("nonEmptyList");}this.tags.scrollbar.update();},addFileTags:function(b){var a=this.container.getElement(".tags-list > .oops");
if(b.length){a.setStyle("display","none");}b.reverse().forEach(function(c){var d=new Element('div[class="tag dark"]');d.set("html",'<div class="tag-value"><span class="tag-name">'+c.tag+"</span></div>");
d.inject(a,"after");});},updateScrollbars:function(){this.scrollbar.each(function(a){a.update();});},attachNavigation:function(){var a=this.navigation.arrows,c=this.navigation.current,b=this.navigation.total;
a.each(function(d){d.addEvent("click",function(g){g.stop();if(this.wrapper.hasClass("loader")){return;}var f=this.fileSettings.currentSlice;if(d.hasClass("previous-slice")){this.fileSettings.previousSlice();
}else{this.fileSettings.nextSlice();}if(this.fileSettings.currentSlice==f){return;}this.toolbar.detachAll();this.wrapper.getElement(".image-overlay").empty();
this.toolbar=function(){};this.fileSettings.editSlice();RokGallery.editPanel.updateScrollbars();}.bind(this));},this);},load:function(e,g){var d=this,c=e.imageurl,b=this.fileSettings.current.retrieve("thumb-defaults");
document.removeEvents(RokGallery.blocks.editFileSettings.bounds.document);this.container.removeClass("has-ribbon");this.container.getElement(".ribbon").setStyle("display","none");
this.container.getElement(".edit-block").removeClass("with-thumb");this.container.getElement(".button.file-edit-delete").setStyle("display","none");this.container.getElements(".info input[type=checkbox]").set("checked","");
for(var f in this.inputs){this.inputs[f].removeClass("disabled").removeProperty("disabled");}if(!g){g={id:null,gallery_id:null,xsize:e.xsize,ysize:e.ysize,title:"",slug:"",link:"",caption:"",admin_thumb:false,published:false,thumb_xsize:b.thumb_xsize.toString(),thumb_ysize:b.thumb_ysize.toString(),thumb_keep_aspect:b.thumb_keep_aspect,thumb_background:b.thumb_background.toString(),manipulations:[{action:"resize",options:{width:e.xsize,height:e.ysize}},{action:"crop",options:{top:0,left:0,width:e.xsize,height:e.ysize}}],Tags:[],FileTags:e.Tags,Gallery:{}};
}if(!g.gallery_id){this.container.getElement(".edit-block").addClass("with-thumb");}if(this.image){this.wrapper.getElement(".image-overlay").empty();}this.wrapper.addClass("loader");
this.container.getElement(".button.file-edit-delete").setStyle("display","none");this.id=g.id;this.sliceData=g;var a=this.container.getElement(".image-status .left");
a.set("html","<span>original file:</span> "+e.title+" <span> &#x25CF; </span> "+e.xsize+" x "+e.ysize+" <span>(1:1)</span> <span> &#x25CF; </span> "+Uploader.formatUnit(e.filesize,"b"));
if(!this.isOpen){this.open();}(function(){new Asset.image(c,{onload:function(){d.wrapper.removeClass("loader");d.imageSize=d.options.imageSize;d.image=this;
var j=d.inputs;if(d.sliceData.admin_thumb){d.container.addClass("has-ribbon");d.container.getElement(".ribbon").setStyle("display","block");$$([j.image[0],j.image[1],j.marquee[2],j.marquee[3]]).addClass("disabled").set("disabled","disabled");
}d.image.store("size",{width:d.imageSize.width,height:d.imageSize.height});d.image.store("resize",{width:d.sliceData.xsize,height:d.sliceData.ysize});d.image.store("realScale",100);
d.image.store("fakeScale",100);d.image.store("revert",d.sliceData);d.image.set("width",d.imageSize.width).set("height",d.imageSize.height);this.inject(d.wrapper.getFirst());
RokGallery.editPanel.updateScrollbars();d.toolbar=new RokGallery.Edit.Toolbar();d.resize({width:d.sliceData.xsize,height:d.sliceData.ysize});d.setTags(d.sliceData.Tags||[]);
d.addFileTags(d.sliceData.FileTags||[]);d.publish(d.sliceData.published);var i=d.galleries.container.getElement("li[data-key="+d.sliceData.gallery_id+"]");
if(d.sliceData.gallery_id&&i){i.fireEvent("click");}else{d.galleries.list[0].fireEvent("click");}["title","slug","link","caption","thumb_xsize","thumb_ysize","thumb_keep_aspect","thumb_background"].each(function(k,l){var m=(d.infoInputs[l].get("type")!="checkbox")?d.sliceData[k]:(d.sliceData[k]?"checked":"");
d.infoInputs[l].set(d.infoInputs[l].get("type")=="checkbox"?"checked":"value",m);},this);d.parseSliceLink(d.sliceData.link);d.sliceData.manipulations.each(function(k){d[k.action](k.options);
},this);if(!d.id){d.toolbar.buttons[1].fireEvent("click");}if(d.id&&!d.sliceData.admin_thumb){d.container.getElement(".button.file-edit-delete").setStyle("display","block");
}if(d.sliceData.admin_thumb){if(d.toolbar.marquee){d.toolbar.marquee.box.setOptions({noHandlers:true}).hideHandlers();}}if(d.sliceData.Gallery&&d.sliceData.Gallery.force_image_size){if(d.toolbar.marquee){d.toolbar.marquee.box.setOptions({noHandlers:true}).hideHandlers();
}$$([j.image[0],j.image[1],j.marquee[2],j.marquee[3]]).addClass("disabled").set("disabled","disabled");}if((d.sliceData.Gallery&&d.sliceData.Gallery.force_image_size)||d.sliceData.admin_thumb){document.getElement("#file-edit .file-edit-apply").setStyle("display","none");
}else{document.getElement("#file-edit .file-edit-apply").setStyle("display","block");}var h=d.container.getElements(".edit-block, .file-edit-publish, .file-edit-unpublish, .file-gallery.galleries-list");
if(d.sliceData.admin_thumb){h.setStyle("display","none");d.setSize();}else{h.setStyle("display","block");d.setSize();}}});}).delay(500);},attachSliceLink:function(){this.sliceInputLink=document.id(RokGallery.SqueezeBox.linkElement)||document.getElement(RokGallery.SqueezeBox.linkElement);
this.sliceInputData=document.id(RokGallery.SqueezeBox.dataElement)||document.getElement(RokGallery.SqueezeBox.dataElement);this.sliceClearData=document.getElement(".link-clear-input");
this.sliceInputLink.addEvent("keyup",function(){var a={type:"manual",link:this.sliceInputLink.get("value")};this.sliceInputData.set("value",JSON.encode(a));
}.bind(this));this.sliceClearData.addEvent("click:stop",this.enableSliceLink.bind(this));},disableSliceLink:function(){this.sliceInputLink.set("disabled","disabled").getParent().addClass("disabled");
this.sliceClearData.setStyle("display","block");},enableSliceLink:function(a){this.sliceInputLink.getParent().removeClass("disabled");this.sliceClearData.setStyle("display","none");
this.sliceInputLink.set("value","").removeProperty("disabled").fireEvent("keyup");if(a!==true){this.sliceInputLink.focus();}},parseSliceLink:function(b){if(!b){b="";
}var a=b.length?(JSON.validate(b)?JSON.decode(b):{type:"manual",link:b}):{type:"manual",link:""};if(a.title){this.disableSliceLink();this.sliceInputLink.set("value",a.title);
this.sliceInputData.set("value",JSON.encode(a));}else{this.enableSliceLink(true);this.sliceInputLink.set("value",a.link);this.sliceInputData.set("value",JSON.encode(a));
}},resetThumbDefaults:function(d){d.stop();var b=["thumb_xsize","thumb_ysize","thumb_keep_aspect","thumb_background"],a=this.infoInputs.slice(4,8),c=this.fileSettings.current.retrieve("thumb-defaults");
b.each(function(e,f){var g=(a[f].get("type")!="checkbox")?c[e]:(c[e]?"checked":"");a[f].set(a[f].get("type")=="checkbox"?"checked":"value",g);},this);},popup:function(a){var b={type:"warning",title:"Error",message:"",buttons:{ok:{show:false},cancel:{show:true,label:"close"}}};
window.Popup.setPopup(Object.merge(b,a)).open();},open:function(){this.attach();RokGallery.rubberband.detach();document.body.setStyle("overflow","hidden");
this.container.setStyle("display","block");this.setSize();this.setGalleries();window.scrollTo(0,window.getScroll().y);this.infoInputs.set("value","");this.scroll.toRight().chain(function(){this.isOpen=true;
window.Popup.overlay.setStyle("width","200%");}.bind(this));},close:function(){this.scroll.toLeft().chain(function(){this.detach();this.id=null;this.toolbar.detachAll();
this.wrapper.getElement(".image-overlay").empty();this.toolbar=function(){};window.Popup.overlay.setStyle("width","");RokGallery.rubberband.attach();this.container.setStyle("display","none");
document.body.setStyle("overflow","visible");RokGallery.blocks.editFileSettings.scroller.toElementEdge("file-settings","y");document.body.addEvents(RokGallery.blocks.editFileSettings.bounds.document);
this.isOpen=false;window.Popup.overlay.setStyle("width","");}.bind(this));},setGalleries:function(){this.galleries={container:this.container.getElement(".file-gallery"),text:this.container.getElements(".file-gallery .title"),list:this.container.getElements(".file-gallery li")};
this.galleries.list.removeEvents("click").each(function(b,a){b.addEvent("click",function(){this.galleries.list.removeClass("selected");if(a){b.addClass("selected");
}this.galleries.text.set("text",b.get("text"));this.gallery=b.get("data-key")||null;if(!this.gallery){this.container.getElement(".edit-block").addClass("with-thumb");
}else{this.container.getElement(".edit-block").removeClass("with-thumb");}this.tags.scrollbar.update();this.galleries.container.addClass("hidden");document.addEvent("mousemove:once",function(){this.galleries.container.removeClass("hidden");
}.bind(this));}.bind(this));},this);},beforePublish:function(){if(!this.id){this.publish();}else{if(!this.publishAjax.isRunning()){this.publishAjax.send({data:{model:"Slice",action:"update",params:JSON.encode({id:this.id,slice:{published:!this.sliceData.published}})}});
}}},publish:function(c){var b=this.container.getElement(".file-edit-publish, .file-edit-unpublish"),a=typeOf(c)=="boolean"||c===0?c:b.hasClass("file-edit-publish");
if(a){b.removeClass("file-edit-publish").addClass("file-edit-unpublish");b.getLast("span > span").set("text","unpublish");this.sliceData.published=true;
}else{b.removeClass("file-edit-unpublish").addClass("file-edit-publish");b.getLast("span > span").set("text","publish");this.sliceData.published=false;
}},publishRequest:function(a){},publishSuccess:function(b,a){if(!JSON.validate(a)){return this.popup({title:"Publish Action - Invalid Response",message:'<p class="error-intro">The response from the server had an invalid JSON string while trying to publishing / unpublishing the Slice. Following is the reply.</p>'+a});
}a=JSON.decode(a);if(a.status!="success"){return this.popup({title:"Publish Action - Error",message:a.message});}this.publish(a.payload.published);return this;
},saveRequest:function(){if(this.ajax.isRunning()){return;}var d=this.sliceData,a={manipulations:[]},c="",f={};var e={resize:{width:this.inputs.image[0].get("value").toInt(),height:this.inputs.image[1].get("value").toInt()},crop:{left:this.inputs.marquee[0].get("value").toInt(),top:this.inputs.marquee[1].get("value").toInt(),width:this.inputs.marquee[2].get("value").toInt(),height:this.inputs.marquee[3].get("value").toInt()}};
["title","slug","link","caption","thumb_xsize","thumb_ysize","thumb_keep_aspect","thumb_background"].each(function(g,h){a[g]=this.infoInputs[h].get(this.infoInputs[h].get("type")=="checkbox"?"checked":"value");
},this);a.published=d.published;a.Tags=this.tags.getValues();a.gallery_id=this.gallery;for(var b in e){a.manipulations.push({action:b,options:e[b]});}if(this.id){Object.merge(this.sliceData.manipulations,a.manipulations);
f={id:this.id,slice:a};c="update";}else{f={fileId:RokGallery.blocks.editFileSettings.id,slice:a};c="create";}a={model:"Slice",action:c,params:JSON.encode(f)};
this.ajax.send({data:a});},deleteRequest:function(){if(this.deleteAjax.isRunning()||!this.id){return;}var a=this,b={model:"Slice",action:"delete",params:JSON.encode({id:this.id})};
window.Popup.setPopup({type:"warning",title:"Slice Deletion - Are you sure?",message:"<p>You are about to delete the current Slice <strong>"+this.sliceData.title+"</strong></p> 					  <p>This operation is irreversible, are you sure you want to continue?</p>",buttons:{ok:{show:true,label:"yes"},cancel:{show:true,label:"no"}},"continue":function(){a.deleteAjax.send({data:b});
this.close();}}).open();},save:function(a){this.loader.setStyle("display","none");if(!JSON.validate(a)){return this.popup({title:"Slice Save - Invalid Response",message:'<p class="error-intro">The response from the server had an invalid JSON string while trying to save the Slice. Following is the reply.</p>'+a});
}a=JSON.decode(a);if(a.status!="success"){return this.popup({title:"Slice Save - Error",message:a.message});}if(!this.id&&a.payload.slice.id){this.id=a.payload.slice.id;
this.sliceData=a.payload.slice;this.setTags(this.sliceData.Tags||[]);this.fileSettings.slices.push(a.payload.slice);this.fileSettings.currentSlice=this.fileSettings.slices.length-1;
}this.fileSettings.slices[this.fileSettings.currentSlice]=a.payload.slice;this.fileSettings.loadSlice(this.fileSettings.currentSlice,true);this.close();
return this;},remove:function(a){this.loader.setStyle("display","none");if(!JSON.validate(a)){return this.popup({title:"Slice Deletion - Invalid Response",message:'<p class="error-intro">The response from the server had an invalid JSON string while trying to delete the Slice. Following is the reply.</p>'+a});
}a=JSON.decode(a);if(a.status!="success"){return this.popup({title:"Slice Deletion - Error",message:a.message});}this.id=null;this.sliceData=null;this.fileSettings.deleteSlice();
this.close();return this;},revert:function(){var a=this.image.retrieve("revert"),c=a.manipulations,b=[];this.image.store("size",{width:this.imageSize.width,height:this.imageSize.height});
this.image.store("resize",{width:a.xsize,height:a.ysize});this.image.store("realScale",100);this.image.store("fakeScale",100);this.image.store("revert",a);
c.each(function(d){b.push(d.action);this[d.action](d.options);},this);if(!b.contains("crop")){this.crop({left:0,top:0,width:a.xsize,height:a.ysize});}return this;
},resize:function(a){var b=a.width<a.height?"width":"height";var c=Math.round((a[b]/this.image.retrieve("size")[b])*100);this.image.set("width",a.width).set("height",a.height);
this.toolbar.image.store("realScale",c);this.toolbar.image.store("fakeScale",100);this.toolbar.scaling.include(c);this.toolbar.scaling.sort(function(e,d){return e-d;
});this.image.store("resize",{width:a.width,height:a.height});RokGallery.editPanel.inputs.image[0].set("value",a.width);RokGallery.editPanel.inputs.image[1].set("value",a.height);
this.toolbar.marquee.updateBox({scale:c,zoom:100,width:a.width,height:a.height,zooming:true});RokGallery.editPanel.updateScrollbars();},crop:function(a){var b=this.toolbar.buttons.filter(function(c){return c.hasClass("marquee");
});b=Array.from(b)[0];if(!b.hasClass("pressed")){b.fireEvent("click");}this.toolbar.marquee.box.setCoords([a.left,a.top,a.width,a.height]);RokGallery.editPanel.updateScrollbars();
}});this.RokGallery.Edit.Toolbar=new Class({Implements:[Options],options:{handtool:{onChange:function(a,b){this.element.scrollTo(a,b);RokGallery.editPanel.updateScrollbars();
}}},initialize:function(b){var e=["handtool","marquee"],c=["zoomin","zoom100","zoomout"],f=document.getElement("#file-edit-wrapper .image-wrapper"),d=f.getElement("img"),a=document.getElement("#file-edit-wrapper .toolbar");
this.buttons=[];this.image=d;this.scaling=[6,12,16,25,33,50,66,100,150,200,300,400,600];this.size={width:d.get("width"),height:d.get("height")};e.each(function(h){var i=a.getElement("."+h),g=RokGallery.Edit.Toolbar[h.capitalize()];
if(typeof g=="undefined"){return;}if(this[h]){delete this[h];}this[h]=new g(f,this.options[h]||{});i.store("tool",h);i.addEvent("click",function(){this.buttons.each(function(j){if(j!=i){j.removeClass("pressed");
}});e.each(function(j){if(typeof this[j]!="undefined"){this[j].detach();}},this);if(i.hasClass("pressed")){i.removeClass("pressed");this[i.retrieve("tool")].detach();
}else{i.addClass("pressed");this[i.retrieve("tool")].attach();}}.bind(this));this.buttons.push(i);},this);c.each(function(h){var g=a.getElement("."+h);
g.addEvent("click",function(){this.zoom(h);}.bind(this));},this);},zoom:function(f){var e,a=this.image.retrieve("realScale"),b=this.image.retrieve("fakeScale"),c=this.scaling.indexOf(a),d=this.image.retrieve("size");
switch(f){case"zoomin":e=(this.scaling[c+1])?this.scaling[c+1]:this.scaling[c];break;case"zoom100":c=this.scaling.indexOf(100);e=this.scaling[c];break;
case"zoomout":e=(this.scaling[c-1]>=0)?this.scaling[c-1]:this.scaling[c];break;}this.image.store("realScale",e);this.image.set("width",d.width*e/100).set("height",d.height*e/100);
if(this.marquee){this.marquee.updateBox({zoom:e,scale:a,width:d.width,height:d.height,zooming:true});}RokGallery.editPanel.updateScrollbars();},enable:function(a){a.attach();
},disable:function(a){a.detach();},detachAll:function(){this.buttons.each(function(b){var a=b.retrieve("tool");this.disable(this[a]);b.removeClass("pressed").removeEvents("click");
},this);}});this.RokGallery.Edit.Toolbar.Handtool=new Class({Implements:[Options,Events],options:{velocity:1,onStart:function(){document.body.addClass("dragging");
this.element.addClass("dragging");},onChange:function(a,b){this.element.scrollTo(a,b);},onEnd:function(){document.body.removeClass("dragging");this.element.removeClass("dragging");
}},initialize:function(b,a){this.setOptions(a);this.element=document.id(b)||document.getElement(b)||false;if(!this.element){return this;}this.bounds={element:{mousedown:this.start.bind(this),mouseup:this.end.bind(this)},document:{mousemove:this.drag.bind(this),mouseup:this.end.bind(this)}};
return this;},attach:function(){this.element.addEvents(this.bounds.element);this.element.addClass("handtool");return this;},detach:function(){this.element.removeEvents(this.bounds.element);
document.body.removeEvents(this.bounds.document);this.element.removeClass("handtool");return this;},start:function(a){a.stop();document.addEvents(this.bounds.document);
if(!this.coordinates){this.coordinates={mouse:{start:0,now:0},position:{start:0,now:0}};}this.coordinates.mouse.start=a.page;this.coordinates.position.start=this.element.getScroll();
this.fireEvent("start");},drag:function(a){a.stop();var b=this.coordinates;b.mouse.now=a.page;b.position.now={x:(b.position.start.x-(b.mouse.now.x-b.mouse.start.x)),y:(b.position.start.y-(b.mouse.now.y-b.mouse.start.y))};
this.scroll();},end:function(a){a.stop();document.removeEvents(this.bounds.document);this.fireEvent("end");},scroll:function(){var a=this.coordinates.position.now;
this.fireEvent("change",[a.x,a.y]);}});this.RokGallery.Edit.Toolbar.Marquee=new Class({Implements:[Options,Events],options:{},initialize:function(c,b){var a=this;
this.setOptions(b);this.element=document.id(c)||document.getElement(c)||false;if(!this.element){return this;}this.image=this.element.getElement("img");
var d=this.box=new Marquee.Crop(this.image,{ratio:false,preset:[0,0,0,0],min:[1,1],handleSize:4,opacity:0.1,color:"#fff",border:RokGallerySettings.images+"crop.gif",onResize:function(k){var i={width:a.image.retrieve("resize").width,height:a.image.retrieve("resize").height},l=a.image.retrieve("fakeScale"),g=l/100,f=Math.round(k.w/g),j=Math.round(k.h/g),e=Math.round(k.x/g),m=Math.round(k.y/g);
e=(e<0)?0:e;m=(m<0)?0:m;RokGallery.editPanel.inputs.marquee[0].set("value",e);RokGallery.editPanel.inputs.marquee[1].set("value",m);RokGallery.editPanel.inputs.marquee[2].set("value",f);
RokGallery.editPanel.inputs.marquee[3].set("value",j);}});this.scroller=new Scroller(this.element,{onChange:function(e,f){d.getContainCoords();d.getRelativeOffset();
this.element.scrollTo(e,f);RokGallery.editPanel.updateScrollbars();}});this.box.scroller=this.scroller;this.detach();return this;},attach:function(){if(this.box.detached){this.box.attach();
this.box.img.setStyle("display","none");this.box.container.setStyle("display","block");}},detach:function(){if(!this.box.detached){this.box.detach();this.box.img.setStyle("display","");
this.box.container.setStyle("display","none");}},updateBox:function(m){var a=m.zooming||false;m.oSize={width:this.image.retrieve("size").width,height:this.image.retrieve("size").height};
this.box.refreshClip(m.width*m.zoom/100,m.height*m.zoom/100,a);var f=Math.round(this.box.coords.box.x[0]/(m.scale/100)),d=Math.round(this.box.coords.box.y[0]/(m.scale/100)),g=Math.round(this.box.coords.w/(m.scale/100)),c=Math.round(this.box.coords.h/(m.scale/100));
var l=g*m.zoom/100,e=c*m.zoom/100,j=f*m.zoom/100,i=d*m.zoom/100;this.box.coords.box.x[0]=j;this.box.coords.box.y[0]=i;this.box.coords.box.x[1]=j+l;this.box.coords.box.y[1]=i+e;
var b=this.image.retrieve("resize").width,n=m.width*m.zoom/100,k=(n/b)*100;this.image.store("fakeScale",k);RokGallery.editPanel.scaleInfo.set("text",Math.round(k)+"%");
this.box.refresh(a);}});})());