/**
* Joint 0.4 - JavaScript diagramming library.
* Copyright (c) David Durman 2009 - 2011
* Licensed under the MIT license: (http://www.opensource.org/licenses/mit-license.php)
*/(function(m){var g=m.Joint;g.Mixin(g.prototype,{compact:function(){var b=this.startObject(),a=this.endObject(),c=this._registeredObjects,d=c.length,e={object:"joint",euid:this.euid(),opt:this._opt,from:undefined,to:undefined,registered:{start:[],end:[],both:[]}};if(b.wholeShape)e.from=b.wholeShape.euid();if(a.wholeShape)e.to=a.wholeShape.euid();if(this.isStartDummy())e.from=b.attrs.cx+"@"+b.attrs.cy;if(this.isEndDummy())e.to=a.attrs.cx+"@"+a.attrs.cy;for(;d--;){b=c[d];e.registered[b._capToStick|| "both"].push(b.euid())}return e},stringify:function(){return JSON.stringify(this.compact())}});g.Mixin(g.dia,{clone:function(){return this.parse(this.stringify(g.paper()))},parse:function(b){b=JSON.parse(b);var a,c,d,e=[],f,j,i={},h=[];b instanceof Array||(b=[b]);f=0;for(j=b.length;f<j;f++){a=b[f];c=a.module;d=a.object;if(d==="joint"){e.push(a);h.push(a)}else{if(this[c])if(this[c][d])c=this[c][d].create(a);else{console.error("Object "+d+" of module "+c+" is missing.");return}else{console.error("Module "+ c+" is missing.");return}if(a.euid)i[a.euid]=c;c.translate(a.dx,a.dy);c.scale(a.sx,a.sy);h.push(c)}}this.hierarchize(i);this.createJoints(e,i);return h},hierarchize:function(b){var a,c;for(a in b)if(b.hasOwnProperty(a)){c=b[a];c.properties.parent&&b[c.properties.parent]&&b[c.properties.parent].addInner(c)}},createJoints:function(b,a){for(var c=b.length,d,e,f,j,i,h,k=["start","end","both"],l=k.length;c--;){d=b[c];e=a[d.from];f=a[d.to];e=e?e.wrapper:{x:d.from.split("@")[0],y:d.from.split("@")[1]};f= f?f.wrapper:{x:d.to.split("@")[0],y:d.to.split("@")[1]};f=this.Joint(e,f,d.opt);e=[];for(l=k.length;l--;){h=k[l];for(i=d.registered[h].length;i--;)if(a[d.registered[h][i]]){j=a[d.registered[h][i]];j._capToStick=h;e.push(j)}}f.registerForever(e)}},stringify:function(b){var a,c,d,e=[];a=this._registeredObjects;var f=this._registeredJoints;b=b.euid();if(a[b]){a=a[b];for(c=a.length;c--;){d=a[c];d.object&&e.push(d.stringify())}}if(f[b]){a=f[b];for(c=a.length;c--;){d=a[c];e.push(d.stringify())}}return"["+ e.join(",")+"]"}});g.Mixin(g.dia.Element.prototype,{stringify:function(){return JSON.stringify(g.Mixin(this.properties,{euid:this.euid()}))},clone:function(){return g.dia.parse(this.stringify())[0]}})})(this);