function IctinusShape(B,A){if(!B||!B.draw){throw new Error("Класс не предназначен для вызова напрямую через new IctinusShape(), используй ictinus.shape()")}this._adapter=B;this._cache={};this._session={};this.paths=A||[];this.strokeWidth=1;this.strokeColor="#000000";this.fillColor="#ff0000";this.scaleGrid={x1:0,x2:0,y1:0,y2:0};this._width=100;this._height=100;this.contentBox={x:0,y:0,width:0,height:0};this._scaleX=1;this._scaleY=1}IctinusShape.prototype={getPaths:function(){if(this._session.paths){return this._session.paths}var I=[];function K(N){var O={};for(var P in N){if(N.hasOwnProperty(P)){O[P]=N[P]}}return O}function L(N,P,O){for(var Q in N){if(N.hasOwnProperty(Q)){if((!O||(Q!="type"&&Q.indexOf(O)!=-1))){N[Q]=P(N[Q])}}}}var E=this.scaleX();var D=this.scaleY();var J=this._width*(E-1);var C=this._height*(D-1);var F={moveX:function(N){return N+J},moveY:function(N){return N+C},scaleX:function(N){return N*E},scaleY:function(N){return N*D}};if(!this.isEmptyGrid()){var B=K(this.scaleGrid);function H(O,N){var Q,P;if(O<=B.x1){P="1"}else{if(O>=B.x2){P="3"}else{P="2"}}if(N<=B.y1){Q="1"}else{if(N>=B.y2){Q="3"}else{Q="2"}}return parseInt(Q+P,10)}for(var A=0;A<this.paths.length;A++){var M=K(this.paths[A]);var G;if(M.type==ictinus.DRAW_TYPE.CLOSE){I.push(M);continue}switch(H(M.x,M.y)){case 12:L(M,F.scaleX,"x");break;case 13:L(M,F.moveX,"x");break;case 21:L(M,F.scaleY,"y");break;case 22:L(M,F.scaleX,"x");L(M,F.scaleY,"y");break;case 23:L(M,F.moveX,"x");L(M,F.scaleY,"y");break;case 31:L(M,F.moveY,"y");break;case 32:L(M,F.scaleX,"x");L(M,F.moveY,"y");break;case 33:L(M,F.moveX,"x");L(M,F.moveY,"y");break}I.push(M)}}else{for(var A=0;A<this.paths.length;A++){var M=K(this.paths[A]);L(M,F.scaleX,"x");L(M,F.scaleY,"y");I.push(M)}}return I},addPath:function(A){for(var B=0;B<arguments.length;B++){this.paths.push(arguments[B])}},scaleX:function(A){if(arguments.length){this._scaleX=parseFloat(A,10)}return this._scaleX},scaleY:function(A){if(arguments.length){this._scaleY=parseFloat(A,10)}return this._scaleY},width:function(A){if(arguments.length){this._width=parseFloat(A,10)}return this._width*this.scaleX()},height:function(A){if(arguments.length){this._height=parseFloat(A,10)}return this._height*this.scaleY()},setScaleGrid:function(A,D,C,B){this.scaleGrid.x1=Math.min(A,D);this.scaleGrid.x2=Math.max(A,D);this.scaleGrid.y1=Math.min(C,B);this.scaleGrid.y2=Math.max(C,B)},isEmptyGrid:function(){var A=this.scaleGrid;return(!A.x1&&!A.x2&&!A.y1&&!A.y2)},draw:function(B,A){this._session.paths=A;ictinus.draw(B,this);delete this._session.paths},decorate:function(A,B){this._session.paths=B;var C=ictinus.decorate(A,this);delete this._session.paths;return C}};var ictinus=(function(){var E=navigator.userAgent.toLowerCase();var O=/msie/.test(E)&&!/opera/.test(E);var F={MOVETO:"moveto",CLOSE:"close",LINE:"line",BEZIER:"bezier",QUADRATIC:"quad"};var N={line_width:1,line_color:"#ff0000"};function B(){var Q={};for(var S=0;S<arguments.length;S++){var P=arguments[S];if(!P){continue}for(var R in P){Q[R]=P[R]}}return Q}function M(P,Q){return P.nodeType==1&&P.className.indexOf(Q)!=-1}function K(P){return{type:P}}function G(Q,P){return B(K(F.LINE),{x:Q,y:P})}function J(Q,P){return B(K(F.MOVETO),{x:Q,y:P})}function I(Q,P,S,U,R,T){return B(G(Q,P),{type:F.BEZIER,cpx1:S,cpy1:U,cpx2:R,cpy2:T})}function L(Q,P,S,R){return B(G(Q,P),{type:F.QUADRATIC,cpx:S,cpy:R})}function D(P){return B(N,P)}function H(){var R;function Q(U){var T;T=document.createElement("canvas");T.width=U.offsetWidth+1;T.height=U.offsetHeight+1;T.className="ictinus";if(U.tagName=="IMG"){U.parentNode.insertBefore(T,U)}else{U.appendChild(T)}U.className=(U.className?U.className+" ":"")+"ictinus-init";R=T;return T.getContext("2d")}function P(U,V){U.beginPath();var T=V.getPaths();for(var W=0;W<T.length;W++){var X=T[W];switch(X.type){case F.MOVETO:U.moveTo(X.x,X.y);break;case F.LINE:U.lineTo(X.x,X.y);break;case F.BEZIER:U.bezierCurveTo(X.cpx1,X.cpy1,X.cpx2,X.cpy2,X.x,X.y);break;case F.QUADRATIC:U.quadraticCurveTo(X.cpx,X.cpy,X.x,X.y);break;case F.CLOSE:U.closePath();U.beginPath();break}}U.closePath()}function S(W){var Y=1;var T="#cccccc";var U="red";updateLook();function V(c,b){canvas.fillRect(c.x-b/2,c.y-b/2,b,b)}V(shape.anchor,6);canvas.beginPath();canvas.moveTo(shape.anchor.x,shape.anchor.y);var X=shape.getSegments();for(var Z=0;Z<X.length;Z++){var a=X[Z];canvas.lineTo(a.cp1.x,a.cp1.y);canvas.stroke();canvas.beginPath();canvas.moveTo(a.cp2.x,a.cp2.y);canvas.lineTo(a.anchor.x,a.anchor.y);canvas.stroke();V(a.anchor,6);V(a.cp1,2);V(a.cp2,2);canvas.beginPath();canvas.moveTo(a.anchor.x,a.anchor.y)}restoreLook()}return{decorate:function(V,U){var T=Q(V);T.clearRect(0,0,T.canvas.width,T.canvas.height);T.save();P(T,U);T.clip();T.drawImage(V,0,0,V.offsetWidth,V.offsetHeight);T.restore();T.save();var W=(U.strokeWidth%2)/2;T.translate(W,W);P(T,U);if(U.strokeWidth){T.strokeStyle=U.strokeColor;T.lineWidth=U.strokeWidth;T.stroke()}T.restore();return R},draw:function(V,U){var T=Q(V);T.clearRect(0,0,T.canvas.width,T.canvas.height);T.save();P(T,U);T.fillStyle=U.fillColor;T.fill();if(U.strokeWidth){T.strokeStyle=U.strokeColor;T.lineWidth=U.strokeWidth;T.stroke()}T.restore()}}}function A(){var P=10;function S(W){var U=[];for(var X=0;X<W.length;X++){var T={},Y=W[X];switch(Y.type){case F.MOVETO:case F.LINE:case F.BEZIER:for(var V in Y){T[V]=(typeof Y[V]=="number")?Math.round(Y[V]*P):Y[V]}U.push(T);break;default:U.push(Y)}}return U}if(!document.namespaces.v){document.namespaces.add("v","urn:schemas-microsoft-com:vml");var R=document.createStyleSheet();R.cssText="v\\:* {behavior:url(#default#VML);display:inline-block;}"}function Q(W){var T;if(W.className.indexOf("ictinus-init")!=-1){if(W.nodeName=="IMG"&&M(W.previousSibling,"ictinus")){T=W.previousSibling}else{if(W.getElementsByTagName("div").length){var V=W.getElementsByTagName("div");for(var U=0;U<V.length;U++){if(M(V[U],"ictinus")){T=V[U];break}}}}}if(!T){T=document.createElement("div");T.style.width=W.offsetWidth+"px";T.style.height=W.offsetHeight+"px";T.className="ictinus";if(W.tagName=="IMG"){W.parentNode.insertBefore(T,W)}else{W.appendChild(T)}W.className=(W.className?W.className+" ":"")+"ictinus-init"}return T}return{decorate:function(a,b){var T=S(b.getPaths());var U=[];for(var Z=0;Z<T.length;Z++){var V=T[Z];switch(V.type){case F.MOVETO:U.push("m "+V.x+","+V.y);break;case F.LINE:U.push("l "+V.x+","+V.y);break;case F.BEZIER:U.push("c "+V.cpx1+","+V.cpy1+", "+V.cpx2+","+V.cpy2+", "+V.x+","+V.y);break}}U.push("x e");var X;var c;var W=false;if(W){X=b._cache.shape_elem;c=b._cache.fill_elem}else{X=document.createElement("v:shape");var Y=Q(a);c=document.createElement("v:fill");c.type="tile";X.appendChild(c);b._cache.shape_elem=X;b._cache.fill_elem=c}X.strokeweight=b.strokeWidth;X.strokecolor=b.strokeColor;if(!b.strokeWidth){X.stroked=false}X.style.width=a.offsetWidth+"px";X.style.height=a.offsetHeight+"px";X.coordsize=(a.offsetWidth*P)+" "+(a.offsetHeight*P);X.path=U.join(" ");if(!W){Y.appendChild(X)}c.origin=(X.offsetLeft/a.offsetWidth)+" "+(X.offsetTop/a.offsetHeight);c.src=a.src;return X},draw:function(){}}}var C=O?A():H();return{decorate:function(R,Q,P){if(!(Q instanceof IctinusShape)){var S=Q;P=D(P);Q=ictinus.shape();Q.addPath.apply(Q,S);Q.strokeColor=P.line_color;Q.strokeWidth=P.line_width}return C.decorate(R,Q)},draw:function(P,Q){C.draw(P,Q)},draw_type:{move:J,close:function(){return K(F.CLOSE)},line:G,bezier:I,quadratic:L},DRAW_TYPE:F,shape:function(P){return new IctinusShape(C,P)}}})();var planning={shape:0,planselected:0,init:function(){planning.shape=ictinus.shape();planning.shape.strokeWidth=0;if($("#planmate").size()){planning.initplan()}if($("#floors").size()){var A=$("#floors a");A.each(function(B){$(this).click(function(){planning.changeFloor(this,B+1);planning.flats();return false})});if(A[0]){planning.changeFloor(A[0],1)}}planning.flats();$("#planmap a").each(function(B){$(this).click(function(){planning.changePlan(this,B+1);planning.flats();return false})})},initplan:function(){var B=$("#planmate");var C=$("#planselected");var A=$("#planmap area");A.each(function(){var F=this.coords.replace(/\s/g,"").split(",");var G=[];for(var D=0;D<F.length;D+=2){if(!D){G.push(ictinus.draw_type.move(parseInt(F[D]),parseInt(F[D+1])))}else{G.push(ictinus.draw_type.line(parseInt(F[D]),parseInt(F[D+1])))}}this.ictinushover=planning.shape.decorate(B[0],G);this.ictinusselected=planning.shape.decorate(C[0],G);var E=this;if(E.className.indexOf("selected")!=-1){this.ictinusselected.style.visibility="visible";this.ictinushover.style.visibility="hidden";planning.planselected=E}});A.mouseover(function(){if(planning.planselected!=this){this.ictinushover.style.visibility="visible"}}).mouseout(function(){if(planning.planselected!=this){this.ictinushover.style.visibility="hidden"}});A.each(function(D){$(this).click(function(){planning.planselected.ictinusselected.style.visibility="hidden";planning.planselected.ictinushover.style.visibility="hidden";planning.planselected=this;this.ictinusselected.style.visibility="visible";planning.changePlan(this,D+1);planning.flats();return false})})},flats:function(){var A=$("#plans div");A.each(function(){if(this.id.indexOf("flatsplan")==-1||this.parentNode.className.indexOf("selected")==-1){return }var C=$(this).find("img.mate");var B=$(this).find("area");B.each(function(){var G=this.coords.replace(/\s/g,"").split(",");var H=[];for(var D=0;D<G.length;D+=2){if(!D){H.push(ictinus.draw_type.move(parseInt(G[D]),parseInt(G[D+1])))}else{H.push(ictinus.draw_type.line(parseInt(G[D]),parseInt(G[D+1])))}}this.ictinus=planning.shape.decorate(C[0],H);var F=this;for(D=1;D<20;D++){var E=$("#"+this.className+"-"+D);E.mouseover(function(){F.ictinus.style.visibility="visible"});if(!E.size()){break}}});B.mouseover(function(){this.ictinus.style.visibility="visible"}).mouseout(function(){this.ictinus.style.visibility="hidden"})})},changePlan:function(B,A){$("#plans > div").attr("class","");if(!planning.planselected){$("#planmap > div").attr("class","");B.parentNode.className="selected"}$("#planshow"+A).addClass("selected");return false},changeFloor:function(A,B){$("#floors > div").attr("class","");A.parentNode.className="selected";$("#planmap > div").each(function(C){if(C>=(B-1)*3&&C<=(B*3-1)){this.style.display="block"}else{this.style.display="none"}})}};my.onload.push(planning.init);