/* Generated 2012-02-10 03:17:40*/jQuery.imgAreaSelect={onKeyPress:null};jQuery.imgAreaSelect.init=function(k,Q){var ar=jQuery(k),ae=jQuery("<div />"),af=jQuery("<div />"),ad=jQuery("<div />"),G=jQuery("<div />"),O,X=jQuery("<div />"),ag=jQuery("<div />"),ac=jQuery("<div />"),Y=jQuery("<div />"),I,L,T=[],h,i,aw,K,b,q,J,ak,z=0,ab="absolute",c,P,N,l,j,S=10,F=[],f=0,p=1,D,ao,R,v,u,av,au,Z,W,t,s={x1:0,y1:0,x2:0,y2:0,width:0,height:0};var o=ae.add(af).add(ad).add(G);var e=X.add(ag).add(ac).add(Y);function E(d){return d+aw.left+ak.left-J.left}function C(d){return d+aw.top+ak.top-J.top}function B(d){return d-aw.left-ak.left+J.left}function w(d){return d-aw.top-ak.top+J.top}function ai(d){return d.pageX+ak.left-J.left}function ah(d){return d.pageY+ak.top-J.top}function al(){c=ar;while(c.length&&!c.is("body")){if(!isNaN(c.css("z-index"))&&c.css("z-index")>z){z=c.css("z-index")}if(c.css("position")=="fixed"){ab="fixed"}c=c.parent()}}function am(){aw=ar.offset();aw.left=parseInt(aw.left);aw.top=parseInt(aw.top);K=ar.width();b=ar.height();if(jQuery(q).is("body")){J=ak={left:0,top:0}}else{J=jQuery(q).offset();ak={left:q.scrollLeft,top:q.scrollTop}}h=E(0);i=C(0)}function U(x){o.css({left:E(s.x1)+"px",top:C(s.y1)+"px",width:Math.max(s.width-Q.borderWidth*2,0)+"px",height:Math.max(s.height-Q.borderWidth*2,0)+"px"});G.css({width:s.width+"px",height:s.height+"px"});X.css({left:h+"px",top:i+"px",width:s.x1+"px",height:b+"px"});ag.css({left:h+s.x1+"px",top:i+"px",width:s.width+"px",height:s.y1+"px"});ac.css({left:h+s.x2+"px",top:i+"px",width:K-s.x2+"px",height:b+"px"});Y.css({left:h+s.x1+"px",top:i+s.y2+"px",width:s.width+"px",height:b-s.y2+"px"});if(I){T[0].css({left:E(s.x1)+"px",top:C(s.y1)+"px"});T[1].css({left:E(s.x2-L)+"px",top:C(s.y1)+"px"});T[2].css({left:E(s.x1)+"px",top:C(s.y2-L)+"px"});T[3].css({left:E(s.x2-L)+"px",top:C(s.y2-L)+"px"});if(T.length==8){T[4].css({left:E(s.x1+(s.width-L)/2)+"px",top:C(s.y1)+"px"});T[5].css({left:E(s.x1)+"px",top:C(s.y1+(s.height-L)/2)+"px"});T[6].css({left:E(s.x1+(s.width-L)/2)+"px",top:C(s.y2-L)+"px"});T[7].css({left:E(s.x2-L)+"px",top:C(s.y1+(s.height-L)/2)+"px"})}for(var d=0;d<T.length;d++){if(B(parseInt(T[d].css("left")))<0){T[d].css("left",E(0)+"px")}if(B(parseInt(T[d].css("left")))>K-L){T[d].css("left",E(K-L)+"px")}if(w(parseInt(T[d].css("top")))<0){T[d].css("top",C(0)+"px")}if(w(parseInt(T[d].css("top")))>b-L){T[d].css("top",C(b-L)+"px")}}}if(x!==false){if(jQuery.imgAreaSelect.keyPress!=ap){jQuery(document).unbind(jQuery.imgAreaSelect.keyPress,jQuery.imgAreaSelect.onKeyPress)}if(Q.keys){jQuery(document).bind(jQuery.imgAreaSelect.keyPress,jQuery.imgAreaSelect.onKeyPress=ap)}}}function A(d){if(!t){am();t=true;o.one("mouseout",function(){t=false})}Z=B(ai(d))-s.x1;W=w(ah(d))-s.y1;F=[];if(Q.resizable){if(W<=S){F[f]="n"}else{if(W>=s.height-S){F[f]="s"}}if(Z<=S){F[p]="w"}else{if(Z>=s.width-S){F[p]="e"}}}G.css("cursor",F.length?F.join("")+"-resize":Q.movable?"move":"");if(O){O.toggle()}}function n(d){if(d.which!=1){return false}am();if(Q.resizable&&F.length>0){jQuery("body").css("cursor",F.join("")+"-resize");v=E(s[F[p]=="w"?"x2":"x1"]);av=C(s[F[f]=="n"?"y2":"y1"]);jQuery(document).mousemove(aa);G.unbind("mousemove",A);jQuery(document).one("mouseup",function(){F=[];jQuery("body").css("cursor","");if(Q.autoHide||s.width==0||s.height==0){o.add(e).add(I).hide()}Q.onSelectEnd(k,s);jQuery(document).unbind("mousemove",aa);G.mousemove(A)})}else{if(Q.movable){l=s.x1+h;j=s.y1+i;P=ai(d);N=ah(d);G.unbind("mousemove",A);jQuery(document).mousemove(a).one("mouseup",function(){Q.onSelectEnd(k,s);jQuery(document).unbind("mousemove",a);G.mousemove(A)})}else{ar.mousedown(d)}}return false}function m(){u=Math.max(h,Math.min(h+K,v+Math.abs(au-av)*R*(u>=v?1:-1)));au=Math.round(Math.max(i,Math.min(i+b,av+Math.abs(u-v)/R*(au>=av?1:-1))));u=Math.round(u)}function aj(){au=Math.max(i,Math.min(i+b,av+Math.abs(u-v)/R*(au>=av?1:-1)));u=Math.round(Math.max(h,Math.min(h+K,v+Math.abs(au-av)*R*(u>=v?1:-1))));au=Math.round(au)}function aq(d,x){u=d;au=x;if(Q.minWidth&&Math.abs(u-v)<Q.minWidth){u=v-Q.minWidth*(u<v?1:-1);if(u<h){v=h+Q.minWidth}else{if(u>h+K){v=h+K-Q.minWidth}}}if(Q.minHeight&&Math.abs(au-av)<Q.minHeight){au=av-Q.minHeight*(au<av?1:-1);if(au<i){av=i+Q.minHeight}else{if(au>i+b){av=i+b-Q.minHeight}}}u=Math.max(h,Math.min(u,h+K));au=Math.max(i,Math.min(au,i+b));if(R){if(Math.abs(u-v)/R>Math.abs(au-av)){aj()}else{m()}}if(Q.maxWidth&&Math.abs(u-v)>Q.maxWidth){u=v-Q.maxWidth*(u<v?1:-1);if(R){aj()}}if(Q.maxHeight&&Math.abs(au-av)>Q.maxHeight){au=av-Q.maxHeight*(au<av?1:-1);if(R){m()}}s={x1:B(Math.min(v,u)),x2:B(Math.max(v,u)),y1:w(Math.min(av,au)),y2:w(Math.max(av,au)),width:Math.abs(u-v),height:Math.abs(au-av)};U();Q.onSelectChange(k,s)}function aa(d){u=!F.length||F[p]||R?ai(d):E(s.x2);au=!F.length||F[f]||R?ah(d):C(s.y2);aq(u,au);return false}function M(d,x){u=(v=d)+s.width;au=(av=x)+s.height;s.x1=B(v);s.y1=w(av);s.x2=B(u);s.y2=w(au);U();Q.onSelectChange(k,s)}function a(d){var x=Math.max(h,Math.min(l+ai(d)-P,h+K-s.width));var y=Math.max(i,Math.min(j+ah(d)-N,i+b-s.height));M(x,y);d.preventDefault();return false}function at(d){am();s={x1:B(v),y1:w(av)};aq(v,av);F=[];o.add(e).add(I).show();jQuery(document).unbind("mouseup",an).mousemove(aa);G.unbind("mousemove",A);Q.onSelectStart(k,s);jQuery(document).one("mouseup",function(){if(Q.autoHide||(s.width*s.height==0)){o.add(e).add(I).hide()}Q.onSelectEnd(k,s);jQuery(document).unbind("mousemove",aa);G.mousemove(A)})}function an(){jQuery(document).unbind("mousemove",at);o.add(e).add(I).hide();s={x1:0,y1:0,x2:0,y2:0,width:0,height:0};Q.onSelectChange(k,s);Q.onSelectEnd(k,s)}function g(d){if(d.which!=1){return false}P=v=ai(d);N=av=ah(d);jQuery(document).one("mousemove",at).one("mouseup",an);return false}function r(){am();U(false);v=E(s.x1);av=C(s.y1);u=E(s.x2);au=C(s.y2)}var ap=function(V){var x=Q.keys,ax=10,H,y=V.keyCode||V.which;if(!isNaN(x.arrows)){ax=x.arrows}if(!isNaN(x.shift)&&V.shiftKey){ax=x.shift}if(!isNaN(x.ctrl)&&V.ctrlKey){ax=x.ctrl}if(!isNaN(x.alt)&&(V.altKey||V.originalEvent.altKey)){ax=x.alt}if(x.arrows=="resize"||(x.shift=="resize"&&V.shiftKey)||(x.ctrl=="resize"&&V.ctrlKey)||(x.alt=="resize"&&(V.altKey||V.originalEvent.altKey))){switch(y){case 37:ax=-ax;case 39:H=Math.max(v,u);v=Math.min(v,u);u=Math.max(H+ax,v);if(R){aj()}break;case 38:ax=-ax;case 40:H=Math.max(av,au);av=Math.min(av,au);au=Math.max(H+ax,av);if(R){m()}break;default:return}aq(u,au)}else{v=Math.min(v,u);av=Math.min(av,au);switch(y){case 37:M(Math.max(v-ax,h),av);break;case 38:M(v,Math.max(av-ax,i));break;case 39:M(v+Math.min(ax,K-B(u)),av);break;case 40:M(v,av+Math.min(ax,b-w(au)));break;default:return}}return false};this.setOptions=function(x){Q=jQuery.extend(Q,x);if(x.x1!=null){s={x1:x.x1,y1:x.y1,x2:x.x2,y2:x.y2};x.show=true}if(x.keys){Q.keys=jQuery.extend({shift:1,ctrl:"resize"},x.keys===true?{}:x.keys)}q=jQuery(Q.parent).get(0);am();al();v=E(s.x1);av=C(s.y1);u=E(s.x2);au=C(s.y2);s.width=u-v;s.height=au-av;if(I){I.remove();I=null;T=[]}if(Q.handles){for(var d=0;d<(Q.handles=="corners"?4:8);d++){I=I?I.add(T[d]=jQuery("<div />")):T[d]=jQuery("<div />")}L=4+Q.borderWidth;I.css({position:ab,borderWidth:Q.borderWidth,borderStyle:"solid",borderColor:Q.borderColor1,backgroundColor:Q.borderColor2,display:ae.css("display"),width:L+"px",height:L+"px",fontSize:"0px",zIndex:z>0?z+1:"1"});I.addClass(Q.classPrefix+"-handle");L+=Q.borderWidth*2}e.addClass(Q.classPrefix+"-outer");ae.addClass(Q.classPrefix+"-selection");af.addClass(Q.classPrefix+"-border1");ad.addClass(Q.classPrefix+"-border2");o.css({borderWidth:Q.borderWidth+"px"});ae.css({backgroundColor:Q.selectionColor,opacity:Q.selectionOpacity});af.css({borderStyle:"solid",borderColor:Q.borderColor1});ad.css({borderStyle:"dashed",borderColor:Q.borderColor2});e.css({opacity:Q.outerOpacity,backgroundColor:Q.outerColor});jQuery(Q.parent).append(e.add(o).add(I));U();if(x.hide){o.add(e).add(I).hide()}else{if(x.show){o.add(e).add(I).show()}}R=Q.aspectRatio&&(ao=Q.aspectRatio.split(/:/))?ao[0]/ao[1]:null;if(R){if(Q.minWidth){Q.minHeight=parseInt(Q.minWidth/R)}else{if(Q.minHeight){Q.minWidth=parseInt(Q.minHeight*R)}}}if(Q.disable||Q.enable===false){G.unbind("mousemove",A).unbind("mousedown",n);ar.add(e).unbind("mousedown",g);jQuery(window).unbind("resize",r)}else{if(Q.enable||Q.disable===false){if(Q.resizable||Q.movable){G.mousemove(A).mousedown(n)}if(!Q.persistent){ar.add(e).mousedown(g)}jQuery(window).resize(r)}}Q.enable=Q.disable=undefined};if(jQuery.browser.msie){ar.attr("unselectable","on")}jQuery.imgAreaSelect.keyPress=jQuery.browser.msie||jQuery.browser.safari?"keydown":"keypress";if(jQuery.browser.opera){G.append(O=jQuery('<div style="width: 100%;height: 100%;" />'))}al();o.add(e).css({display:"none",position:ab,overflow:"hidden",zIndex:z>0?z:"0"});G.css({zIndex:z>0?z+2:"2"});ae.css({borderStyle:"solid"});this.setOptions(Q=jQuery.extend({borderColor1:"#000",borderColor2:"#fff",borderWidth:1,classPrefix:"imgareaselect",movable:true,resizable:true,selectionColor:"#fff",selectionOpacity:0.2,outerColor:"#000",outerOpacity:0.2,parent:"body",onSelectStart:function(){},onSelectChange:function(){},onSelectEnd:function(){}},Q))};jQuery.fn.imgAreaSelect=function(a){a=a||{};this.each(function(){if(jQuery(this).data("imgAreaSelect")){jQuery(this).data("imgAreaSelect").setOptions(a)}else{if(a.enable===undefined&&a.disable===undefined){a.enable=true}jQuery(this).data("imgAreaSelect",new jQuery.imgAreaSelect.init(this,a))}});return this};
