var dragObj=new Object();var maskObj=new Object();var handleObj=new Object();var supportWindowEvent=typeof(window.event)!='undefined';var supportWindowScroll=typeof(window.scrollX)!='undefined';var supportAttachEvent=typeof(document.attachEvent)!='undefined';var supportEventListener=typeof(document.addEventListener)!='undefined';var currentAction='move';function register(action){currentAction=action}function callDragStart(ev,action){dragStart(ev,action)}function init_drag(){dragObj.elNode=$('iz_crop');maskObj.Top=$('iz_mT');maskObj.Left=$('iz_mL');maskObj.Bottom=$('iz_mB');maskObj.Right=$('iz_mR');maskObj.TopBorder=$('iz_mTB');maskObj.LeftBorder=$('iz_mLB');maskObj.BottomBorder=$('iz_mBB');maskObj.RightBorder=$('iz_mRB');handleObj.NE=$('iz_ne');handleObj.NW=$('iz_nw');handleObj.SE=$('iz_se');handleObj.SW=$('iz_sw')}function init_image(width,height){init_drag();dragObj.elNode.style.left=0+"px";maskLeftFix(0);maskRightFix(width);dragObj.elNode.style.top=0+"px";maskTopFix(0);maskBottomFix(height)}function dragStart(event){var el;var x,y;init_drag();if(supportWindowEvent){x=window.event.clientX+document.documentElement.scrollLeft+document.body.scrollLeft;y=window.event.clientY+document.documentElement.scrollTop+document.body.scrollTop}else if(supportWindowScroll){x=event.clientX+window.scrollX;y=event.clientY+window.scrollY}dragObj.cursorStartX=x;dragObj.cursorStartY=y;dragObj.elStartLeft=parseFloat(dragObj.elNode.style.left,10);dragObj.elStartTop=parseFloat(dragObj.elNode.style.top,10);dragObj.elStartWidth=parseFloat(dragObj.elNode.style.width,10);dragObj.elStartHeight=parseFloat(dragObj.elNode.style.height,10);if(supportAttachEvent){document.attachEvent("onmousemove",dragGo);document.attachEvent("onmouseup",dragStop);window.event.cancelBubble=true;window.event.returnValue=false}else if(supportEventListener){document.addEventListener("mousemove",dragGo,true);document.addEventListener("mouseup",dragStop,true);event.preventDefault()}}function dragGo(event){var x,y;var iBottom,iTop,iLeft,iRight;if(supportWindowEvent){x=window.event.clientX+document.documentElement.scrollLeft+document.body.scrollLeft;y=window.event.clientY+document.documentElement.scrollTop+document.body.scrollTop}else if(supportWindowScroll){x=event.clientX+window.scrollX;y=event.clientY+window.scrollY}if(currentAction=='move'){var xMove=(dragObj.elStartLeft+x-dragObj.cursorStartX);var yMove=(dragObj.elStartTop+y-dragObj.cursorStartY);if(xMove<=0){iLeft=0}else if((xMove+imgCropWidth)>=(imgWidth)){iLeft=(imgWidth-imgCropWidth)}else{iLeft=xMove}dragObj.elNode.style.left=iLeft+"px";maskLeftFix(iLeft);maskRightFix(iLeft+imgCropWidth);if(yMove<=0){iTop=0}else if((yMove+imgCropHeight)>=(imgHeight)){iTop=(imgHeight-imgCropHeight)}else{iTop=yMove}dragObj.elNode.style.top=iTop+"px";maskTopFix(parseInt(iTop));maskBottomFix(iTop+imgCropHeight)}else{var xMove=(dragObj.elStartLeft+x-dragObj.cursorStartX);var yMove=(dragObj.elStartTop+y-dragObj.cursorStartY);var xStopAt=0;var yStopAt=0;if(currentAction.indexOf('e')!=-1){xMove+=dragObj.elStartWidth;xStopAt=imgWidth}if(currentAction.indexOf('s')!=-1){yMove+=dragObj.elStartHeight;yStopAt=imgHeight}switch(currentAction){case'nw':if(imgRatio>0){xStopAt=(dragObj.elStartLeft+dragObj.elStartWidth)-(dragObj.elStartTop+dragObj.elStartHeight)*imgRatio;if(xStopAt<0){xStopAt=0;yStopAt=(dragObj.elStartTop+dragObj.elStartHeight)-((dragObj.elStartLeft+dragObj.elStartWidth)/imgRatio)}else{yStopAt=0}yMove=(((dragObj.elStartLeft-xMove)/imgRatio)-dragObj.elStartTop)*(-1)}if(yMove<=yStopAt){iTop=yStopAt}else if(yMove>=(dragObj.elStartTop+dragObj.elStartHeight-imgCropMin)){iTop=(dragObj.elStartTop+dragObj.elStartHeight-imgCropMin)}else{iTop=yMove}if(xMove<=xStopAt){iLeft=xStopAt}else if(xMove>=(dragObj.elStartLeft+dragObj.elStartWidth-imgCropMin)){iLeft=(dragObj.elStartLeft+dragObj.elStartWidth-imgCropMin)}else{iLeft=xMove}break;case'ne':if(imgRatio>0){xStopAt=((dragObj.elStartTop+dragObj.elStartHeight)*imgRatio)+dragObj.elStartLeft;if(xStopAt>imgWidth){xStopAt=imgWidth;yStopAt=(dragObj.elStartTop+dragObj.elStartHeight)-((imgWidth-dragObj.elStartLeft)/imgRatio)}else{yStopAt=0}xMove=(((dragObj.elStartTop+dragObj.elStartHeight)-yMove)*imgRatio)}if((xMove+dragObj.elStartLeft)>=xStopAt){iRight=xStopAt}else if((xMove+dragObj.elStartLeft)<=dragObj.elStartLeft+imgCropMin){iRight=dragObj.elStartLeft+imgCropMin}else{iRight=xMove+dragObj.elStartLeft}if(yMove<=yStopAt){iTop=yStopAt}else if(yMove>=(dragObj.elStartTop+dragObj.elStartHeight-imgCropMin)){iTop=(dragObj.elStartTop+dragObj.elStartHeight-imgCropMin)}else{iTop=yMove}break;case'se':if(imgRatio>0){xStopAt=((imgHeight-dragObj.elStartTop)*imgRatio)+dragObj.elStartLeft;if(xStopAt>imgWidth){xStopAt=imgWidth;yStopAt=(dragObj.elStartTop)+((imgWidth-dragObj.elStartLeft)/imgRatio)}else{yStopAt=imgHeight}yMove=(((dragObj.elStartLeft-xMove)/imgRatio)-dragObj.elStartTop)*-1}if(yMove>=yStopAt){iBottom=yStopAt}else if((yMove)<=dragObj.elStartTop+imgCropMin){iBottom=dragObj.elStartTop+imgCropMin}else{iBottom=yMove}if(xMove>=xStopAt){iRight=xStopAt}else if((xMove)<=dragObj.elStartLeft+imgCropMin){iRight=dragObj.elStartLeft+imgCropMin}else{iRight=xMove}break;case'sw':if(imgRatio>0){xStopAt=(dragObj.elStartLeft+dragObj.elStartWidth)-((imgHeight-dragObj.elStartTop)*imgRatio);if(xStopAt<0){xStopAt=0;yStopAt=((dragObj.elStartLeft+dragObj.elStartWidth)/imgRatio)+dragObj.elStartTop}else{yStopAt=imgHeight}xMove=(((yMove-dragObj.elStartTop)*imgRatio)-(dragObj.elStartLeft+dragObj.elStartWidth))*-1}if(yMove>=yStopAt){iBottom=yStopAt}else if(yMove<=dragObj.elStartTop+imgCropMin){iBottom=dragObj.elStartTop+imgCropMin}else{iBottom=yMove}if(xMove<=xStopAt){iLeft=xStopAt}else if(xMove>=(dragObj.elStartLeft+dragObj.elStartWidth-imgCropMin)){iLeft=(dragObj.elStartLeft+dragObj.elStartWidth-imgCropMin)}else{iLeft=xMove}break}if(iRight!=null){imgCropWidth=(iRight-dragObj.elStartLeft);dragObj.elNode.style.width=imgCropWidth+"px";maskRightFix(iRight)}if(iTop!=null){dragObj.elNode.style.top=iTop+"px";imgCropHeight=(dragObj.elStartTop+dragObj.elStartHeight-iTop);dragObj.elNode.style.height=imgCropHeight+"px";maskTopFix(iTop)}if(iBottom!=null){imgCropHeight=(iBottom-dragObj.elStartTop);dragObj.elNode.style.height=imgCropHeight+"px";maskBottomFix(iBottom)}if(iLeft!=null){dragObj.elNode.style.left=iLeft+"px";imgCropWidth=(dragObj.elStartLeft+dragObj.elStartWidth-iLeft);dragObj.elNode.style.width=imgCropWidth+"px";maskLeftFix(iLeft)}}if(supportWindowEvent){window.event.cancelBubble=true;window.event.returnValue=false}else if(typeof(event.preventDefault)!='undefined'){event.preventDefault()}}function dragStop(event){currentAction='move';if(supportAttachEvent){document.detachEvent("onmousemove",dragGo);document.detachEvent("onmouseup",dragStop)}else if(supportEventListener){document.removeEventListener("mousemove",dragGo,true);document.removeEventListener("mouseup",dragStop,true)}dragObj.elStartLeft=parseFloat(dragObj.elNode.style.left,10);dragObj.elStartTop=parseFloat(dragObj.elNode.style.top,10);dragObj.elStartWidth=parseFloat(dragObj.elNode.style.width,10);dragObj.elStartHeight=parseFloat(dragObj.elNode.style.height,10);var west=dragObj.elStartLeft/imgProportion;var east=(dragObj.elStartLeft+dragObj.elStartWidth)/imgProportion;var north=dragObj.elStartTop/imgProportion;var south=(dragObj.elStartTop+dragObj.elStartHeight)/imgProportion;if(west>=0){$("textW").value=west}else{$("textW").value=-1}if(east<=imgOrigWidth){$("textE").value=east}else{$("textE").value=-1}if(north>=0){$("textN").value=north}else{$("textN").value=-1}if(south<=imgOrigHeight){$("textS").value=south}else{$("textS").value=-1}}function maskLeftFix(boundary,crop){maskObj.Left.style.width=boundary+"px";maskObj.Top.style.left=boundary+"px";maskObj.Top.style.width=(imgWidth-boundary)+"px";maskObj.LeftBorder.style.width=boundary+"px";maskObj.TopBorder.style.left=boundary+"px";maskObj.TopBorder.style.width=imgCropWidth+"px";maskObj.BottomBorder.style.left=maskObj.Left.style.width;maskObj.BottomBorder.style.width=imgCropWidth+"px";handleObj.NE.style.left=(imgCropWidth-4)+"px";handleObj.SE.style.left=(imgCropWidth-4)+"px"}function maskRightFix(boundary,crop){maskObj.Right.style.left=boundary+"px";maskObj.Right.style.width=(imgWidth-boundary)+"px";maskObj.Bottom.style.width=boundary+"px";maskObj.RightBorder.style.left=boundary+"px";maskObj.RightBorder.style.width=(imgWidth-boundary)+"px";maskObj.BottomBorder.style.width=imgCropWidth+"px";maskObj.TopBorder.style.width=imgCropWidth+"px";handleObj.NE.style.left=(imgCropWidth-4)+"px";handleObj.SE.style.left=(imgCropWidth-4)+"px"}function maskTopFix(boundary,crop){maskObj.Top.style.height=boundary+"px";maskObj.Right.style.top=boundary+"px";maskObj.Right.style.height=(imgHeight-boundary)+"px";maskObj.TopBorder.style.height=boundary+"px";maskObj.RightBorder.style.top=boundary+"px";maskObj.RightBorder.style.height=imgCropHeight+"px";maskObj.LeftBorder.style.top=maskObj.TopBorder.style.height;maskObj.LeftBorder.style.height=imgCropHeight+"px";handleObj.SW.style.top=(imgCropHeight-4)+"px";handleObj.SE.style.top=(imgCropHeight-4)+"px"}function maskBottomFix(boundary,crop){maskObj.Bottom.style.top=boundary+"px";maskObj.Bottom.style.height=(imgHeight-boundary)+"px";maskObj.Left.style.height=boundary+"px";maskObj.BottomBorder.style.top=boundary+"px";maskObj.BottomBorder.style.height=(imgHeight-boundary)+"px";maskObj.LeftBorder.style.height=imgCropHeight+"px";maskObj.RightBorder.style.top=maskObj.Top.style.height;maskObj.RightBorder.style.height=imgCropHeight+"px";handleObj.SW.style.top=(imgCropHeight-4)+"px";handleObj.SE.style.top=(imgCropHeight-4)+"px"}