
(function($){
$.fn.jqDragResize=function(obj,dh,rh,opts){this._opt=opts; this.i(obj,dh,'d',this._opt);  this.i(obj,rh,'r',this._opt);};
$.jqDnR={dnr:{},e:0,
drag:function(v){
 //Update Data
 

if(opt.container_id)
{
    opt.minLeft=0;
    opt.minTop=0;
    opt.maxRight=$('#'+opt.container_id).width();
    opt.maxBottom=$('#'+opt.container_id).height();
}

 if(M.k == 'd')
 {
     ll=M.X+v.pageX-M.pX;
     if(ll<opt.minLeft) ll=opt.minLeft;
     if(ll+f('width')>opt.maxRight) ll=opt.maxRight-f('width');
     
     tt=M.Y+v.pageY-M.pY;
     if(tt<opt.minTop) tt=opt.minTop;
     if(tt+f('height')>opt.maxBottom) tt=opt.maxBottom-f('height');
     
     E.css({left:ll,top:tt});

    opt.onChange();
 }
 else 
 {
     ww=Math.max(v.pageX-M.pX+M.W,0);
     if(ww+f('left')>opt.maxRight) ww=opt.maxRight-f('left');
     if(ww<opt.minWidth) ww=opt.minWidth;
     
     hh=Math.max(v.pageY-M.pY+M.H,0);
     if(hh+f('top')>opt.maxBottom) hh=opt.maxBottom-f('top');
     if(hh<opt.minHeight) hh=opt.minHeight;
     
     E.css({width:ww,height:hh});

     opt.onChange();
 }
  return false;
},

stop:function(){if(!opt.iepng) E.css('opacity',M.o);$().unbind('mousemove',J.drag).unbind('mouseup',J.stop); }
};
var J=$.jqDnR,M=J.dnr,E=J.e,opt;
$.fn.jqDragResize.prototype.i =function(e,h,k){
 opt=this._opt  = $.extend({
            minWidth:13,
            minHeight:13,
			minLeft: 0,
			minTop: 0,
			maxRight: 0,
			maxBottom: 0,
			container_id: '',
            iepng:false,
            onChange:function(){}
			}, this._opt);
 e.each(function(){h=(h)?$(h,e):e;
 h.bind('mousedown',{e:e,k:k},function(v){var d=v.data,p={};E=d.e;
 // attempt utilization of dimensions plugin to fix IE issues
 if(E.css('position') != 'relative'){try{E.position(p);}catch(e){}}
 M={X:p.left||f('left')||0,Y:p.top||f('top')||0,W:f('width')||E[0].scrollWidth||0,H:f('height')||E[0].scrollHeight||0,pX:v.pageX,pY:v.pageY,k:d.k,o:E.css('opacity')};
 if(!opt.iepng) E.css({opacity:0.8});$().mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
 return false;
 });
}); return this;},
f=function(k){return parseInt(E.css(k))||false;};
})(jQuery);


