(function(){var c=YAHOO.util.Dom,a=YAHOO.util.Event,d=YAHOO.lang;var b=function(f,e){var g={element:f,attributes:e||{}};b.superclass.constructor.call(this,g.element,g.attributes)};b._instances={};b.getCropperById=function(e){if(b._instances[e]){return b._instances[e]}return false};YAHOO.extend(b,YAHOO.util.Element,{CSS_MAIN:"yui-crop",CSS_MASK:"yui-crop-mask",CSS_RESIZE_MASK:"yui-crop-resize-mask",_image:null,_active:null,_resize:null,_resizeEl:null,_resizeMaskEl:null,_wrap:null,_mask:null,_createWrap:function(){this._wrap=document.createElement("div");this._wrap.id=this.get("element").id+"_wrap";this._wrap.className=this.CSS_MAIN;var f=this.get("element");this._wrap.style.width=f.width?f.width+"px":c.getStyle(f,"width");this._wrap.style.height=f.height?f.height+"px":c.getStyle(f,"height");var e=this.get("element").parentNode;e.replaceChild(this._wrap,this.get("element"));this._wrap.appendChild(this.get("element"));a.on(this._wrap,"mouseover",this._handleMouseOver,this,true);a.on(this._wrap,"mouseout",this._handleMouseOut,this,true);a.on(this._wrap,"click",function(g){a.stopEvent(g)},this,true)},_createMask:function(){this._mask=document.createElement("div");this._mask.className=this.CSS_MASK;this._wrap.appendChild(this._mask)},_createResize:function(){var e;this._resizeEl=document.createElement("div");this._resizeEl.className=YAHOO.util.Resize.prototype.CSS_RESIZE;this._resizeEl.style.position="absolute";this._resizeEl.innerHTML='<div class="'+this.CSS_RESIZE_MASK+'"></div>';this._resizeMaskEl=this._resizeEl.firstChild;this._wrap.appendChild(this._resizeEl);this._resizeEl.style.top=this.get("initialXY")[1]+"px";this._resizeEl.style.left=this.get("initialXY")[0]+"px";this._resizeMaskEl.style.height=Math.floor(this.get("initHeight"))+"px";this._resizeMaskEl.style.width=Math.floor(this.get("initWidth"))+"px";e={knobHandles:true,handles:"all",draggable:true,status:this.get("status"),minWidth:this.get("minWidth"),minHeight:this.get("minHeight"),ratio:this.get("ratio"),autoRatio:this.get("autoRatio"),height:this.get("initHeight"),width:this.get("initWidth")};if(this.get("maxWidth")){e.maxWidth=this.get("maxWidth")}if(this.get("maxHeight")){e.maxHeight=this.get("maxHeight")}this._resize=new YAHOO.util.Resize(this._resizeEl,e);this._setBackgroundImage(this.get("element").getAttribute("src",2));this._setBackgroundPosition(-(this.get("initialXY")[0]),-(this.get("initialXY")[1]));this._resize.on("startResize",this._handleStartResizeEvent,this,true);this._resize.on("endResize",this._handleEndResizeEvent,this,true);this._resize.on("dragEvent",this._handleDragEvent,this,true);this._resize.on("beforeResize",this._handleBeforeResizeEvent,this,true);this._resize.on("resize",this._handleResizeEvent,this,true);this._resize.dd.on("b4StartDragEvent",this._handleB4DragEvent,this,true)},_handleMouseOver:function(f){var e="keydown";if(YAHOO.env.ua.gecko||YAHOO.env.ua.opera){e="keypress"}if(!this._active){this._active=true;if(this.get("useKeys")){a.on(document,e,this._handleKeyPress,this,true)}}},_handleMouseOut:function(f){var e="keydown";if(YAHOO.env.ua.gecko||YAHOO.env.ua.opera){e="keypress"}this._active=false;if(this.get("useKeys")){a.removeListener(document,e,this._handleKeyPress)}},_moveEl:function(g,j){var h=0,e=0,i=this._setConstraints(),f=true;switch(g){case"down":h=-(j);if((i.bottom-j)<0){f=false;this._resizeEl.style.top=(i.top+i.bottom)+"px"}break;case"up":h=(j);if((i.top-j)<0){f=false;this._resizeEl.style.top="0px"}break;case"right":e=-(j);if((i.right-j)<0){f=false;this._resizeEl.style.left=(i.left+i.right)+"px"}break;case"left":e=j;if((i.left-j)<0){f=false;this._resizeEl.style.left="0px"}break}if(f){this._resizeEl.style.left=(parseInt(this._resizeEl.style.left,10)-e)+"px";this._resizeEl.style.top=(parseInt(this._resizeEl.style.top,10)-h)+"px";this.fireEvent("moveEvent",{target:"keypress"})}else{this._setConstraints()}this._syncBackgroundPosition()},_handleKeyPress:function(g){var e=a.getCharCode(g),f=false,h=((g.shiftKey)?this.get("shiftKeyTick"):this.get("keyTick"));switch(e){case 37:this._moveEl("left",h);f=true;break;case 38:this._moveEl("up",h);f=true;break;case 39:this._moveEl("right",h);f=true;break;case 40:this._moveEl("down",h);f=true;break;default:}if(f){a.preventDefault(g)}},_handleB4DragEvent:function(){this._setConstraints()},_handleDragEvent:function(){this._syncBackgroundPosition();this.fireEvent("dragEvent",arguments);this.fireEvent("moveEvent",{target:"dragevent"})},_handleBeforeResizeEvent:function(f){var j=c.getRegion(this.get("element")),k=this._resize._cache,i=this._resize._currentHandle,g=0,e=0;if(f.top&&(f.top<j.top)){g=(k.height+k.top)-j.top;c.setY(this._resize.getWrapEl(),j.top);this._resize.getWrapEl().style.height=g+"px";this._resize._cache.height=g;this._resize._cache.top=j.top;this._syncBackgroundPosition();return false}if(f.left&&(f.left<j.left)){e=(k.width+k.left)-j.left;c.setX(this._resize.getWrapEl(),j.left);this._resize._cache.left=j.left;this._resize.getWrapEl().style.width=e+"px";this._resize._cache.width=e;this._syncBackgroundPosition();return false}if(i!="tl"&&i!="l"&&i!="bl"){if(k.left&&f.width&&((k.left+f.width)>j.right)){e=(j.right-k.left);c.setX(this._resize.getWrapEl(),(j.right-e));this._resize.getWrapEl().style.width=e+"px";this._resize._cache.left=(j.right-e);this._resize._cache.width=e;this._syncBackgroundPosition();return false}}if(i!="t"&&i!="tr"&&i!="tl"){if(k.top&&f.height&&((k.top+f.height)>j.bottom)){g=(j.bottom-k.top);c.setY(this._resize.getWrapEl(),(j.bottom-g));this._resize.getWrapEl().style.height=g+"px";this._resize._cache.height=g;this._resize._cache.top=(j.bottom-g);this._syncBackgroundPosition();return false}}},_handleResizeMaskEl:function(){var e=this._resize._cache;this._resizeMaskEl.style.height=Math.floor(e.height)+"px";this._resizeMaskEl.style.width=Math.floor(e.width)+"px"},_handleResizeEvent:function(e){this._setConstraints(true);this._syncBackgroundPosition();this.fireEvent("resizeEvent",arguments);this.fireEvent("moveEvent",{target:"resizeevent"})},_syncBackgroundPosition:function(){this._handleResizeMaskEl();this._setBackgroundPosition(-(parseInt(this._resizeEl.style.left,10)),-(parseInt(this._resizeEl.style.top,10)))},_setBackgroundPosition:function(f,h){var j=parseInt(c.getStyle(this._resize.get("element"),"borderLeftWidth"),10);var g=parseInt(c.getStyle(this._resize.get("element"),"borderTopWidth"),10);if(isNaN(j)){j=0}if(isNaN(g)){g=0}var e=this._resize.getWrapEl().firstChild;var i=(f-j)+"px "+(h-g)+"px";this._resizeMaskEl.style.backgroundPosition=i},_setBackgroundImage:function(f){var e=this._resize.getWrapEl().firstChild;this._image=f;e.style.backgroundImage="url("+f+")"},_handleEndResizeEvent:function(){this._setConstraints(true)},_handleStartResizeEvent:function(){this._setConstraints(true);var j=this._resize._cache.height,f=this._resize._cache.width,i=parseInt(this._resize.getWrapEl().style.top,10),e=parseInt(this._resize.getWrapEl().style.left,10),g=0,k=0;switch(this._resize._currentHandle){case"b":g=(j+this._resize.dd.bottomConstraint);break;case"l":k=(f+this._resize.dd.leftConstraint);break;case"r":g=(j+i);k=(f+this._resize.dd.rightConstraint);break;case"br":g=(j+this._resize.dd.bottomConstraint);k=(f+this._resize.dd.rightConstraint);break;case"tr":g=(j+i);k=(f+this._resize.dd.rightConstraint);break}if(g){}if(k){}this.fireEvent("startResizeEvent",arguments)},_setConstraints:function(j){var h=this._resize;h.dd.resetConstraints();var n=parseInt(h.get("height"),10),f=parseInt(h.get("width"),10);if(j){n=h._cache.height;f=h._cache.width}var l=c.getRegion(this.get("element"));var g=h.getWrapEl();var o=c.getXY(g);var i=o[0]-l.left;var m=l.right-o[0]-f;var k=o[1]-l.top;var e=l.bottom-o[1]-n;if(k<0){k=0}h.dd.setXConstraint(i,m);h.dd.setYConstraint(k,e);return{top:k,right:m,bottom:e,left:i}},getCropCoords:function(){var e={top:parseInt(this._resize.getWrapEl().style.top,10),left:parseInt(this._resize.getWrapEl().style.left,10),height:this._resize._cache.height,width:this._resize._cache.width,image:this._image};return e},reset:function(){this._resize.destroy();this._resizeEl.parentNode.removeChild(this._resizeEl);this._createResize();this._setConstraints();return this},getEl:function(){return this.get("element")},getResizeEl:function(){return this._resizeEl},getWrapEl:function(){return this._wrap},getMaskEl:function(){return this._mask},getResizeMaskEl:function(){return this._resizeMaskEl},getResizeObject:function(){return this._resize},init:function(g,e){b.superclass.init.call(this,g,e);var h=g;if(!d.isString(h)){if(h.tagName&&(h.tagName.toLowerCase()=="img")){h=c.generateId(h)}else{return false}}else{var f=c.get(h);if(f.tagName&&f.tagName.toLowerCase()=="img"){}else{return false}}b._instances[h]=this;this._createWrap();this._createMask();this._createResize();this._setConstraints()},initAttributes:function(e){b.superclass.initAttributes.call(this,e);this.setAttributeConfig("initialXY",{writeOnce:true,validator:YAHOO.lang.isArray,value:e.initialXY||[10,10]});this.setAttributeConfig("keyTick",{validator:YAHOO.lang.isNumber,value:e.keyTick||1});this.setAttributeConfig("shiftKeyTick",{validator:YAHOO.lang.isNumber,value:e.shiftKeyTick||10});this.setAttributeConfig("useKeys",{validator:YAHOO.lang.isBoolean,value:((e.useKeys===false)?false:true)});this.setAttributeConfig("status",{validator:YAHOO.lang.isBoolean,value:((e.status===false)?false:true),method:function(f){if(this._resize){this._resize.set("status",f)}}});this.setAttributeConfig("minHeight",{validator:YAHOO.lang.isNumber,value:e.minHeight||50,method:function(f){if(this._resize){this._resize.set("minHeight",f)}}});this.setAttributeConfig("minWidth",{validator:YAHOO.lang.isNumber,value:e.minWidth||50,method:function(f){if(this._resize){this._resize.set("minWidth",f)}}});this.setAttributeConfig("maxWidth",{validator:YAHOO.lang.isNumber,value:e.maxWidth,method:function(f){if(this._resize){this._resize.set("maxWidth",f)}}});this.setAttributeConfig("maxHeight",{validator:YAHOO.lang.isNumber,value:e.maxHeight,method:function(f){if(this._resize){this._resize.set("maxHeight",f)}}});this.setAttributeConfig("ratio",{validator:YAHOO.lang.isBoolean,value:e.ratio||false,method:function(f){if(this._resize){this._resize.set("ratio",f)}}});this.setAttributeConfig("autoRatio",{validator:YAHOO.lang.isBoolean,value:((e.autoRatio===false)?false:true),method:function(f){if(this._resize){this._resize.set("autoRatio",f)}}});this.setAttributeConfig("initHeight",{writeOnce:true,validator:YAHOO.lang.isNumber,value:e.initHeight||(this.get("element").height/4)});this.setAttributeConfig("initWidth",{validator:YAHOO.lang.isNumber,writeOnce:true,value:e.initWidth||(this.get("element").width/4)})},destroy:function(){this._resize.destroy();this._resizeEl.parentNode.removeChild(this._resizeEl);this._mask.parentNode.removeChild(this._mask);a.purgeElement(this._wrap);this._wrap.parentNode.replaceChild(this.get("element"),this._wrap);for(var e in this){if(d.hasOwnProperty(this,e)){this[e]=null}}},toString:function(){if(this.get){return"ImageCropper (#"+this.get("id")+")"}return"Image Cropper"}});YAHOO.widget.ImageCropper=b})();YAHOO.register("imagecropper",YAHOO.widget.ImageCropper,{version:"2.6.0",build:"1321"});