var Matrix=function(a,b,c,d,e,f,g,h,i){"array"===$.type(a)?this.elements=[+a[0],+a[2],+a[4],+a[1],+a[3],+a[5],0,0,1]:this.elements=[a,b,c,d,e,f,g||0,h||0,i||1]},Vector=(Matrix.prototype={x:function(matrix){var a=this.elements,b=matrix.elements;return matrix instanceof Vector&&3===b.length?new Vector(a[0]*b[0]+a[1]*b[1]+a[2]*b[2],a[3]*b[0]+a[4]*b[1]+a[5]*b[2],a[6]*b[0]+a[7]*b[1]+a[8]*b[2]):b.length===a.length&&new Matrix(a[0]*b[0]+a[1]*b[3]+a[2]*b[6],a[0]*b[1]+a[1]*b[4]+a[2]*b[7],a[0]*b[2]+a[1]*b[5]+a[2]*b[8],a[3]*b[0]+a[4]*b[3]+a[5]*b[6],a[3]*b[1]+a[4]*b[4]+a[5]*b[7],a[3]*b[2]+a[4]*b[5]+a[5]*b[8],a[6]*b[0]+a[7]*b[3]+a[8]*b[6],a[6]*b[1]+a[7]*b[4]+a[8]*b[7],a[6]*b[2]+a[7]*b[5]+a[8]*b[8])},inverse:function(){var d=1/this.determinant(),a=this.elements;return new Matrix(d*(a[8]*a[4]-a[7]*a[5]),d*-(a[8]*a[1]-a[7]*a[2]),d*(a[5]*a[1]-a[4]*a[2]),d*-(a[8]*a[3]-a[6]*a[5]),d*(a[8]*a[0]-a[6]*a[2]),d*-(a[5]*a[0]-a[3]*a[2]),d*(a[7]*a[3]-a[6]*a[4]),d*-(a[7]*a[0]-a[6]*a[1]),d*(a[4]*a[0]-a[3]*a[1]))},determinant:function(){var a=this.elements;return a[0]*(a[8]*a[4]-a[7]*a[5])-a[3]*(a[8]*a[1]-a[7]*a[2])+a[6]*(a[5]*a[1]-a[4]*a[2])}},function(x,y,z){this.elements=[x,y,z]});Vector.prototype.e=Matrix.prototype.e=function(i){return null!=this.elements[i]?this.elements[i]:this.elements},$.ui.plugin.add("draggable","transform",{start:function(event,ui){if(!$(this).data("ui-draggable"))return!1;var matrix;$(this).data("ui-draggable").matrix=new Matrix((matrix=[$(this).parents('[style*="transform"]').css("transform")],(matrix=new RegExp("^matrix\\((\\-?[\\d\\.e]+)\\,?\\s*(\\-?[\\d\\.e]+)\\,?\\s*(\\-?[\\d\\.e]+)\\,?\\s*(\\-?[\\d\\.e]+)\\,?\\s*(\\-?[\\d\\.e]+)\\,?\\s*(\\-?[\\d\\.e]+)\\)$").exec(matrix))&&matrix.shift(),matrix||[1,0,0,1,0,0]))},drag:function(event,ui){if(!$(this).data("ui-draggable"))return!1;var inst=$(this).data("ui-draggable"),t_pos=inst.matrix.inverse().x(new Vector(ui.position.left,ui.position.top,0));ui.position.left=t_pos.e(0),ui.position.top=t_pos.e(1),inst.options.grid&&(ui.position.left=ui.position.left-ui.position.left%inst.options.grid[0],ui.position.top=ui.position.top-ui.position.top%inst.options.grid[1]),inst.containment&&(ui.position.left<inst.containment[0]&&(ui.position.left=inst.containment[0]),ui.position.left>inst.containment[2]&&(ui.position.left=inst.containment[2]),ui.position.top<inst.containment[1]&&(ui.position.top=inst.containment[1]),ui.position.top>inst.containment[3]&&(ui.position.top=inst.containment[3]))}}),$.ui.plugin.add("resizable","transform",{start:function(event,ui){if(!$(this).data("ui-resizable"))return!1;var matrix;$(this).data("ui-resizable").matrix=new Matrix((matrix=[$(this).parents('[style*="transform"]').css("transform")],(matrix=new RegExp("^matrix\\((\\-?[\\d\\.e]+)\\,?\\s*(\\-?[\\d\\.e]+)\\,?\\s*(\\-?[\\d\\.e]+)\\,?\\s*(\\-?[\\d\\.e]+)\\,?\\s*(\\-?[\\d\\.e]+)\\,?\\s*(\\-?[\\d\\.e]+)\\)$").exec(matrix))&&matrix.shift(),matrix||[1,0,0,1,0,0]))},resize:function(event,ui){if(!$(this).data("ui-resizable"))return!1;var inst=$(this).data("ui-resizable");inst.helper&&0<inst.helper.length&&(ui=inst.matrix.inverse().x(new Vector(ui.size.width,ui.size.height,0)),inst.helper[0].width=ui.e(0),inst.helper[0].height=ui.e(1))}});