added ID generation according to RFC 4122
[raphael] / raphael.js
1 /*!
2  * Raphael 1.5.1 - JavaScript Vector Library
3  *
4  * Copyright (c) 2010 Dmitry Baranovskiy (http://raphaeljs.com)
5  * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
6  */
7 (function () {
8     function R() {
9         if (R.is(arguments[0], array)) {
10             var a = arguments[0],
11                 cnv = create[apply](R, a.splice(0, 3 + R.is(a[0], nu))),
12                 res = cnv.set();
13             for (var i = 0, ii = a[length]; i < ii; i++) {
14                 var j = a[i] || {};
15                 elements[has](j.type) && res[push](cnv[j.type]().attr(j));
16             }
17             return res;
18         }
19         return create[apply](R, arguments);
20     }
21     R.version = "1.5.1";
22     var separator = /[, ]+/,
23         elements = {circle: 1, rect: 1, path: 1, ellipse: 1, text: 1, image: 1},
24         formatrg = /\{(\d+)\}/g,
25         proto = "prototype",
26         has = "hasOwnProperty",
27         doc = document,
28         win = window,
29         oldRaphael = {
30             was: Object[proto][has].call(win, "Raphael"),
31             is: win.Raphael
32         },
33         Paper = function () {
34             this.customAttributes = {};
35         },
36         paperproto,
37         appendChild = "appendChild",
38         apply = "apply",
39         concat = "concat",
40         supportsTouch = "createTouch" in doc,
41         E = "",
42         S = " ",
43         Str = String,
44         split = "split",
45         events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend orientationchange touchcancel gesturestart gesturechange gestureend"[split](S),
46         touchMap = {
47             mousedown: "touchstart",
48             mousemove: "touchmove",
49             mouseup: "touchend"
50         },
51         join = "join",
52         length = "length",
53         lowerCase = Str[proto].toLowerCase,
54         math = Math,
55         mmax = math.max,
56         mmin = math.min,
57         abs = math.abs,
58         pow = math.pow,
59         nu = "number",
60         string = "string",
61         array = "array",
62         toString = "toString",
63         fillString = "fill",
64         objectToString = Object[proto][toString],
65         paper = {},
66         push = "push",
67         rg = /^(?=[\da-f]$)/,
68         ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
69         colourRegExp = /^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+(?:\s*,\s*[\d\.]+)?)\s*\)|rgba?\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%(?:\s*,\s*[\d\.]+%)?)\s*\)|hsb\(\s*([\d\.]+(?:deg|\xb0)?\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hsb\(\s*([\d\.]+(?:deg|\xb0|%)\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\)|hsl\(\s*([\d\.]+(?:deg|\xb0)?\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hsl\(\s*([\d\.]+(?:deg|\xb0|%)\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i,
70         isnan = /^(NaN|-?Infinity)$/,
71         bezierrg = /^cubic-bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
72         round = math.round,
73         setAttribute = "setAttribute",
74         toFloat = parseFloat,
75         toInt = parseInt,
76         ms = " progid:DXImageTransform.Microsoft",
77         upperCase = Str[proto].toUpperCase,
78         availableAttrs = {blur: 0, "clip-rect": "0 0 1e9 1e9", cursor: "default", cx: 0, cy: 0, fill: "#fff", "fill-opacity": 1, font: '10px "Arial"', "font-family": '"Arial"', "font-size": "10", "font-style": "normal", "font-weight": 400, gradient: 0, height: 0, href: "http://raphaeljs.com/", opacity: 1, path: "M0,0", r: 0, rotation: 0, rx: 0, ry: 0, scale: "1 1", src: "", stroke: "#000", "stroke-dasharray": "", "stroke-linecap": "butt", "stroke-linejoin": "butt", "stroke-miterlimit": 0, "stroke-opacity": 1, "stroke-width": 1, target: "_blank", "text-anchor": "middle", title: "Raphael", translation: "0 0", width: 0, x: 0, y: 0},
79         availableAnimAttrs = {along: "along", blur: nu, "clip-rect": "csv", cx: nu, cy: nu, fill: "colour", "fill-opacity": nu, "font-size": nu, height: nu, opacity: nu, path: "path", r: nu, rotation: "csv", rx: nu, ry: nu, scale: "csv", stroke: "colour", "stroke-opacity": nu, "stroke-width": nu, translation: "csv", width: nu, x: nu, y: nu},
80         rp = "replace",
81         p2s = /,?([achlmqrstvxz]),?/gi,
82         commaSpaces = /\s*,\s*/,
83         hsrg = {hs: 1, rg: 1},
84         animKeyFrames= /^(from|to|\d+%)$/,
85         pathCommand = /([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig,
86         pathValues = /(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig,
87         sortByKey = function (a, b) {
88             return a.key - b.key;
89         };
90
91     R.type = (win.SVGAngle || doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
92     if (R.type == "VML") {
93         var d = doc.createElement("div"),
94             b;
95         d.innerHTML = '<v:shape adj="1"/>';
96         b = d.firstChild;
97         b.style.behavior = "url(#default#VML)";
98         if (!(b && typeof b.adj == "object")) {
99             return R.type = null;
100         }
101         d = null;
102     }
103     R.svg = !(R.vml = R.type == "VML");
104     Paper[proto] = R[proto];
105     paperproto = Paper[proto];
106     R._id = 0;
107     R._oid = 0;
108     R.fn = {};
109     R.is = function (o, type) {
110         type = lowerCase.call(type);
111         if (type == "finite") {
112             return !isnan.test(+o);
113         }
114         return  (type == "null" && o === null) ||
115                 (type == typeof o) ||
116                 (type == "object" && o === Object(o)) ||
117                 (type == "array" && Array.isArray && Array.isArray(o)) ||
118                 objectToString.call(o).slice(8, -1).toLowerCase() == type;
119     };
120     R.angle = function (x1, y1, x2, y2, x3, y3) {
121         if (x3 == null) {
122             var x = x1 - x2,
123                 y = y1 - y2;
124             if (!x && !y) {
125                 return 0;
126             }
127             return ((x < 0) * 180 + math.atan(-y / -x) * 180 / math.PI + 360) % 360;
128         } else {
129             return R.angle(x1, y1, x3, y3) - R.angle(x2, y2, x3, y3);
130         }
131     };
132     R.snapTo = function (values, value, tolerance) {
133         tolerance = tolerance || 10;
134         values = [][concat](values);
135         var i = values.length;
136         while (i--) if (abs(values[i] - value) <= tolerance) {
137             return values[i];
138         }
139         return value;
140     };
141     function createUUID() {
142         // http://www.ietf.org/rfc/rfc4122.txt
143         var s = [],
144             i = 0;
145         for (; i < 32; i++) {
146             s[i] = (~~(math.random() * 16))[toString](16);
147         }
148         s[12] = 4;  // bits 12-15 of the time_hi_and_version field to 0010
149         s[16] = ((s[16] & 3) | 8)[toString](16);  // bits 6-7 of the clock_seq_hi_and_reserved to 01
150         return "r-" + s[join]("");
151     }
152
153     R.setWindow = function (newwin) {
154         win = newwin;
155         doc = win.document;
156     };
157     // colour utilities
158     var toHex = function (color) {
159         if (R.vml) {
160             // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
161             var trim = /^\s+|\s+$/g;
162             var bod;
163             try {
164                 var docum = new ActiveXObject("htmlfile");
165                 docum.write("<body>");
166                 docum.close();
167                 bod = docum.body;
168             } catch(e) {
169                 bod = createPopup().document.body;
170             }
171             var range = bod.createTextRange();
172             toHex = cacher(function (color) {
173                 try {
174                     bod.style.color = Str(color)[rp](trim, E);
175                     var value = range.queryCommandValue("ForeColor");
176                     value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
177                     return "#" + ("000000" + value[toString](16)).slice(-6);
178                 } catch(e) {
179                     return "none";
180                 }
181             });
182         } else {
183             var i = doc.createElement("i");
184             i.title = "Rapha\xebl Colour Picker";
185             i.style.display = "none";
186             doc.body[appendChild](i);
187             toHex = cacher(function (color) {
188                 i.style.color = color;
189                 return doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
190             });
191         }
192         return toHex(color);
193     },
194     hsbtoString = function () {
195         return "hsb(" + [this.h, this.s, this.b] + ")";
196     },
197     hsltoString = function () {
198         return "hsl(" + [this.h, this.s, this.l] + ")";
199     },
200     rgbtoString = function () {
201         return this.hex;
202     };
203     R.hsb2rgb = function (h, s, b) {
204         if (R.is(h, "object") && "h" in h && "s" in h && "b" in h) {
205             b = h.b;
206             s = h.s;
207             h = h.h;
208         }
209         return R.hsl2rgb(h, s, b / 2);
210     };
211     R.hsl2rgb = function (h, s, l) {
212         if (R.is(h, "object") && "h" in h && "s" in h && "l" in h) {
213             l = h.l;
214             s = h.s;
215             h = h.h;
216         }
217         if (h > 1 || s > 1 || l > 1) {
218             h /= 360;
219             s /= 100;
220             l /= 100;
221         }
222         var rgb = {},
223             channels = ["r", "g", "b"],
224             t2, t1, t3, r, g, b;
225         if (!s) {
226             rgb = {
227                 r: l,
228                 g: l,
229                 b: l
230             };
231         } else {
232             if (l < .5) {
233                 t2 = l * (1 + s);
234             } else {
235                 t2 = l + s - l * s;
236             }
237             t1 = 2 * l - t2;
238             for (var i = 0, ii = channels.length; i < ii; i++) {
239                 t3 = h + 1 / 3 * -(i - 1);
240                 t3 < 0 && t3++;
241                 t3 > 1 && t3--;
242                 if (t3 * 6 < 1) {
243                     rgb[channels[i]] = t1 + (t2 - t1) * 6 * t3;
244                 } else if (t3 * 2 < 1) {
245                     rgb[channels[i]] = t2;
246                 } else if (t3 * 3 < 2) {
247                     rgb[channels[i]] = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
248                 } else {
249                     rgb[channels[i]] = t1;
250                 }
251             }
252         }
253         rgb.r *= 255;
254         rgb.g *= 255;
255         rgb.b *= 255;
256         r = (~~rgb.r)[toString](16);
257         g = (~~rgb.g)[toString](16);
258         b = (~~rgb.b)[toString](16);
259         r = r[rp](rg, "0");
260         g = g[rp](rg, "0");
261         b = b[rp](rg, "0");
262         rgb.hex = "#" + r + g + b;
263         rgb.toString = rgbtoString;
264         return rgb;
265     };
266     R.rgb2hsb = function (red, green, blue) {
267         if (green == null && R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
268             blue = red.b;
269             green = red.g;
270             red = red.r;
271         }
272         if (green == null && R.is(red, string)) {
273             var clr = R.getRGB(red);
274             red = clr.r;
275             green = clr.g;
276             blue = clr.b;
277         }
278         if (red > 1 || green > 1 || blue > 1) {
279             red /= 255;
280             green /= 255;
281             blue /= 255;
282         }
283         var max = mmax(red, green, blue),
284             min = mmin(red, green, blue),
285             hue,
286             saturation,
287             brightness = max;
288         if (min == max) {
289             return {h: 0, s: 0, b: max, toString: hsbtoString};
290         } else {
291             var delta = (max - min);
292             saturation = delta / max;
293             if (red == max) {
294                 hue = (green - blue) / delta;
295             } else if (green == max) {
296                 hue = 2 + ((blue - red) / delta);
297             } else {
298                 hue = 4 + ((red - green) / delta);
299             }
300             hue /= 6;
301             hue < 0 && hue++;
302             hue > 1 && hue--;
303         }
304         return {h: hue, s: saturation, b: brightness, toString: hsbtoString};
305     };
306     R.rgb2hsl = function (red, green, blue) {
307         if (green == null && R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
308             blue = red.b;
309             green = red.g;
310             red = red.r;
311         }
312         if (green == null && R.is(red, string)) {
313             var clr = R.getRGB(red);
314             red = clr.r;
315             green = clr.g;
316             blue = clr.b;
317         }
318         if (red > 1 || green > 1 || blue > 1) {
319             red /= 255;
320             green /= 255;
321             blue /= 255;
322         }
323         var max = mmax(red, green, blue),
324             min = mmin(red, green, blue),
325             h,
326             s,
327             l = (max + min) / 2,
328             hsl;
329         if (min == max) {
330             hsl =  {h: 0, s: 0, l: l};
331         } else {
332             var delta = max - min;
333             s = l < .5 ? delta / (max + min) : delta / (2 - max - min);
334             if (red == max) {
335                 h = (green - blue) / delta;
336             } else if (green == max) {
337                 h = 2 + (blue - red) / delta;
338             } else {
339                 h = 4 + (red - green) / delta;
340             }
341             h /= 6;
342             h < 0 && h++;
343             h > 1 && h--;
344             hsl = {h: h, s: s, l: l};
345         }
346         hsl.toString = hsltoString;
347         return hsl;
348     };
349     R._path2string = function () {
350         return this.join(",")[rp](p2s, "$1");
351     };
352     function cacher(f, scope, postprocessor) {
353         function newf() {
354             var arg = Array[proto].slice.call(arguments, 0),
355                 args = arg[join]("\u25ba"),
356                 cache = newf.cache = newf.cache || {},
357                 count = newf.count = newf.count || [];
358             if (cache[has](args)) {
359                 return postprocessor ? postprocessor(cache[args]) : cache[args];
360             }
361             count[length] >= 1e3 && delete cache[count.shift()];
362             count[push](args);
363             cache[args] = f[apply](scope, arg);
364             return postprocessor ? postprocessor(cache[args]) : cache[args];
365         }
366         return newf;
367     }
368  
369     R.getRGB = cacher(function (colour) {
370         if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) {
371             return {r: -1, g: -1, b: -1, hex: "none", error: 1};
372         }
373         if (colour == "none") {
374             return {r: -1, g: -1, b: -1, hex: "none"};
375         }
376         !(hsrg[has](colour.substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
377         var res,
378             red,
379             green,
380             blue,
381             opacity,
382             t,
383             rgb = colour.match(colourRegExp);
384         if (rgb) {
385             if (rgb[2]) {
386                 blue = toInt(rgb[2].substring(5), 16);
387                 green = toInt(rgb[2].substring(3, 5), 16);
388                 red = toInt(rgb[2].substring(1, 3), 16);
389             }
390             if (rgb[3]) {
391                 blue = toInt((t = rgb[3].charAt(3)) + t, 16);
392                 green = toInt((t = rgb[3].charAt(2)) + t, 16);
393                 red = toInt((t = rgb[3].charAt(1)) + t, 16);
394             }
395             if (rgb[4]) {
396                 rgb = rgb[4][split](commaSpaces);
397                 red = toFloat(rgb[0]);
398                 green = toFloat(rgb[1]);
399                 blue = toFloat(rgb[2]);
400                 opacity = toFloat(rgb[3]);
401             }
402             if (rgb[5]) {
403                 rgb = rgb[5][split](commaSpaces);
404                 red = toFloat(rgb[0]) * 2.55;
405                 green = toFloat(rgb[1]) * 2.55;
406                 blue = toFloat(rgb[2]) * 2.55;
407                 opacity = toFloat(rgb[3]);
408             }
409             if (rgb[6]) {
410                 rgb = rgb[6][split](commaSpaces);
411                 red = toFloat(rgb[0]);
412                 green = toFloat(rgb[1]);
413                 blue = toFloat(rgb[2]);
414                 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360);
415                 return R.hsb2rgb(red, green, blue);
416             }
417             if (rgb[7]) {
418                 rgb = rgb[7][split](commaSpaces);
419                 red = toFloat(rgb[0]) * 2.55;
420                 green = toFloat(rgb[1]) * 2.55;
421                 blue = toFloat(rgb[2]) * 2.55;
422                 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360 * 2.55);
423                 return R.hsb2rgb(red, green, blue);
424             }
425             if (rgb[8]) {
426                 rgb = rgb[8][split](commaSpaces);
427                 red = toFloat(rgb[0]);
428                 green = toFloat(rgb[1]);
429                 blue = toFloat(rgb[2]);
430                 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360);
431                 return R.hsl2rgb(red, green, blue);
432             }
433             if (rgb[9]) {
434                 rgb = rgb[9][split](commaSpaces);
435                 red = toFloat(rgb[0]) * 2.55;
436                 green = toFloat(rgb[1]) * 2.55;
437                 blue = toFloat(rgb[2]) * 2.55;
438                 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360 * 2.55);
439                 return R.hsl2rgb(red, green, blue);
440             }
441             rgb = {r: red, g: green, b: blue};
442             var r = (~~red)[toString](16),
443                 g = (~~green)[toString](16),
444                 b = (~~blue)[toString](16);
445             r = r[rp](rg, "0");
446             g = g[rp](rg, "0");
447             b = b[rp](rg, "0");
448             rgb.hex = "#" + r + g + b;
449             isFinite(toFloat(opacity)) && (rgb.o = opacity);
450             return rgb;
451         }
452         return {r: -1, g: -1, b: -1, hex: "none", error: 1};
453     }, R);
454     R.getColor = function (value) {
455         var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
456             rgb = this.hsb2rgb(start.h, start.s, start.b);
457         start.h += .075;
458         if (start.h > 1) {
459             start.h = 0;
460             start.s -= .2;
461             start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
462         }
463         return rgb.hex;
464     };
465     R.getColor.reset = function () {
466         delete this.start;
467     };
468     // path utilities
469     R.parsePathString = cacher(function (pathString) {
470         if (!pathString) {
471             return null;
472         }
473         var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
474             data = [];
475         if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
476             data = pathClone(pathString);
477         }
478         if (!data[length]) {
479             Str(pathString)[rp](pathCommand, function (a, b, c) {
480                 var params = [],
481                     name = lowerCase.call(b);
482                 c[rp](pathValues, function (a, b) {
483                     b && params[push](+b);
484                 });
485                 if (name == "m" && params[length] > 2) {
486                     data[push]([b][concat](params.splice(0, 2)));
487                     name = "l";
488                     b = b == "m" ? "l" : "L";
489                 }
490                 while (params[length] >= paramCounts[name]) {
491                     data[push]([b][concat](params.splice(0, paramCounts[name])));
492                     if (!paramCounts[name]) {
493                         break;
494                     }
495                 }
496             });
497         }
498         data[toString] = R._path2string;
499         return data;
500     });
501     R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
502         var t1 = 1 - t,
503             x = pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
504             y = pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y,
505             mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x),
506             my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y),
507             nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x),
508             ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y),
509             ax = (1 - t) * p1x + t * c1x,
510             ay = (1 - t) * p1y + t * c1y,
511             cx = (1 - t) * c2x + t * p2x,
512             cy = (1 - t) * c2y + t * p2y,
513             alpha = (90 - math.atan((mx - nx) / (my - ny)) * 180 / math.PI);
514         (mx > nx || my < ny) && (alpha += 180);
515         return {x: x, y: y, m: {x: mx, y: my}, n: {x: nx, y: ny}, start: {x: ax, y: ay}, end: {x: cx, y: cy}, alpha: alpha};
516     };
517     var pathDimensions = cacher(function (path) {
518         if (!path) {
519             return {x: 0, y: 0, width: 0, height: 0};
520         }
521         path = path2curve(path);
522         var x = 0, 
523             y = 0,
524             X = [],
525             Y = [],
526             p;
527         for (var i = 0, ii = path[length]; i < ii; i++) {
528             p = path[i];
529             if (p[0] == "M") {
530                 x = p[1];
531                 y = p[2];
532                 X[push](x);
533                 Y[push](y);
534             } else {
535                 var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
536                 X = X[concat](dim.min.x, dim.max.x);
537                 Y = Y[concat](dim.min.y, dim.max.y);
538                 x = p[5];
539                 y = p[6];
540             }
541         }
542         var xmin = mmin[apply](0, X),
543             ymin = mmin[apply](0, Y);
544         return {
545             x: xmin,
546             y: ymin,
547             width: mmax[apply](0, X) - xmin,
548             height: mmax[apply](0, Y) - ymin
549         };
550     }),
551         pathClone = function (pathArray) {
552             var res = [];
553             if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
554                 pathArray = R.parsePathString(pathArray);
555             }
556             for (var i = 0, ii = pathArray[length]; i < ii; i++) {
557                 res[i] = [];
558                 for (var j = 0, jj = pathArray[i][length]; j < jj; j++) {
559                     res[i][j] = pathArray[i][j];
560                 }
561             }
562             res[toString] = R._path2string;
563             return res;
564         },
565         pathToRelative = cacher(function (pathArray) {
566             if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
567                 pathArray = R.parsePathString(pathArray);
568             }
569             var res = [],
570                 x = 0,
571                 y = 0,
572                 mx = 0,
573                 my = 0,
574                 start = 0;
575             if (pathArray[0][0] == "M") {
576                 x = pathArray[0][1];
577                 y = pathArray[0][2];
578                 mx = x;
579                 my = y;
580                 start++;
581                 res[push](["M", x, y]);
582             }
583             for (var i = start, ii = pathArray[length]; i < ii; i++) {
584                 var r = res[i] = [],
585                     pa = pathArray[i];
586                 if (pa[0] != lowerCase.call(pa[0])) {
587                     r[0] = lowerCase.call(pa[0]);
588                     switch (r[0]) {
589                         case "a":
590                             r[1] = pa[1];
591                             r[2] = pa[2];
592                             r[3] = pa[3];
593                             r[4] = pa[4];
594                             r[5] = pa[5];
595                             r[6] = +(pa[6] - x).toFixed(3);
596                             r[7] = +(pa[7] - y).toFixed(3);
597                             break;
598                         case "v":
599                             r[1] = +(pa[1] - y).toFixed(3);
600                             break;
601                         case "m":
602                             mx = pa[1];
603                             my = pa[2];
604                         default:
605                             for (var j = 1, jj = pa[length]; j < jj; j++) {
606                                 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
607                             }
608                     }
609                 } else {
610                     r = res[i] = [];
611                     if (pa[0] == "m") {
612                         mx = pa[1] + x;
613                         my = pa[2] + y;
614                     }
615                     for (var k = 0, kk = pa[length]; k < kk; k++) {
616                         res[i][k] = pa[k];
617                     }
618                 }
619                 var len = res[i][length];
620                 switch (res[i][0]) {
621                     case "z":
622                         x = mx;
623                         y = my;
624                         break;
625                     case "h":
626                         x += +res[i][len - 1];
627                         break;
628                     case "v":
629                         y += +res[i][len - 1];
630                         break;
631                     default:
632                         x += +res[i][len - 2];
633                         y += +res[i][len - 1];
634                 }
635             }
636             res[toString] = R._path2string;
637             return res;
638         }, 0, pathClone),
639         pathToAbsolute = cacher(function (pathArray) {
640             if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
641                 pathArray = R.parsePathString(pathArray);
642             }
643             var res = [],
644                 x = 0,
645                 y = 0,
646                 mx = 0,
647                 my = 0,
648                 start = 0;
649             if (pathArray[0][0] == "M") {
650                 x = +pathArray[0][1];
651                 y = +pathArray[0][2];
652                 mx = x;
653                 my = y;
654                 start++;
655                 res[0] = ["M", x, y];
656             }
657             for (var i = start, ii = pathArray[length]; i < ii; i++) {
658                 var r = res[i] = [],
659                     pa = pathArray[i];
660                 if (pa[0] != upperCase.call(pa[0])) {
661                     r[0] = upperCase.call(pa[0]);
662                     switch (r[0]) {
663                         case "A":
664                             r[1] = pa[1];
665                             r[2] = pa[2];
666                             r[3] = pa[3];
667                             r[4] = pa[4];
668                             r[5] = pa[5];
669                             r[6] = +(pa[6] + x);
670                             r[7] = +(pa[7] + y);
671                             break;
672                         case "V":
673                             r[1] = +pa[1] + y;
674                             break;
675                         case "H":
676                             r[1] = +pa[1] + x;
677                             break;
678                         case "M":
679                             mx = +pa[1] + x;
680                             my = +pa[2] + y;
681                         default:
682                             for (var j = 1, jj = pa[length]; j < jj; j++) {
683                                 r[j] = +pa[j] + ((j % 2) ? x : y);
684                             }
685                     }
686                 } else {
687                     for (var k = 0, kk = pa[length]; k < kk; k++) {
688                         res[i][k] = pa[k];
689                     }
690                 }
691                 switch (r[0]) {
692                     case "Z":
693                         x = mx;
694                         y = my;
695                         break;
696                     case "H":
697                         x = r[1];
698                         break;
699                     case "V":
700                         y = r[1];
701                         break;
702                     case "M":
703                         mx = res[i][res[i][length] - 2];
704                         my = res[i][res[i][length] - 1];
705                     default:
706                         x = res[i][res[i][length] - 2];
707                         y = res[i][res[i][length] - 1];
708                 }
709             }
710             res[toString] = R._path2string;
711             return res;
712         }, null, pathClone),
713         l2c = function (x1, y1, x2, y2) {
714             return [x1, y1, x2, y2, x2, y2];
715         },
716         q2c = function (x1, y1, ax, ay, x2, y2) {
717             var _13 = 1 / 3,
718                 _23 = 2 / 3;
719             return [
720                     _13 * x1 + _23 * ax,
721                     _13 * y1 + _23 * ay,
722                     _13 * x2 + _23 * ax,
723                     _13 * y2 + _23 * ay,
724                     x2,
725                     y2
726                 ];
727         },
728         a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
729             // for more information of where this math came from visit:
730             // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
731             var PI = math.PI,
732                 _120 = PI * 120 / 180,
733                 rad = PI / 180 * (+angle || 0),
734                 res = [],
735                 xy,
736                 rotate = cacher(function (x, y, rad) {
737                     var X = x * math.cos(rad) - y * math.sin(rad),
738                         Y = x * math.sin(rad) + y * math.cos(rad);
739                     return {x: X, y: Y};
740                 });
741             if (!recursive) {
742                 xy = rotate(x1, y1, -rad);
743                 x1 = xy.x;
744                 y1 = xy.y;
745                 xy = rotate(x2, y2, -rad);
746                 x2 = xy.x;
747                 y2 = xy.y;
748                 var cos = math.cos(PI / 180 * angle),
749                     sin = math.sin(PI / 180 * angle),
750                     x = (x1 - x2) / 2,
751                     y = (y1 - y2) / 2;
752                 var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
753                 if (h > 1) {
754                     h = math.sqrt(h);
755                     rx = h * rx;
756                     ry = h * ry;
757                 }
758                 var rx2 = rx * rx,
759                     ry2 = ry * ry,
760                     k = (large_arc_flag == sweep_flag ? -1 : 1) *
761                         math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
762                     cx = k * rx * y / ry + (x1 + x2) / 2,
763                     cy = k * -ry * x / rx + (y1 + y2) / 2,
764                     f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
765                     f2 = math.asin(((y2 - cy) / ry).toFixed(9));
766
767                 f1 = x1 < cx ? PI - f1 : f1;
768                 f2 = x2 < cx ? PI - f2 : f2;
769                 f1 < 0 && (f1 = PI * 2 + f1);
770                 f2 < 0 && (f2 = PI * 2 + f2);
771                 if (sweep_flag && f1 > f2) {
772                     f1 = f1 - PI * 2;
773                 }
774                 if (!sweep_flag && f2 > f1) {
775                     f2 = f2 - PI * 2;
776                 }
777             } else {
778                 f1 = recursive[0];
779                 f2 = recursive[1];
780                 cx = recursive[2];
781                 cy = recursive[3];
782             }
783             var df = f2 - f1;
784             if (abs(df) > _120) {
785                 var f2old = f2,
786                     x2old = x2,
787                     y2old = y2;
788                 f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
789                 x2 = cx + rx * math.cos(f2);
790                 y2 = cy + ry * math.sin(f2);
791                 res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
792             }
793             df = f2 - f1;
794             var c1 = math.cos(f1),
795                 s1 = math.sin(f1),
796                 c2 = math.cos(f2),
797                 s2 = math.sin(f2),
798                 t = math.tan(df / 4),
799                 hx = 4 / 3 * rx * t,
800                 hy = 4 / 3 * ry * t,
801                 m1 = [x1, y1],
802                 m2 = [x1 + hx * s1, y1 - hy * c1],
803                 m3 = [x2 + hx * s2, y2 - hy * c2],
804                 m4 = [x2, y2];
805             m2[0] = 2 * m1[0] - m2[0];
806             m2[1] = 2 * m1[1] - m2[1];
807             if (recursive) {
808                 return [m2, m3, m4][concat](res);
809             } else {
810                 res = [m2, m3, m4][concat](res)[join]()[split](",");
811                 var newres = [];
812                 for (var i = 0, ii = res[length]; i < ii; i++) {
813                     newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
814                 }
815                 return newres;
816             }
817         },
818         findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
819             var t1 = 1 - t;
820             return {
821                 x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
822                 y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
823             };
824         },
825         curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
826             var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
827                 b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
828                 c = p1x - c1x,
829                 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
830                 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
831                 y = [p1y, p2y],
832                 x = [p1x, p2x],
833                 dot;
834             abs(t1) > "1e12" && (t1 = .5);
835             abs(t2) > "1e12" && (t2 = .5);
836             if (t1 > 0 && t1 < 1) {
837                 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
838                 x[push](dot.x);
839                 y[push](dot.y);
840             }
841             if (t2 > 0 && t2 < 1) {
842                 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
843                 x[push](dot.x);
844                 y[push](dot.y);
845             }
846             a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
847             b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
848             c = p1y - c1y;
849             t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
850             t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
851             abs(t1) > "1e12" && (t1 = .5);
852             abs(t2) > "1e12" && (t2 = .5);
853             if (t1 > 0 && t1 < 1) {
854                 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
855                 x[push](dot.x);
856                 y[push](dot.y);
857             }
858             if (t2 > 0 && t2 < 1) {
859                 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
860                 x[push](dot.x);
861                 y[push](dot.y);
862             }
863             return {
864                 min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
865                 max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
866             };
867         }),
868         path2curve = cacher(function (path, path2) {
869             var p = pathToAbsolute(path),
870                 p2 = path2 && pathToAbsolute(path2),
871                 attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
872                 attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
873                 processPath = function (path, d) {
874                     var nx, ny;
875                     if (!path) {
876                         return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
877                     }
878                     !(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null);
879                     switch (path[0]) {
880                         case "M":
881                             d.X = path[1];
882                             d.Y = path[2];
883                             break;
884                         case "A":
885                             path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
886                             break;
887                         case "S":
888                             nx = d.x + (d.x - (d.bx || d.x));
889                             ny = d.y + (d.y - (d.by || d.y));
890                             path = ["C", nx, ny][concat](path.slice(1));
891                             break;
892                         case "T":
893                             d.qx = d.x + (d.x - (d.qx || d.x));
894                             d.qy = d.y + (d.y - (d.qy || d.y));
895                             path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
896                             break;
897                         case "Q":
898                             d.qx = path[1];
899                             d.qy = path[2];
900                             path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
901                             break;
902                         case "L":
903                             path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
904                             break;
905                         case "H":
906                             path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
907                             break;
908                         case "V":
909                             path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
910                             break;
911                         case "Z":
912                             path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
913                             break;
914                     }
915                     return path;
916                 },
917                 fixArc = function (pp, i) {
918                     if (pp[i][length] > 7) {
919                         pp[i].shift();
920                         var pi = pp[i];
921                         while (pi[length]) {
922                             pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
923                         }
924                         pp.splice(i, 1);
925                         ii = mmax(p[length], p2 && p2[length] || 0);
926                     }
927                 },
928                 fixM = function (path1, path2, a1, a2, i) {
929                     if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
930                         path2.splice(i, 0, ["M", a2.x, a2.y]);
931                         a1.bx = 0;
932                         a1.by = 0;
933                         a1.x = path1[i][1];
934                         a1.y = path1[i][2];
935                         ii = mmax(p[length], p2 && p2[length] || 0);
936                     }
937                 };
938             for (var i = 0, ii = mmax(p[length], p2 && p2[length] || 0); i < ii; i++) {
939                 p[i] = processPath(p[i], attrs);
940                 fixArc(p, i);
941                 p2 && (p2[i] = processPath(p2[i], attrs2));
942                 p2 && fixArc(p2, i);
943                 fixM(p, p2, attrs, attrs2, i);
944                 fixM(p2, p, attrs2, attrs, i);
945                 var seg = p[i],
946                     seg2 = p2 && p2[i],
947                     seglen = seg[length],
948                     seg2len = p2 && seg2[length];
949                 attrs.x = seg[seglen - 2];
950                 attrs.y = seg[seglen - 1];
951                 attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
952                 attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
953                 attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
954                 attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
955                 attrs2.x = p2 && seg2[seg2len - 2];
956                 attrs2.y = p2 && seg2[seg2len - 1];
957             }
958             return p2 ? [p, p2] : p;
959         }, null, pathClone),
960         parseDots = cacher(function (gradient) {
961             var dots = [];
962             for (var i = 0, ii = gradient[length]; i < ii; i++) {
963                 var dot = {},
964                     par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
965                 dot.color = R.getRGB(par[1]);
966                 if (dot.color.error) {
967                     return null;
968                 }
969                 dot.color = dot.color.hex;
970                 par[2] && (dot.offset = par[2] + "%");
971                 dots[push](dot);
972             }
973             for (i = 1, ii = dots[length] - 1; i < ii; i++) {
974                 if (!dots[i].offset) {
975                     var start = toFloat(dots[i - 1].offset || 0),
976                         end = 0;
977                     for (var j = i + 1; j < ii; j++) {
978                         if (dots[j].offset) {
979                             end = dots[j].offset;
980                             break;
981                         }
982                     }
983                     if (!end) {
984                         end = 100;
985                         j = ii;
986                     }
987                     end = toFloat(end);
988                     var d = (end - start) / (j - i + 1);
989                     for (; i < j; i++) {
990                         start += d;
991                         dots[i].offset = start + "%";
992                     }
993                 }
994             }
995             return dots;
996         }),
997         getContainer = function (x, y, w, h) {
998             var container;
999             if (R.is(x, string) || R.is(x, "object")) {
1000                 container = R.is(x, string) ? doc.getElementById(x) : x;
1001                 if (container.tagName) {
1002                     if (y == null) {
1003                         return {
1004                             container: container,
1005                             width: container.style.pixelWidth || container.offsetWidth,
1006                             height: container.style.pixelHeight || container.offsetHeight
1007                         };
1008                     } else {
1009                         return {container: container, width: y, height: w};
1010                     }
1011                 }
1012             } else {
1013                 return {container: 1, x: x, y: y, width: w, height: h};
1014             }
1015         },
1016         plugins = function (con, add) {
1017             var that = this;
1018             for (var prop in add) {
1019                 if (add[has](prop) && !(prop in con)) {
1020                     switch (typeof add[prop]) {
1021                         case "function":
1022                             (function (f) {
1023                                 con[prop] = con === that ? f : function () { return f[apply](that, arguments); };
1024                             })(add[prop]);
1025                         break;
1026                         case "object":
1027                             con[prop] = con[prop] || {};
1028                             plugins.call(this, con[prop], add[prop]);
1029                         break;
1030                         default:
1031                             con[prop] = add[prop];
1032                         break;
1033                     }
1034                 }
1035             }
1036         },
1037         tear = function (el, paper) {
1038             el == paper.top && (paper.top = el.prev);
1039             el == paper.bottom && (paper.bottom = el.next);
1040             el.next && (el.next.prev = el.prev);
1041             el.prev && (el.prev.next = el.next);
1042         },
1043         tofront = function (el, paper) {
1044             if (paper.top === el) {
1045                 return;
1046             }
1047             tear(el, paper);
1048             el.next = null;
1049             el.prev = paper.top;
1050             paper.top.next = el;
1051             paper.top = el;
1052         },
1053         toback = function (el, paper) {
1054             if (paper.bottom === el) {
1055                 return;
1056             }
1057             tear(el, paper);
1058             el.next = paper.bottom;
1059             el.prev = null;
1060             paper.bottom.prev = el;
1061             paper.bottom = el;
1062         },
1063         insertafter = function (el, el2, paper) {
1064             tear(el, paper);
1065             el2 == paper.top && (paper.top = el);
1066             el2.next && (el2.next.prev = el);
1067             el.next = el2.next;
1068             el.prev = el2;
1069             el2.next = el;
1070         },
1071         insertbefore = function (el, el2, paper) {
1072             tear(el, paper);
1073             el2 == paper.bottom && (paper.bottom = el);
1074             el2.prev && (el2.prev.next = el);
1075             el.prev = el2.prev;
1076             el2.prev = el;
1077             el.next = el2;
1078         },
1079         removed = function (methodname) {
1080             return function () {
1081                 throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object");
1082             };
1083         },
1084         radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/;
1085     R.pathToRelative = pathToRelative;
1086     // SVG
1087     if (R.svg) {
1088         paperproto.svgns = "http://www.w3.org/2000/svg";
1089         paperproto.xlink = "http://www.w3.org/1999/xlink";
1090         round = function (num) {
1091             return +num + (~~num === num) * .5;
1092         };
1093         var $ = function (el, attr) {
1094             if (attr) {
1095                 for (var key in attr) {
1096                     if (attr[has](key)) {
1097                         el[setAttribute](key, Str(attr[key]));
1098                     }
1099                 }
1100             } else {
1101                 el = doc.createElementNS(paperproto.svgns, el);
1102                 el.style.webkitTapHighlightColor = "rgba(0,0,0,0)";
1103                 return el;
1104             }
1105         };
1106         R[toString] = function () {
1107             return  "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
1108         };
1109         var thePath = function (pathString, SVG) {
1110             var el = $("path");
1111             SVG.canvas && SVG.canvas[appendChild](el);
1112             var p = new Element(el, SVG);
1113             p.type = "path";
1114             setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString});
1115             return p;
1116         };
1117         var addGradientFill = function (o, gradient, SVG) {
1118             var type = "linear",
1119                 fx = .5, fy = .5,
1120                 s = o.style;
1121             gradient = Str(gradient)[rp](radial_gradient, function (all, _fx, _fy) {
1122                 type = "radial";
1123                 if (_fx && _fy) {
1124                     fx = toFloat(_fx);
1125                     fy = toFloat(_fy);
1126                     var dir = ((fy > .5) * 2 - 1);
1127                     pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
1128                         (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
1129                         fy != .5 &&
1130                         (fy = fy.toFixed(5) - 1e-5 * dir);
1131                 }
1132                 return E;
1133             });
1134             gradient = gradient[split](/\s*\-\s*/);
1135             if (type == "linear") {
1136                 var angle = gradient.shift();
1137                 angle = -toFloat(angle);
1138                 if (isNaN(angle)) {
1139                     return null;
1140                 }
1141                 var vector = [0, 0, math.cos(angle * math.PI / 180), math.sin(angle * math.PI / 180)],
1142                     max = 1 / (mmax(abs(vector[2]), abs(vector[3])) || 1);
1143                 vector[2] *= max;
1144                 vector[3] *= max;
1145                 if (vector[2] < 0) {
1146                     vector[0] = -vector[2];
1147                     vector[2] = 0;
1148                 }
1149                 if (vector[3] < 0) {
1150                     vector[1] = -vector[3];
1151                     vector[3] = 0;
1152                 }
1153             }
1154             var dots = parseDots(gradient);
1155             if (!dots) {
1156                 return null;
1157             }
1158             var id = o.getAttribute(fillString);
1159             id = id.match(/^url\(#(.*)\)$/);
1160             id && SVG.defs.removeChild(doc.getElementById(id[1]));
1161
1162             var el = $(type + "Gradient");
1163             el.id = createUUID();
1164             $(el, type == "radial" ? {fx: fx, fy: fy} : {x1: vector[0], y1: vector[1], x2: vector[2], y2: vector[3]});
1165             SVG.defs[appendChild](el);
1166             for (var i = 0, ii = dots[length]; i < ii; i++) {
1167                 var stop = $("stop");
1168                 $(stop, {
1169                     offset: dots[i].offset ? dots[i].offset : !i ? "0%" : "100%",
1170                     "stop-color": dots[i].color || "#fff"
1171                 });
1172                 el[appendChild](stop);
1173             }
1174             $(o, {
1175                 fill: "url(#" + el.id + ")",
1176                 opacity: 1,
1177                 "fill-opacity": 1
1178             });
1179             s.fill = E;
1180             s.opacity = 1;
1181             s.fillOpacity = 1;
1182             return 1;
1183         };
1184         var updatePosition = function (o) {
1185             var bbox = o.getBBox();
1186             $(o.pattern, {patternTransform: R.format("translate({0},{1})", bbox.x, bbox.y)});
1187         };
1188         var setFillAndStroke = function (o, params) {
1189             var dasharray = {
1190                     "": [0],
1191                     "none": [0],
1192                     "-": [3, 1],
1193                     ".": [1, 1],
1194                     "-.": [3, 1, 1, 1],
1195                     "-..": [3, 1, 1, 1, 1, 1],
1196                     ". ": [1, 3],
1197                     "- ": [4, 3],
1198                     "--": [8, 3],
1199                     "- .": [4, 3, 1, 3],
1200                     "--.": [8, 3, 1, 3],
1201                     "--..": [8, 3, 1, 3, 1, 3]
1202                 },
1203                 node = o.node,
1204                 attrs = o.attrs,
1205                 rot = o.rotate(),
1206                 addDashes = function (o, value) {
1207                     value = dasharray[lowerCase.call(value)];
1208                     if (value) {
1209                         var width = o.attrs["stroke-width"] || "1",
1210                             butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
1211                             dashes = [];
1212                         var i = value[length];
1213                         while (i--) {
1214                             dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
1215                         }
1216                         $(node, {"stroke-dasharray": dashes[join](",")});
1217                     }
1218                 };
1219             params[has]("rotation") && (rot = params.rotation);
1220             var rotxy = Str(rot)[split](separator);
1221             if (!(rotxy.length - 1)) {
1222                 rotxy = null;
1223             } else {
1224                 rotxy[1] = +rotxy[1];
1225                 rotxy[2] = +rotxy[2];
1226             }
1227             toFloat(rot) && o.rotate(0, true);
1228             for (var att in params) {
1229                 if (params[has](att)) {
1230                     if (!availableAttrs[has](att)) {
1231                         continue;
1232                     }
1233                     var value = params[att];
1234                     attrs[att] = value;
1235                     switch (att) {
1236                         case "blur":
1237                             o.blur(value);
1238                             break;
1239                         case "rotation":
1240                             o.rotate(value, true);
1241                             break;
1242                         case "href":
1243                         case "title":
1244                         case "target":
1245                             var pn = node.parentNode;
1246                             if (lowerCase.call(pn.tagName) != "a") {
1247                                 var hl = $("a");
1248                                 pn.insertBefore(hl, node);
1249                                 hl[appendChild](node);
1250                                 pn = hl;
1251                             }
1252                             if (att == "target" && value == "blank") {
1253                                 pn.setAttributeNS(o.paper.xlink, "show", "new");
1254                             } else {
1255                                 pn.setAttributeNS(o.paper.xlink, att, value);
1256                             }
1257                             break;
1258                         case "cursor":
1259                             node.style.cursor = value;
1260                             break;
1261                         case "clip-rect":
1262                             var rect = Str(value)[split](separator);
1263                             if (rect[length] == 4) {
1264                                 o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
1265                                 var el = $("clipPath"),
1266                                     rc = $("rect");
1267                                 el.id = createUUID();
1268                                 $(rc, {
1269                                     x: rect[0],
1270                                     y: rect[1],
1271                                     width: rect[2],
1272                                     height: rect[3]
1273                                 });
1274                                 el[appendChild](rc);
1275                                 o.paper.defs[appendChild](el);
1276                                 $(node, {"clip-path": "url(#" + el.id + ")"});
1277                                 o.clip = rc;
1278                             }
1279                             if (!value) {
1280                                 var clip = doc.getElementById(node.getAttribute("clip-path")[rp](/(^url\(#|\)$)/g, E));
1281                                 clip && clip.parentNode.removeChild(clip);
1282                                 $(node, {"clip-path": E});
1283                                 delete o.clip;
1284                             }
1285                         break;
1286                         case "path":
1287                             if (o.type == "path") {
1288                                 $(node, {d: value ? attrs.path = pathToAbsolute(value) : "M0,0"});
1289                             }
1290                             break;
1291                         case "width":
1292                             node[setAttribute](att, value);
1293                             if (attrs.fx) {
1294                                 att = "x";
1295                                 value = attrs.x;
1296                             } else {
1297                                 break;
1298                             }
1299                         case "x":
1300                             if (attrs.fx) {
1301                                 value = -attrs.x - (attrs.width || 0);
1302                             }
1303                         case "rx":
1304                             if (att == "rx" && o.type == "rect") {
1305                                 break;
1306                             }
1307                         case "cx":
1308                             rotxy && (att == "x" || att == "cx") && (rotxy[1] += value - attrs[att]);
1309                             node[setAttribute](att, value);
1310                             o.pattern && updatePosition(o);
1311                             break;
1312                         case "height":
1313                             node[setAttribute](att, value);
1314                             if (attrs.fy) {
1315                                 att = "y";
1316                                 value = attrs.y;
1317                             } else {
1318                                 break;
1319                             }
1320                         case "y":
1321                             if (attrs.fy) {
1322                                 value = -attrs.y - (attrs.height || 0);
1323                             }
1324                         case "ry":
1325                             if (att == "ry" && o.type == "rect") {
1326                                 break;
1327                             }
1328                         case "cy":
1329                             rotxy && (att == "y" || att == "cy") && (rotxy[2] += value - attrs[att]);
1330                             node[setAttribute](att, value);
1331                             o.pattern && updatePosition(o);
1332                             break;
1333                         case "r":
1334                             if (o.type == "rect") {
1335                                 $(node, {rx: value, ry: value});
1336                             } else {
1337                                 node[setAttribute](att, value);
1338                             }
1339                             break;
1340                         case "src":
1341                             if (o.type == "image") {
1342                                 node.setAttributeNS(o.paper.xlink, "href", value);
1343                             }
1344                             break;
1345                         case "stroke-width":
1346                             node.style.strokeWidth = value;
1347                             // Need following line for Firefox
1348                             node[setAttribute](att, value);
1349                             if (attrs["stroke-dasharray"]) {
1350                                 addDashes(o, attrs["stroke-dasharray"]);
1351                             }
1352                             break;
1353                         case "stroke-dasharray":
1354                             addDashes(o, value);
1355                             break;
1356                         case "translation":
1357                             var xy = Str(value)[split](separator);
1358                             xy[0] = +xy[0] || 0;
1359                             xy[1] = +xy[1] || 0;
1360                             if (rotxy) {
1361                                 rotxy[1] += xy[0];
1362                                 rotxy[2] += xy[1];
1363                             }
1364                             translate.call(o, xy[0], xy[1]);
1365                             break;
1366                         case "scale":
1367                             xy = Str(value)[split](separator);
1368                             o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, isNaN(toFloat(xy[2])) ? null : +xy[2], isNaN(toFloat(xy[3])) ? null : +xy[3]);
1369                             break;
1370                         case fillString:
1371                             var isURL = Str(value).match(ISURL);
1372                             if (isURL) {
1373                                 el = $("pattern");
1374                                 var ig = $("image");
1375                                 el.id = createUUID();
1376                                 $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
1377                                 $(ig, {x: 0, y: 0});
1378                                 ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
1379                                 el[appendChild](ig);
1380  
1381                                 var img = doc.createElement("img");
1382                                 img.style.cssText = "position:absolute;left:-9999em;top-9999em";
1383                                 img.onload = function () {
1384                                     $(el, {width: this.offsetWidth, height: this.offsetHeight});
1385                                     $(ig, {width: this.offsetWidth, height: this.offsetHeight});
1386                                     doc.body.removeChild(this);
1387                                     o.paper.safari();
1388                                 };
1389                                 doc.body[appendChild](img);
1390                                 img.src = isURL[1];
1391                                 o.paper.defs[appendChild](el);
1392                                 node.style.fill = "url(#" + el.id + ")";
1393                                 $(node, {fill: "url(#" + el.id + ")"});
1394                                 o.pattern = el;
1395                                 o.pattern && updatePosition(o);
1396                                 break;
1397                             }
1398                             var clr = R.getRGB(value);
1399                             if (!clr.error) {
1400                                 delete params.gradient;
1401                                 delete attrs.gradient;
1402                                 !R.is(attrs.opacity, "undefined") &&
1403                                     R.is(params.opacity, "undefined") &&
1404                                     $(node, {opacity: attrs.opacity});
1405                                 !R.is(attrs["fill-opacity"], "undefined") &&
1406                                     R.is(params["fill-opacity"], "undefined") &&
1407                                     $(node, {"fill-opacity": attrs["fill-opacity"]});
1408                             } else if ((({circle: 1, ellipse: 1})[has](o.type) || Str(value).charAt() != "r") && addGradientFill(node, value, o.paper)) {
1409                                 attrs.gradient = value;
1410                                 attrs.fill = "none";
1411                                 break;
1412                             }
1413                             clr[has]("o") && $(node, {"fill-opacity": clr.o > 1 ? clr.o / 100 : clr.o});
1414                         case "stroke":
1415                             clr = R.getRGB(value);
1416                             node[setAttribute](att, clr.hex);
1417                             att == "stroke" && clr[has]("o") && $(node, {"stroke-opacity": clr.o > 1 ? clr.o / 100 : clr.o});
1418                             break;
1419                         case "gradient":
1420                             (({circle: 1, ellipse: 1})[has](o.type) || Str(value).charAt() != "r") && addGradientFill(node, value, o.paper);
1421                             break;
1422                         case "opacity":
1423                         case "fill-opacity":
1424                             if (attrs.gradient) {
1425                                 var gradient = doc.getElementById(node.getAttribute(fillString)[rp](/^url\(#|\)$/g, E));
1426                                 if (gradient) {
1427                                     var stops = gradient.getElementsByTagName("stop");
1428                                     stops[stops[length] - 1][setAttribute]("stop-opacity", value);
1429                                 }
1430                                 break;
1431                             }
1432                         default:
1433                             att == "font-size" && (value = toInt(value, 10) + "px");
1434                             var cssrule = att[rp](/(\-.)/g, function (w) {
1435                                 return upperCase.call(w.substring(1));
1436                             });
1437                             node.style[cssrule] = value;
1438                             // Need following line for Firefox
1439                             node[setAttribute](att, value);
1440                             break;
1441                     }
1442                 }
1443             }
1444             
1445             tuneText(o, params);
1446             if (rotxy) {
1447                 o.rotate(rotxy.join(S));
1448             } else {
1449                 toFloat(rot) && o.rotate(rot, true);
1450             }
1451         };
1452         var leading = 1.2,
1453         tuneText = function (el, params) {
1454             if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
1455                 return;
1456             }
1457             var a = el.attrs,
1458                 node = el.node,
1459                 fontSize = node.firstChild ? toInt(doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
1460  
1461             if (params[has]("text")) {
1462                 a.text = params.text;
1463                 while (node.firstChild) {
1464                     node.removeChild(node.firstChild);
1465                 }
1466                 var texts = Str(params.text)[split]("\n");
1467                 for (var i = 0, ii = texts[length]; i < ii; i++) if (texts[i]) {
1468                     var tspan = $("tspan");
1469                     i && $(tspan, {dy: fontSize * leading, x: a.x});
1470                     tspan[appendChild](doc.createTextNode(texts[i]));
1471                     node[appendChild](tspan);
1472                 }
1473             } else {
1474                 texts = node.getElementsByTagName("tspan");
1475                 for (i = 0, ii = texts[length]; i < ii; i++) {
1476                     i && $(texts[i], {dy: fontSize * leading, x: a.x});
1477                 }
1478             }
1479             $(node, {y: a.y});
1480             var bb = el.getBBox(),
1481                 dif = a.y - (bb.y + bb.height / 2);
1482             dif && isFinite(dif) && $(node, {y: a.y + dif});
1483         },
1484         Element = function (node, svg) {
1485             var X = 0,
1486                 Y = 0;
1487             this[0] = node;
1488             this.id = R._oid++;
1489             this.node = node;
1490             node.raphael = this;
1491             this.paper = svg;
1492             this.attrs = this.attrs || {};
1493             this.transformations = []; // rotate, translate, scale
1494             this._ = {
1495                 tx: 0,
1496                 ty: 0,
1497                 rt: {deg: 0, cx: 0, cy: 0},
1498                 sx: 1,
1499                 sy: 1
1500             };
1501             !svg.bottom && (svg.bottom = this);
1502             this.prev = svg.top;
1503             svg.top && (svg.top.next = this);
1504             svg.top = this;
1505             this.next = null;
1506         };
1507         var elproto = Element[proto];
1508         Element[proto].rotate = function (deg, cx, cy) {
1509             if (this.removed) {
1510                 return this;
1511             }
1512             if (deg == null) {
1513                 if (this._.rt.cx) {
1514                     return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
1515                 }
1516                 return this._.rt.deg;
1517             }
1518             var bbox = this.getBBox();
1519             deg = Str(deg)[split](separator);
1520             if (deg[length] - 1) {
1521                 cx = toFloat(deg[1]);
1522                 cy = toFloat(deg[2]);
1523             }
1524             deg = toFloat(deg[0]);
1525             if (cx != null && cx !== false) {
1526                 this._.rt.deg = deg;
1527             } else {
1528                 this._.rt.deg += deg;
1529             }
1530             (cy == null) && (cx = null);
1531             this._.rt.cx = cx;
1532             this._.rt.cy = cy;
1533             cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1534             cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1535             if (this._.rt.deg) {
1536                 this.transformations[0] = R.format("rotate({0} {1} {2})", this._.rt.deg, cx, cy);
1537                 this.clip && $(this.clip, {transform: R.format("rotate({0} {1} {2})", -this._.rt.deg, cx, cy)});
1538             } else {
1539                 this.transformations[0] = E;
1540                 this.clip && $(this.clip, {transform: E});
1541             }
1542             $(this.node, {transform: this.transformations[join](S)});
1543             return this;
1544         };
1545         Element[proto].hide = function () {
1546             !this.removed && (this.node.style.display = "none");
1547             return this;
1548         };
1549         Element[proto].show = function () {
1550             !this.removed && (this.node.style.display = "");
1551             return this;
1552         };
1553         Element[proto].remove = function () {
1554             if (this.removed) {
1555                 return;
1556             }
1557             tear(this, this.paper);
1558             this.node.parentNode.removeChild(this.node);
1559             for (var i in this) {
1560                 delete this[i];
1561             }
1562             this.removed = true;
1563         };
1564         Element[proto].getBBox = function () {
1565             if (this.removed) {
1566                 return this;
1567             }
1568             if (this.type == "path") {
1569                 return pathDimensions(this.attrs.path);
1570             }
1571             if (this.node.style.display == "none") {
1572                 this.show();
1573                 var hide = true;
1574             }
1575             var bbox = {};
1576             try {
1577                 bbox = this.node.getBBox();
1578             } catch(e) {
1579                 // Firefox 3.0.x plays badly here
1580             } finally {
1581                 bbox = bbox || {};
1582             }
1583             if (this.type == "text") {
1584                 bbox = {x: bbox.x, y: Infinity, width: 0, height: 0};
1585                 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1586                     var bb = this.node.getExtentOfChar(i);
1587                     (bb.y < bbox.y) && (bbox.y = bb.y);
1588                     (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1589                     (bb.x + bb.width - bbox.x > bbox.width) && (bbox.width = bb.x + bb.width - bbox.x);
1590                 }
1591             }
1592             hide && this.hide();
1593             return bbox;
1594         };
1595         Element[proto].attr = function (name, value) {
1596             if (this.removed) {
1597                 return this;
1598             }
1599             if (name == null) {
1600                 var res = {};
1601                 for (var i in this.attrs) if (this.attrs[has](i)) {
1602                     res[i] = this.attrs[i];
1603                 }
1604                 this._.rt.deg && (res.rotation = this.rotate());
1605                 (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
1606                 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
1607                 return res;
1608             }
1609             if (value == null && R.is(name, string)) {
1610                 if (name == "translation") {
1611                     return translate.call(this);
1612                 }
1613                 if (name == "rotation") {
1614                     return this.rotate();
1615                 }
1616                 if (name == "scale") {
1617                     return this.scale();
1618                 }
1619                 if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
1620                     return this.attrs.gradient;
1621                 }
1622                 return this.attrs[name];
1623             }
1624             if (value == null && R.is(name, array)) {
1625                 var values = {};
1626                 for (var j = 0, jj = name.length; j < jj; j++) {
1627                     values[name[j]] = this.attr(name[j]);
1628                 }
1629                 return values;
1630             }
1631             if (value != null) {
1632                 var params = {};
1633                 params[name] = value;
1634             } else if (name != null && R.is(name, "object")) {
1635                 params = name;
1636             }
1637             for (var key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
1638                 var par = this.paper.customAttributes[key].apply(this, [][concat](params[key]));
1639                 this.attrs[key] = params[key];
1640                 for (var subkey in par) if (par[has](subkey)) {
1641                     params[subkey] = par[subkey];
1642                 }
1643             }
1644             setFillAndStroke(this, params);
1645             return this;
1646         };
1647         Element[proto].toFront = function () {
1648             if (this.removed) {
1649                 return this;
1650             }
1651             this.node.parentNode[appendChild](this.node);
1652             var svg = this.paper;
1653             svg.top != this && tofront(this, svg);
1654             return this;
1655         };
1656         Element[proto].toBack = function () {
1657             if (this.removed) {
1658                 return this;
1659             }
1660             if (this.node.parentNode.firstChild != this.node) {
1661                 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1662                 toback(this, this.paper);
1663                 var svg = this.paper;
1664             }
1665             return this;
1666         };
1667         Element[proto].insertAfter = function (element) {
1668             if (this.removed) {
1669                 return this;
1670             }
1671             var node = element.node || element[element.length - 1].node;
1672             if (node.nextSibling) {
1673                 node.parentNode.insertBefore(this.node, node.nextSibling);
1674             } else {
1675                 node.parentNode[appendChild](this.node);
1676             }
1677             insertafter(this, element, this.paper);
1678             return this;
1679         };
1680         Element[proto].insertBefore = function (element) {
1681             if (this.removed) {
1682                 return this;
1683             }
1684             var node = element.node || element[0].node;
1685             node.parentNode.insertBefore(this.node, node);
1686             insertbefore(this, element, this.paper);
1687             return this;
1688         };
1689         Element[proto].blur = function (size) {
1690             // Experimental. No Safari support. Use it on your own risk.
1691             var t = this;
1692             if (+size !== 0) {
1693                 var fltr = $("filter"),
1694                     blur = $("feGaussianBlur");
1695                 t.attrs.blur = size;
1696                 fltr.id = createUUID();
1697                 $(blur, {stdDeviation: +size || 1.5});
1698                 fltr.appendChild(blur);
1699                 t.paper.defs.appendChild(fltr);
1700                 t._blur = fltr;
1701                 $(t.node, {filter: "url(#" + fltr.id + ")"});
1702             } else {
1703                 if (t._blur) {
1704                     t._blur.parentNode.removeChild(t._blur);
1705                     delete t._blur;
1706                     delete t.attrs.blur;
1707                 }
1708                 t.node.removeAttribute("filter");
1709             }
1710         };
1711         var theCircle = function (svg, x, y, r) {
1712             var el = $("circle");
1713             svg.canvas && svg.canvas[appendChild](el);
1714             var res = new Element(el, svg);
1715             res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
1716             res.type = "circle";
1717             $(el, res.attrs);
1718             return res;
1719         },
1720         theRect = function (svg, x, y, w, h, r) {
1721             var el = $("rect");
1722             svg.canvas && svg.canvas[appendChild](el);
1723             var res = new Element(el, svg);
1724             res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
1725             res.type = "rect";
1726             $(el, res.attrs);
1727             return res;
1728         },
1729         theEllipse = function (svg, x, y, rx, ry) {
1730             var el = $("ellipse");
1731             svg.canvas && svg.canvas[appendChild](el);
1732             var res = new Element(el, svg);
1733             res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
1734             res.type = "ellipse";
1735             $(el, res.attrs);
1736             return res;
1737         },
1738         theImage = function (svg, src, x, y, w, h) {
1739             var el = $("image");
1740             $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
1741             el.setAttributeNS(svg.xlink, "href", src);
1742             svg.canvas && svg.canvas[appendChild](el);
1743             var res = new Element(el, svg);
1744             res.attrs = {x: x, y: y, width: w, height: h, src: src};
1745             res.type = "image";
1746             return res;
1747         },
1748         theText = function (svg, x, y, text) {
1749             var el = $("text");
1750             $(el, {x: x, y: y, "text-anchor": "middle"});
1751             svg.canvas && svg.canvas[appendChild](el);
1752             var res = new Element(el, svg);
1753             res.attrs = {x: x, y: y, "text-anchor": "middle", text: text, font: availableAttrs.font, stroke: "none", fill: "#000"};
1754             res.type = "text";
1755             setFillAndStroke(res, res.attrs);
1756             return res;
1757         },
1758         setSize = function (width, height) {
1759             this.width = width || this.width;
1760             this.height = height || this.height;
1761             this.canvas[setAttribute]("width", this.width);
1762             this.canvas[setAttribute]("height", this.height);
1763             return this;
1764         },
1765         create = function () {
1766             var con = getContainer[apply](0, arguments),
1767                 container = con && con.container,
1768                 x = con.x,
1769                 y = con.y,
1770                 width = con.width,
1771                 height = con.height;
1772             if (!container) {
1773                 throw new Error("SVG container not found.");
1774             }
1775             var cnvs = $("svg");
1776             x = x || 0;
1777             y = y || 0;
1778             width = width || 512;
1779             height = height || 342;
1780             $(cnvs, {
1781                 xmlns: "http://www.w3.org/2000/svg",
1782                 version: 1.1,
1783                 width: width,
1784                 height: height
1785             });
1786             if (container == 1) {
1787                 cnvs.style.cssText = "position:absolute;left:" + x + "px;top:" + y + "px";
1788                 doc.body[appendChild](cnvs);
1789             } else {
1790                 if (container.firstChild) {
1791                     container.insertBefore(cnvs, container.firstChild);
1792                 } else {
1793                     container[appendChild](cnvs);
1794                 }
1795             }
1796             container = new Paper;
1797             container.width = width;
1798             container.height = height;
1799             container.canvas = cnvs;
1800             plugins.call(container, container, R.fn);
1801             container.clear();
1802             return container;
1803         };
1804         paperproto.clear = function () {
1805             var c = this.canvas;
1806             while (c.firstChild) {
1807                 c.removeChild(c.firstChild);
1808             }
1809             this.bottom = this.top = null;
1810             (this.desc = $("desc"))[appendChild](doc.createTextNode("Created with Rapha\xebl"));
1811             c[appendChild](this.desc);
1812             c[appendChild](this.defs = $("defs"));
1813         };
1814         paperproto.remove = function () {
1815             this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
1816             for (var i in this) {
1817                 this[i] = removed(i);
1818             }
1819         };
1820     }
1821
1822     // VML
1823     if (R.vml) {
1824         var map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
1825             bites = /([clmz]),?([^clmz]*)/gi,
1826             blurregexp = / progid:\S+Blur\([^\)]+\)/g,
1827             val = /-?[^,\s-]+/g,
1828             coordsize = 1e3 + S + 1e3,
1829             zoom = 10,
1830             pathlike = {path: 1, rect: 1},
1831             path2vml = function (path) {
1832                 var total =  /[ahqstv]/ig,
1833                     command = pathToAbsolute;
1834                 Str(path).match(total) && (command = path2curve);
1835                 total = /[clmz]/g;
1836                 if (command == pathToAbsolute && !Str(path).match(total)) {
1837                     var res = Str(path)[rp](bites, function (all, command, args) {
1838                         var vals = [],
1839                             isMove = lowerCase.call(command) == "m",
1840                             res = map[command];
1841                         args[rp](val, function (value) {
1842                             if (isMove && vals[length] == 2) {
1843                                 res += vals + map[command == "m" ? "l" : "L"];
1844                                 vals = [];
1845                             }
1846                             vals[push](round(value * zoom));
1847                         });
1848                         return res + vals;
1849                     });
1850                     return res;
1851                 }
1852                 var pa = command(path), p, r;
1853                 res = [];
1854                 for (var i = 0, ii = pa[length]; i < ii; i++) {
1855                     p = pa[i];
1856                     r = lowerCase.call(pa[i][0]);
1857                     r == "z" && (r = "x");
1858                     for (var j = 1, jj = p[length]; j < jj; j++) {
1859                         r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
1860                     }
1861                     res[push](r);
1862                 }
1863                 return res[join](S);
1864             };
1865         
1866         R[toString] = function () {
1867             return  "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
1868         };
1869         thePath = function (pathString, vml) {
1870             var g = createNode("group");
1871             g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
1872             g.coordsize = vml.coordsize;
1873             g.coordorigin = vml.coordorigin;
1874             var el = createNode("shape"), ol = el.style;
1875             ol.width = vml.width + "px";
1876             ol.height = vml.height + "px";
1877             el.coordsize = coordsize;
1878             el.coordorigin = vml.coordorigin;
1879             g[appendChild](el);
1880             var p = new Element(el, g, vml),
1881                 attr = {fill: "none", stroke: "#000"};
1882             pathString && (attr.path = pathString);
1883             p.type = "path";
1884             p.path = [];
1885             p.Path = E;
1886             setFillAndStroke(p, attr);
1887             vml.canvas[appendChild](g);
1888             return p;
1889         };
1890         setFillAndStroke = function (o, params) {
1891             o.attrs = o.attrs || {};
1892             var node = o.node,
1893                 a = o.attrs,
1894                 s = node.style,
1895                 xy,
1896                 newpath = (params.x != a.x || params.y != a.y || params.width != a.width || params.height != a.height || params.r != a.r) && o.type == "rect",
1897                 res = o;
1898
1899             for (var par in params) if (params[has](par)) {
1900                 a[par] = params[par];
1901             }
1902             if (newpath) {
1903                 a.path = rectPath(a.x, a.y, a.width, a.height, a.r);
1904                 o.X = a.x;
1905                 o.Y = a.y;
1906                 o.W = a.width;
1907                 o.H = a.height;
1908             }
1909             params.href && (node.href = params.href);
1910             params.title && (node.title = params.title);
1911             params.target && (node.target = params.target);
1912             params.cursor && (s.cursor = params.cursor);
1913             "blur" in params && o.blur(params.blur);
1914             if (params.path && o.type == "path" || newpath) {
1915                 node.path = path2vml(a.path);
1916             }
1917             if (params.rotation != null) {
1918                 o.rotate(params.rotation, true);
1919             }
1920             if (params.translation) {
1921                 xy = Str(params.translation)[split](separator);
1922                 translate.call(o, xy[0], xy[1]);
1923                 if (o._.rt.cx != null) {
1924                     o._.rt.cx +=+ xy[0];
1925                     o._.rt.cy +=+ xy[1];
1926                     o.setBox(o.attrs, xy[0], xy[1]);
1927                 }
1928             }
1929             if (params.scale) {
1930                 xy = Str(params.scale)[split](separator);
1931                 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1932             }
1933             if ("clip-rect" in params) {
1934                 var rect = Str(params["clip-rect"])[split](separator);
1935                 if (rect[length] == 4) {
1936                     rect[2] = +rect[2] + (+rect[0]);
1937                     rect[3] = +rect[3] + (+rect[1]);
1938                     var div = node.clipRect || doc.createElement("div"),
1939                         dstyle = div.style,
1940                         group = node.parentNode;
1941                     dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
1942                     if (!node.clipRect) {
1943                         dstyle.position = "absolute";
1944                         dstyle.top = 0;
1945                         dstyle.left = 0;
1946                         dstyle.width = o.paper.width + "px";
1947                         dstyle.height = o.paper.height + "px";
1948                         group.parentNode.insertBefore(div, group);
1949                         div[appendChild](group);
1950                         node.clipRect = div;
1951                     }
1952                 }
1953                 if (!params["clip-rect"]) {
1954                     node.clipRect && (node.clipRect.style.clip = E);
1955                 }
1956             }
1957             if (o.type == "image" && params.src) {
1958                 node.src = params.src;
1959             }
1960             if (o.type == "image" && params.opacity) {
1961                 node.filterOpacity = ms + ".Alpha(opacity=" + (params.opacity * 100) + ")";
1962                 s.filter = (node.filterMatrix || E) + (node.filterOpacity || E);
1963             }
1964             params.font && (s.font = params.font);
1965             params["font-family"] && (s.fontFamily = '"' + params["font-family"][split](",")[0][rp](/^['"]+|['"]+$/g, E) + '"');
1966             params["font-size"] && (s.fontSize = params["font-size"]);
1967             params["font-weight"] && (s.fontWeight = params["font-weight"]);
1968             params["font-style"] && (s.fontStyle = params["font-style"]);
1969             if (params.opacity != null || 
1970                 params["stroke-width"] != null ||
1971                 params.fill != null ||
1972                 params.stroke != null ||
1973                 params["stroke-width"] != null ||
1974                 params["stroke-opacity"] != null ||
1975                 params["fill-opacity"] != null ||
1976                 params["stroke-dasharray"] != null ||
1977                 params["stroke-miterlimit"] != null ||
1978                 params["stroke-linejoin"] != null ||
1979                 params["stroke-linecap"] != null) {
1980                 node = o.shape || node;
1981                 var fill = (node.getElementsByTagName(fillString) && node.getElementsByTagName(fillString)[0]),
1982                     newfill = false;
1983                 !fill && (newfill = fill = createNode(fillString));
1984                 if ("fill-opacity" in params || "opacity" in params) {
1985                     var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
1986                     opacity = mmin(mmax(opacity, 0), 1);
1987                     fill.opacity = opacity;
1988                 }
1989                 params.fill && (fill.on = true);
1990                 if (fill.on == null || params.fill == "none") {
1991                     fill.on = false;
1992                 }
1993                 if (fill.on && params.fill) {
1994                     var isURL = params.fill.match(ISURL);
1995                     if (isURL) {
1996                         fill.src = isURL[1];
1997                         fill.type = "tile";
1998                     } else {
1999                         fill.color = R.getRGB(params.fill).hex;
2000                         fill.src = E;
2001                         fill.type = "solid";
2002                         if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || Str(params.fill).charAt() != "r") && addGradientFill(res, params.fill)) {
2003                             a.fill = "none";
2004                             a.gradient = params.fill;
2005                         }
2006                     }
2007                 }
2008                 newfill && node[appendChild](fill);
2009                 var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
2010                 newstroke = false;
2011                 !stroke && (newstroke = stroke = createNode("stroke"));
2012                 if ((params.stroke && params.stroke != "none") ||
2013                     params["stroke-width"] ||
2014                     params["stroke-opacity"] != null ||
2015                     params["stroke-dasharray"] ||
2016                     params["stroke-miterlimit"] ||
2017                     params["stroke-linejoin"] ||
2018                     params["stroke-linecap"]) {
2019                     stroke.on = true;
2020                 }
2021                 (params.stroke == "none" || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
2022                 var strokeColor = R.getRGB(params.stroke);
2023                 stroke.on && params.stroke && (stroke.color = strokeColor.hex);
2024                 opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
2025                 var width = (toFloat(params["stroke-width"]) || 1) * .75;
2026                 opacity = mmin(mmax(opacity, 0), 1);
2027                 params["stroke-width"] == null && (width = a["stroke-width"]);
2028                 params["stroke-width"] && (stroke.weight = width);
2029                 width && width < 1 && (opacity *= width) && (stroke.weight = 1);
2030                 stroke.opacity = opacity;
2031                 
2032                 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
2033                 stroke.miterlimit = params["stroke-miterlimit"] || 8;
2034                 params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
2035                 if (params["stroke-dasharray"]) {
2036                     var dasharray = {
2037                         "-": "shortdash",
2038                         ".": "shortdot",
2039                         "-.": "shortdashdot",
2040                         "-..": "shortdashdotdot",
2041                         ". ": "dot",
2042                         "- ": "dash",
2043                         "--": "longdash",
2044                         "- .": "dashdot",
2045                         "--.": "longdashdot",
2046                         "--..": "longdashdotdot"
2047                     };
2048                     stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
2049                 }
2050                 newstroke && node[appendChild](stroke);
2051             }
2052             if (res.type == "text") {
2053                 s = res.paper.span.style;
2054                 a.font && (s.font = a.font);
2055                 a["font-family"] && (s.fontFamily = a["font-family"]);
2056                 a["font-size"] && (s.fontSize = a["font-size"]);
2057                 a["font-weight"] && (s.fontWeight = a["font-weight"]);
2058                 a["font-style"] && (s.fontStyle = a["font-style"]);
2059                 res.node.string && (res.paper.span.innerHTML = Str(res.node.string)[rp](/</g, "&#60;")[rp](/&/g, "&#38;")[rp](/\n/g, "<br>"));
2060                 res.W = a.w = res.paper.span.offsetWidth;
2061                 res.H = a.h = res.paper.span.offsetHeight;
2062                 res.X = a.x;
2063                 res.Y = a.y + round(res.H / 2);
2064  
2065                 // text-anchor emulationm
2066                 switch (a["text-anchor"]) {
2067                     case "start":
2068                         res.node.style["v-text-align"] = "left";
2069                         res.bbx = round(res.W / 2);
2070                     break;
2071                     case "end":
2072                         res.node.style["v-text-align"] = "right";
2073                         res.bbx = -round(res.W / 2);
2074                     break;
2075                     default:
2076                         res.node.style["v-text-align"] = "center";
2077                     break;
2078                 }
2079             }
2080         };
2081         addGradientFill = function (o, gradient) {
2082             o.attrs = o.attrs || {};
2083             var attrs = o.attrs,
2084                 fill,
2085                 type = "linear",
2086                 fxfy = ".5 .5";
2087             o.attrs.gradient = gradient;
2088             gradient = Str(gradient)[rp](radial_gradient, function (all, fx, fy) {
2089                 type = "radial";
2090                 if (fx && fy) {
2091                     fx = toFloat(fx);
2092                     fy = toFloat(fy);
2093                     pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
2094                     fxfy = fx + S + fy;
2095                 }
2096                 return E;
2097             });
2098             gradient = gradient[split](/\s*\-\s*/);
2099             if (type == "linear") {
2100                 var angle = gradient.shift();
2101                 angle = -toFloat(angle);
2102                 if (isNaN(angle)) {
2103                     return null;
2104                 }
2105             }
2106             var dots = parseDots(gradient);
2107             if (!dots) {
2108                 return null;
2109             }
2110             o = o.shape || o.node;
2111             fill = o.getElementsByTagName(fillString)[0] || createNode(fillString);
2112             !fill.parentNode && o.appendChild(fill);
2113             if (dots[length]) {
2114                 fill.on = true;
2115                 fill.method = "none";
2116                 fill.color = dots[0].color;
2117                 fill.color2 = dots[dots[length] - 1].color;
2118                 var clrs = [];
2119                 for (var i = 0, ii = dots[length]; i < ii; i++) {
2120                     dots[i].offset && clrs[push](dots[i].offset + S + dots[i].color);
2121                 }
2122                 fill.colors && (fill.colors.value = clrs[length] ? clrs[join]() : "0% " + fill.color);
2123                 if (type == "radial") {
2124                     fill.type = "gradientradial";
2125                     fill.focus = "100%";
2126                     fill.focussize = fxfy;
2127                     fill.focusposition = fxfy;
2128                 } else {
2129                     fill.type = "gradient";
2130                     fill.angle = (270 - angle) % 360;
2131                 }
2132             }
2133             return 1;
2134         };
2135         Element = function (node, group, vml) {
2136             var Rotation = 0,
2137                 RotX = 0,
2138                 RotY = 0,
2139                 Scale = 1;
2140             this[0] = node;
2141             this.id = R._oid++;
2142             this.node = node;
2143             node.raphael = this;
2144             this.X = 0;
2145             this.Y = 0;
2146             this.attrs = {};
2147             this.Group = group;
2148             this.paper = vml;
2149             this._ = {
2150                 tx: 0,
2151                 ty: 0,
2152                 rt: {deg:0},
2153                 sx: 1,
2154                 sy: 1
2155             };
2156             !vml.bottom && (vml.bottom = this);
2157             this.prev = vml.top;
2158             vml.top && (vml.top.next = this);
2159             vml.top = this;
2160             this.next = null;
2161         };
2162         elproto = Element[proto];
2163         elproto.rotate = function (deg, cx, cy) {
2164             if (this.removed) {
2165                 return this;
2166             }
2167             if (deg == null) {
2168                 if (this._.rt.cx) {
2169                     return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
2170                 }
2171                 return this._.rt.deg;
2172             }
2173             deg = Str(deg)[split](separator);
2174             if (deg[length] - 1) {
2175                 cx = toFloat(deg[1]);
2176                 cy = toFloat(deg[2]);
2177             }
2178             deg = toFloat(deg[0]);
2179             if (cx != null) {
2180                 this._.rt.deg = deg;
2181             } else {
2182                 this._.rt.deg += deg;
2183             }
2184             cy == null && (cx = null);
2185             this._.rt.cx = cx;
2186             this._.rt.cy = cy;
2187             this.setBox(this.attrs, cx, cy);
2188             this.Group.style.rotation = this._.rt.deg;
2189             // gradient fix for rotation. TODO
2190             // var fill = (this.shape || this.node).getElementsByTagName(fillString);
2191             // fill = fill[0] || {};
2192             // var b = ((360 - this._.rt.deg) - 270) % 360;
2193             // !R.is(fill.angle, "undefined") && (fill.angle = b);
2194             return this;
2195         };
2196         elproto.setBox = function (params, cx, cy) {
2197             if (this.removed) {
2198                 return this;
2199             }
2200             var gs = this.Group.style,
2201                 os = (this.shape && this.shape.style) || this.node.style;
2202             params = params || {};
2203             for (var i in params) if (params[has](i)) {
2204                 this.attrs[i] = params[i];
2205             }
2206             cx = cx || this._.rt.cx;
2207             cy = cy || this._.rt.cy;
2208             var attr = this.attrs,
2209                 x,
2210                 y,
2211                 w,
2212                 h;
2213             switch (this.type) {
2214                 case "circle":
2215                     x = attr.cx - attr.r;
2216                     y = attr.cy - attr.r;
2217                     w = h = attr.r * 2;
2218                     break;
2219                 case "ellipse":
2220                     x = attr.cx - attr.rx;
2221                     y = attr.cy - attr.ry;
2222                     w = attr.rx * 2;
2223                     h = attr.ry * 2;
2224                     break;
2225                 case "image":
2226                     x = +attr.x;
2227                     y = +attr.y;
2228                     w = attr.width || 0;
2229                     h = attr.height || 0;
2230                     break;
2231                 case "text":
2232                     this.textpath.v = ["m", round(attr.x), ", ", round(attr.y - 2), "l", round(attr.x) + 1, ", ", round(attr.y - 2)][join](E);
2233                     x = attr.x - round(this.W / 2);
2234                     y = attr.y - this.H / 2;
2235                     w = this.W;
2236                     h = this.H;
2237                     break;
2238                 case "rect":
2239                 case "path":
2240                     if (!this.attrs.path) {
2241                         x = 0;
2242                         y = 0;
2243                         w = this.paper.width;
2244                         h = this.paper.height;
2245                     } else {
2246                         var dim = pathDimensions(this.attrs.path);
2247                         x = dim.x;
2248                         y = dim.y;
2249                         w = dim.width;
2250                         h = dim.height;
2251                     }
2252                     break;
2253                 default:
2254                     x = 0;
2255                     y = 0;
2256                     w = this.paper.width;
2257                     h = this.paper.height;
2258                     break;
2259             }
2260             cx = (cx == null) ? x + w / 2 : cx;
2261             cy = (cy == null) ? y + h / 2 : cy;
2262             var left = cx - this.paper.width / 2,
2263                 top = cy - this.paper.height / 2, t;
2264             gs.left != (t = left + "px") && (gs.left = t);
2265             gs.top != (t = top + "px") && (gs.top = t);
2266             this.X = pathlike[has](this.type) ? -left : x;
2267             this.Y = pathlike[has](this.type) ? -top : y;
2268             this.W = w;
2269             this.H = h;
2270             if (pathlike[has](this.type)) {
2271                 os.left != (t = -left * zoom + "px") && (os.left = t);
2272                 os.top != (t = -top * zoom + "px") && (os.top = t);
2273             } else if (this.type == "text") {
2274                 os.left != (t = -left + "px") && (os.left = t);
2275                 os.top != (t = -top + "px") && (os.top = t);
2276             } else {
2277                 gs.width != (t = this.paper.width + "px") && (gs.width = t);
2278                 gs.height != (t = this.paper.height + "px") && (gs.height = t);
2279                 os.left != (t = x - left + "px") && (os.left = t);
2280                 os.top != (t = y - top + "px") && (os.top = t);
2281                 os.width != (t = w + "px") && (os.width = t);
2282                 os.height != (t = h + "px") && (os.height = t);
2283             }
2284         };
2285         elproto.hide = function () {
2286             !this.removed && (this.Group.style.display = "none");
2287             return this;
2288         };
2289         elproto.show = function () {
2290             !this.removed && (this.Group.style.display = "block");
2291             return this;
2292         };
2293         elproto.getBBox = function () {
2294             if (this.removed) {
2295                 return this;
2296             }
2297             if (pathlike[has](this.type)) {
2298                 return pathDimensions(this.attrs.path);
2299             }
2300             return {
2301                 x: this.X + (this.bbx || 0),
2302                 y: this.Y,
2303                 width: this.W,
2304                 height: this.H
2305             };
2306         };
2307         elproto.remove = function () {
2308             if (this.removed) {
2309                 return;
2310             }
2311             tear(this, this.paper);
2312             this.node.parentNode.removeChild(this.node);
2313             this.Group.parentNode.removeChild(this.Group);
2314             this.shape && this.shape.parentNode.removeChild(this.shape);
2315             for (var i in this) {
2316                 delete this[i];
2317             }
2318             this.removed = true;
2319         };
2320         elproto.attr = function (name, value) {
2321             if (this.removed) {
2322                 return this;
2323             }
2324             if (name == null) {
2325                 var res = {};
2326                 for (var i in this.attrs) if (this.attrs[has](i)) {
2327                     res[i] = this.attrs[i];
2328                 }
2329                 this._.rt.deg && (res.rotation = this.rotate());
2330                 (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
2331                 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
2332                 return res;
2333             }
2334             if (value == null && R.is(name, "string")) {
2335                 if (name == "translation") {
2336                     return translate.call(this);
2337                 }
2338                 if (name == "rotation") {
2339                     return this.rotate();
2340                 }
2341                 if (name == "scale") {
2342                     return this.scale();
2343                 }
2344                 if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
2345                     return this.attrs.gradient;
2346                 }
2347                 return this.attrs[name];
2348             }
2349             if (this.attrs && value == null && R.is(name, array)) {
2350                 var ii, values = {};
2351                 for (i = 0, ii = name[length]; i < ii; i++) {
2352                     values[name[i]] = this.attr(name[i]);
2353                 }
2354                 return values;
2355             }
2356             var params;
2357             if (value != null) {
2358                 params = {};
2359                 params[name] = value;
2360             }
2361             value == null && R.is(name, "object") && (params = name);
2362             if (params) {
2363                 for (var key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
2364                     var par = this.paper.customAttributes[key].apply(this, [][concat](params[key]));
2365                     this.attrs[key] = params[key];
2366                     for (var subkey in par) if (par[has](subkey)) {
2367                         params[subkey] = par[subkey];
2368                     }
2369                 }
2370                 if (params.text && this.type == "text") {
2371                     this.node.string = params.text;
2372                 }
2373                 setFillAndStroke(this, params);
2374                 if (params.gradient && (({circle: 1, ellipse: 1})[has](this.type) || Str(params.gradient).charAt() != "r")) {
2375                     addGradientFill(this, params.gradient);
2376                 }
2377                 (!pathlike[has](this.type) || this._.rt.deg) && this.setBox(this.attrs);
2378             }
2379             return this;
2380         };
2381         elproto.toFront = function () {
2382             !this.removed && this.Group.parentNode[appendChild](this.Group);
2383             this.paper.top != this && tofront(this, this.paper);
2384             return this;
2385         };
2386         elproto.toBack = function () {
2387             if (this.removed) {
2388                 return this;
2389             }
2390             if (this.Group.parentNode.firstChild != this.Group) {
2391                 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
2392                 toback(this, this.paper);
2393             }
2394             return this;
2395         };
2396         elproto.insertAfter = function (element) {
2397             if (this.removed) {
2398                 return this;
2399             }
2400             if (element.constructor == Set) {
2401                 element = element[element.length - 1];
2402             }
2403             if (element.Group.nextSibling) {
2404                 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
2405             } else {
2406                 element.Group.parentNode[appendChild](this.Group);
2407             }
2408             insertafter(this, element, this.paper);
2409             return this;
2410         };
2411         elproto.insertBefore = function (element) {
2412             if (this.removed) {
2413                 return this;
2414             }
2415             if (element.constructor == Set) {
2416                 element = element[0];
2417             }
2418             element.Group.parentNode.insertBefore(this.Group, element.Group);
2419             insertbefore(this, element, this.paper);
2420             return this;
2421         };
2422         elproto.blur = function (size) {
2423             var s = this.node.runtimeStyle,
2424                 f = s.filter;
2425             f = f.replace(blurregexp, E);
2426             if (+size !== 0) {
2427                 this.attrs.blur = size;
2428                 s.filter = f + S + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
2429                 s.margin = R.format("-{0}px 0 0 -{0}px", round(+size || 1.5));
2430             } else {
2431                 s.filter = f;
2432                 s.margin = 0;
2433                 delete this.attrs.blur;
2434             }
2435         };
2436  
2437         theCircle = function (vml, x, y, r) {
2438             var g = createNode("group"),
2439                 o = createNode("oval"),
2440                 ol = o.style;
2441             g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2442             g.coordsize = coordsize;
2443             g.coordorigin = vml.coordorigin;
2444             g[appendChild](o);
2445             var res = new Element(o, g, vml);
2446             res.type = "circle";
2447             setFillAndStroke(res, {stroke: "#000", fill: "none"});
2448             res.attrs.cx = x;
2449             res.attrs.cy = y;
2450             res.attrs.r = r;
2451             res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
2452             vml.canvas[appendChild](g);
2453             return res;
2454         };
2455         function rectPath(x, y, w, h, r) {
2456             if (r) {
2457                 return R.format("M{0},{1}l{2},0a{3},{3},0,0,1,{3},{3}l0,{5}a{3},{3},0,0,1,{4},{3}l{6},0a{3},{3},0,0,1,{4},{4}l0,{7}a{3},{3},0,0,1,{3},{4}z", x + r, y, w - r * 2, r, -r, h - r * 2, r * 2 - w, r * 2 - h);
2458             } else {
2459                 return R.format("M{0},{1}l{2},0,0,{3},{4},0z", x, y, w, h, -w);
2460             }
2461         }
2462         theRect = function (vml, x, y, w, h, r) {
2463             var path = rectPath(x, y, w, h, r),
2464                 res = vml.path(path),
2465                 a = res.attrs;
2466             res.X = a.x = x;
2467             res.Y = a.y = y;
2468             res.W = a.width = w;
2469             res.H = a.height = h;
2470             a.r = r;
2471             a.path = path;
2472             res.type = "rect";
2473             return res;
2474         };
2475         theEllipse = function (vml, x, y, rx, ry) {
2476             var g = createNode("group"),
2477                 o = createNode("oval"),
2478                 ol = o.style;
2479             g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2480             g.coordsize = coordsize;
2481             g.coordorigin = vml.coordorigin;
2482             g[appendChild](o);
2483             var res = new Element(o, g, vml);
2484             res.type = "ellipse";
2485             setFillAndStroke(res, {stroke: "#000"});
2486             res.attrs.cx = x;
2487             res.attrs.cy = y;
2488             res.attrs.rx = rx;
2489             res.attrs.ry = ry;
2490             res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
2491             vml.canvas[appendChild](g);
2492             return res;
2493         };
2494         theImage = function (vml, src, x, y, w, h) {
2495             var g = createNode("group"),
2496                 o = createNode("image");
2497             g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2498             g.coordsize = coordsize;
2499             g.coordorigin = vml.coordorigin;
2500             o.src = src;
2501             g[appendChild](o);
2502             var res = new Element(o, g, vml);
2503             res.type = "image";
2504             res.attrs.src = src;
2505             res.attrs.x = x;
2506             res.attrs.y = y;
2507             res.attrs.w = w;
2508             res.attrs.h = h;
2509             res.setBox({x: x, y: y, width: w, height: h});
2510             vml.canvas[appendChild](g);
2511             return res;
2512         };
2513         theText = function (vml, x, y, text) {
2514             var g = createNode("group"),
2515                 el = createNode("shape"),
2516                 ol = el.style,
2517                 path = createNode("path"),
2518                 ps = path.style,
2519                 o = createNode("textpath");
2520             g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2521             g.coordsize = coordsize;
2522             g.coordorigin = vml.coordorigin;
2523             path.v = R.format("m{0},{1}l{2},{1}", round(x * 10), round(y * 10), round(x * 10) + 1);
2524             path.textpathok = true;
2525             ol.width = vml.width;
2526             ol.height = vml.height;
2527             o.string = Str(text);
2528             o.on = true;
2529             el[appendChild](o);
2530             el[appendChild](path);
2531             g[appendChild](el);
2532             var res = new Element(o, g, vml);
2533             res.shape = el;
2534             res.textpath = path;
2535             res.type = "text";
2536             res.attrs.text = text;
2537             res.attrs.x = x;
2538             res.attrs.y = y;
2539             res.attrs.w = 1;
2540             res.attrs.h = 1;
2541             setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2542             res.setBox();
2543             vml.canvas[appendChild](g);
2544             return res;
2545         };
2546         setSize = function (width, height) {
2547             var cs = this.canvas.style;
2548             width == +width && (width += "px");
2549             height == +height && (height += "px");
2550             cs.width = width;
2551             cs.height = height;
2552             cs.clip = "rect(0 " + width + " " + height + " 0)";
2553             return this;
2554         };
2555         var createNode;
2556         doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2557         try {
2558             !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2559             createNode = function (tagName) {
2560                 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2561             };
2562         } catch (e) {
2563             createNode = function (tagName) {
2564                 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2565             };
2566         }
2567         create = function () {
2568             var con = getContainer[apply](0, arguments),
2569                 container = con.container,
2570                 height = con.height,
2571                 s,
2572                 width = con.width,
2573                 x = con.x,
2574                 y = con.y;
2575             if (!container) {
2576                 throw new Error("VML container not found.");
2577             }
2578             var res = new Paper,
2579                 c = res.canvas = doc.createElement("div"),
2580                 cs = c.style;
2581             x = x || 0;
2582             y = y || 0;
2583             width = width || 512;
2584             height = height || 342;
2585             width == +width && (width += "px");
2586             height == +height && (height += "px");
2587             res.width = 1e3;
2588             res.height = 1e3;
2589             res.coordsize = zoom * 1e3 + S + zoom * 1e3;
2590             res.coordorigin = "0 0";
2591             res.span = doc.createElement("span");
2592             res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
2593             c[appendChild](res.span);
2594             cs.cssText = R.format("top:0;left:0;width:{0};height:{1};display:inline-block;position:relative;clip:rect(0 {0} {1} 0);overflow:hidden", width, height);
2595             if (container == 1) {
2596                 doc.body[appendChild](c);
2597                 cs.left = x + "px";
2598                 cs.top = y + "px";
2599                 cs.position = "absolute";
2600             } else {
2601                 if (container.firstChild) {
2602                     container.insertBefore(c, container.firstChild);
2603                 } else {
2604                     container[appendChild](c);
2605                 }
2606             }
2607             plugins.call(res, res, R.fn);
2608             return res;
2609         };
2610         paperproto.clear = function () {
2611             this.canvas.innerHTML = E;
2612             this.span = doc.createElement("span");
2613             this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
2614             this.canvas[appendChild](this.span);
2615             this.bottom = this.top = null;
2616         };
2617         paperproto.remove = function () {
2618             this.canvas.parentNode.removeChild(this.canvas);
2619             for (var i in this) {
2620                 this[i] = removed(i);
2621             }
2622             return true;
2623         };
2624     }
2625  
2626     // rest
2627     // WebKit rendering bug workaround method
2628     var version = navigator.userAgent.match(/Version\/(.*?)\s/);
2629     if ((navigator.vendor == "Apple Computer, Inc.") && (version && version[1] < 4 || navigator.platform.slice(0, 2) == "iP")) {
2630         paperproto.safari = function () {
2631             var rect = this.rect(-99, -99, this.width + 99, this.height + 99).attr({stroke: "none"});
2632             win.setTimeout(function () {rect.remove();});
2633         };
2634     } else {
2635         paperproto.safari = function () {};
2636     }
2637  
2638     // Events
2639     var preventDefault = function () {
2640         this.returnValue = false;
2641     },
2642     preventTouch = function () {
2643         return this.originalEvent.preventDefault();
2644     },
2645     stopPropagation = function () {
2646         this.cancelBubble = true;
2647     },
2648     stopTouch = function () {
2649         return this.originalEvent.stopPropagation();
2650     },
2651     addEvent = (function () {
2652         if (doc.addEventListener) {
2653             return function (obj, type, fn, element) {
2654                 var realName = supportsTouch && touchMap[type] ? touchMap[type] : type;
2655                 var f = function (e) {
2656                     if (supportsTouch && touchMap[has](type)) {
2657                         for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
2658                             if (e.targetTouches[i].target == obj) {
2659                                 var olde = e;
2660                                 e = e.targetTouches[i];
2661                                 e.originalEvent = olde;
2662                                 e.preventDefault = preventTouch;
2663                                 e.stopPropagation = stopTouch;
2664                                 break;
2665                             }
2666                         }
2667                     }
2668                     return fn.call(element, e);
2669                 };
2670                 obj.addEventListener(realName, f, false);
2671                 return function () {
2672                     obj.removeEventListener(realName, f, false);
2673                     return true;
2674                 };
2675             };
2676         } else if (doc.attachEvent) {
2677             return function (obj, type, fn, element) {
2678                 var f = function (e) {
2679                     e = e || win.event;
2680                     e.preventDefault = e.preventDefault || preventDefault;
2681                     e.stopPropagation = e.stopPropagation || stopPropagation;
2682                     return fn.call(element, e);
2683                 };
2684                 obj.attachEvent("on" + type, f);
2685                 var detacher = function () {
2686                     obj.detachEvent("on" + type, f);
2687                     return true;
2688                 };
2689                 return detacher;
2690             };
2691         }
2692     })(),
2693     drag = [],
2694     dragMove = function (e) {
2695         var x = e.clientX,
2696             y = e.clientY,
2697             scrollY = doc.documentElement.scrollTop || doc.body.scrollTop,
2698             scrollX = doc.documentElement.scrollLeft || doc.body.scrollLeft,
2699             dragi,
2700             j = drag.length;
2701         while (j--) {
2702             dragi = drag[j];
2703             if (supportsTouch) {
2704                 var i = e.touches.length,
2705                     touch;
2706                 while (i--) {
2707                     touch = e.touches[i];
2708                     if (touch.identifier == dragi.el._drag.id) {
2709                         x = touch.clientX;
2710                         y = touch.clientY;
2711                         (e.originalEvent ? e.originalEvent : e).preventDefault();
2712                         break;
2713                     }
2714                 }
2715             } else {
2716                 e.preventDefault();
2717             }
2718             x += scrollX;
2719             y += scrollY;
2720             dragi.move && dragi.move.call(dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y);
2721         }
2722     },
2723     dragUp = function () {
2724         R.unmousemove(dragMove).unmouseup(dragUp);
2725         var i = drag.length,
2726             dragi;
2727         while (i--) {
2728             dragi = drag[i];
2729             dragi.el._drag = {};
2730             dragi.end && dragi.end.call(dragi.el);
2731         }
2732         drag = [];
2733     };
2734     for (var i = events[length]; i--;) {
2735         (function (eventName) {
2736             R[eventName] = Element[proto][eventName] = function (fn) {
2737                 if (R.is(fn, "function")) {
2738                     this.events = this.events || [];
2739                     this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || doc, eventName, fn, this)});
2740                 }
2741                 return this;
2742             };
2743             R["un" + eventName] = Element[proto]["un" + eventName] = function (fn) {
2744                 var events = this.events,
2745                     l = events[length];
2746                 while (l--) if (events[l].name == eventName && events[l].f == fn) {
2747                     events[l].unbind();
2748                     events.splice(l, 1);
2749                     !events.length && delete this.events;
2750                     return this;
2751                 }
2752                 return this;
2753             };
2754         })(events[i]);
2755     }
2756     elproto.hover = function (f_in, f_out) {
2757         return this.mouseover(f_in).mouseout(f_out);
2758     };
2759     elproto.unhover = function (f_in, f_out) {
2760         return this.unmouseover(f_in).unmouseout(f_out);
2761     };
2762     elproto.drag = function (onmove, onstart, onend) {
2763         this._drag = {};
2764         this.mousedown(function (e) {
2765             (e.originalEvent || e).preventDefault();
2766             var scrollY = doc.documentElement.scrollTop || doc.body.scrollTop,
2767                 scrollX = doc.documentElement.scrollLeft || doc.body.scrollLeft;
2768             this._drag.x = e.clientX + scrollX;
2769             this._drag.y = e.clientY + scrollY;
2770             this._drag.id = e.identifier;
2771             onstart && onstart.call(this, e.clientX + scrollX, e.clientY + scrollY);
2772             !drag.length && R.mousemove(dragMove).mouseup(dragUp);
2773             drag.push({el: this, move: onmove, end: onend});
2774         });
2775         return this;
2776     };
2777     elproto.undrag = function (onmove, onstart, onend) {
2778         var i = drag.length;
2779         while (i--) {
2780             drag[i].el == this && (drag[i].move == onmove && drag[i].end == onend) && drag.splice(i++, 1);
2781         }
2782         !drag.length && R.unmousemove(dragMove).unmouseup(dragUp);
2783     };
2784     paperproto.circle = function (x, y, r) {
2785         return theCircle(this, x || 0, y || 0, r || 0);
2786     };
2787     paperproto.rect = function (x, y, w, h, r) {
2788         return theRect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
2789     };
2790     paperproto.ellipse = function (x, y, rx, ry) {
2791         return theEllipse(this, x || 0, y || 0, rx || 0, ry || 0);
2792     };
2793     paperproto.path = function (pathString) {
2794         pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
2795         return thePath(R.format[apply](R, arguments), this);
2796     };
2797     paperproto.image = function (src, x, y, w, h) {
2798         return theImage(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
2799     };
2800     paperproto.text = function (x, y, text) {
2801         return theText(this, x || 0, y || 0, Str(text));
2802     };
2803     paperproto.set = function (itemsArray) {
2804         arguments[length] > 1 && (itemsArray = Array[proto].splice.call(arguments, 0, arguments[length]));
2805         return new Set(itemsArray);
2806     };
2807     paperproto.setSize = setSize;
2808     paperproto.top = paperproto.bottom = null;
2809     paperproto.raphael = R;
2810     function x_y() {
2811         return this.x + S + this.y;
2812     }
2813     elproto.resetScale = function () {
2814         if (this.removed) {
2815             return this;
2816         }
2817         this._.sx = 1;
2818         this._.sy = 1;
2819         this.attrs.scale = "1 1";
2820     };
2821     elproto.scale = function (x, y, cx, cy) {
2822         if (this.removed) {
2823             return this;
2824         }
2825         if (x == null && y == null) {
2826             return {
2827                 x: this._.sx,
2828                 y: this._.sy,
2829                 toString: x_y
2830             };
2831         }
2832         y = y || x;
2833         !+y && (y = x);
2834         var dx,
2835             dy,
2836             dcx,
2837             dcy,
2838             a = this.attrs;
2839         if (x != 0) {
2840             var bb = this.getBBox(),
2841                 rcx = bb.x + bb.width / 2,
2842                 rcy = bb.y + bb.height / 2,
2843                 kx = abs(x / this._.sx),
2844                 ky = abs(y / this._.sy);
2845             cx = (+cx || cx == 0) ? cx : rcx;
2846             cy = (+cy || cy == 0) ? cy : rcy;
2847             var posx = this._.sx > 0,
2848                 posy = this._.sy > 0,
2849                 dirx = ~~(x / abs(x)),
2850                 diry = ~~(y / abs(y)),
2851                 dkx = kx * dirx,
2852                 dky = ky * diry,
2853                 s = this.node.style,
2854                 ncx = cx + abs(rcx - cx) * dkx * (rcx > cx == posx ? 1 : -1),
2855                 ncy = cy + abs(rcy - cy) * dky * (rcy > cy == posy ? 1 : -1),
2856                 fr = (x * dirx > y * diry ? ky : kx);
2857             switch (this.type) {
2858                 case "rect":
2859                 case "image":
2860                     var neww = a.width * kx,
2861                         newh = a.height * ky;
2862                     this.attr({
2863                         height: newh,
2864                         r: a.r * fr,
2865                         width: neww,
2866                         x: ncx - neww / 2,
2867                         y: ncy - newh / 2
2868                     });
2869                     break;
2870                 case "circle":
2871                 case "ellipse":
2872                     this.attr({
2873                         rx: a.rx * kx,
2874                         ry: a.ry * ky,
2875                         r: a.r * fr,
2876                         cx: ncx,
2877                         cy: ncy
2878                     });
2879                     break;
2880                 case "text":
2881                     this.attr({
2882                         x: ncx,
2883                         y: ncy
2884                     });
2885                     break;
2886                 case "path":
2887                     var path = pathToRelative(a.path),
2888                         skip = true,
2889                         fx = posx ? dkx : kx,
2890                         fy = posy ? dky : ky;
2891                     for (var i = 0, ii = path[length]; i < ii; i++) {
2892                         var p = path[i],
2893                             P0 = upperCase.call(p[0]);
2894                         if (P0 == "M" && skip) {
2895                             continue;
2896                         } else {
2897                             skip = false;
2898                         }
2899                         if (P0 == "A") {
2900                             p[path[i][length] - 2] *= fx;
2901                             p[path[i][length] - 1] *= fy;
2902                             p[1] *= kx;
2903                             p[2] *= ky;
2904                             p[5] = +(dirx + diry ? !+p[4] : !!+p[4]);
2905                         } else if (P0 == "H") {
2906                             for (var j = 1, jj = p[length]; j < jj; j++) {
2907                                 p[j] *= fx;
2908                             }
2909                         } else if (P0 == "V") {
2910                             for (j = 1, jj = p[length]; j < jj; j++) {
2911                                 p[j] *= fy;
2912                             }
2913                          } else {
2914                             for (j = 1, jj = p[length]; j < jj; j++) {
2915                                 p[j] *= (j % 2) ? fx : fy;
2916                             }
2917                         }
2918                     }
2919                     var dim2 = pathDimensions(path);
2920                     dx = ncx - dim2.x - dim2.width / 2;
2921                     dy = ncy - dim2.y - dim2.height / 2;
2922                     path[0][1] += dx;
2923                     path[0][2] += dy;
2924                     this.attr({path: path});
2925                 break;
2926             }
2927             if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2928                 if (this.transformations) {
2929                     this.transformations[2] = "scale("[concat](dirx, ",", diry, ")");
2930                     this.node[setAttribute]("transform", this.transformations[join](S));
2931                     dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2932                     dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2933                     this.attr({x: dx, y: dy});
2934                     a.fx = dirx - 1;
2935                     a.fy = diry - 1;
2936                 } else {
2937                     this.node.filterMatrix = ms + ".Matrix(M11="[concat](dirx,
2938                         ", M12=0, M21=0, M22=", diry,
2939                         ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2940                     s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
2941                 }
2942             } else {
2943                 if (this.transformations) {
2944                     this.transformations[2] = E;
2945                     this.node[setAttribute]("transform", this.transformations[join](S));
2946                     a.fx = 0;
2947                     a.fy = 0;
2948                 } else {
2949                     this.node.filterMatrix = E;
2950                     s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
2951                 }
2952             }
2953             a.scale = [x, y, cx, cy][join](S);
2954             this._.sx = x;
2955             this._.sy = y;
2956         }
2957         return this;
2958     };
2959     elproto.clone = function () {
2960         if (this.removed) {
2961             return null;
2962         }
2963         var attr = this.attr();
2964         delete attr.scale;
2965         delete attr.translation;
2966         return this.paper[this.type]().attr(attr);
2967     };
2968     var curveslengths = {},
2969     getPointAtSegmentLength = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
2970         var len = 0,
2971             precision = 100,
2972             name = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y].join(),
2973             cache = curveslengths[name],
2974             old, dot;
2975         !cache && (curveslengths[name] = cache = {data: []});
2976         cache.timer && clearTimeout(cache.timer);
2977         cache.timer = setTimeout(function () {delete curveslengths[name];}, 2000);
2978         if (length != null) {
2979             var total = getPointAtSegmentLength(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y);
2980             precision = ~~total * 10;
2981         }
2982         for (var i = 0; i < precision + 1; i++) {
2983             if (cache.data[length] > i) {
2984                 dot = cache.data[i * precision];
2985             } else {
2986                 dot = R.findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i / precision);
2987                 cache.data[i] = dot;
2988             }
2989             i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
2990             if (length != null && len >= length) {
2991                 return dot;
2992             }
2993             old = dot;
2994         }
2995         if (length == null) {
2996             return len;
2997         }
2998     },
2999     getLengthFactory = function (istotal, subpath) {
3000         return function (path, length, onlystart) {
3001             path = path2curve(path);
3002             var x, y, p, l, sp = "", subpaths = {}, point,
3003                 len = 0;
3004             for (var i = 0, ii = path.length; i < ii; i++) {
3005                 p = path[i];
3006                 if (p[0] == "M") {
3007                     x = +p[1];
3008                     y = +p[2];
3009                 } else {
3010                     l = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
3011                     if (len + l > length) {
3012                         if (subpath && !subpaths.start) {
3013                             point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
3014                             sp += ["C", point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
3015                             if (onlystart) {return sp;}
3016                             subpaths.start = sp;
3017                             sp = ["M", point.x, point.y + "C", point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]][join]();
3018                             len += l;
3019                             x = +p[5];
3020                             y = +p[6];
3021                             continue;
3022                         }
3023                         if (!istotal && !subpath) {
3024                             point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
3025                             return {x: point.x, y: point.y, alpha: point.alpha};
3026                         }
3027                     }
3028                     len += l;
3029                     x = +p[5];
3030                     y = +p[6];
3031                 }
3032                 sp += p;
3033             }
3034             subpaths.end = sp;
3035             point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[1], p[2], p[3], p[4], p[5], p[6], 1);
3036             point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha});
3037             return point;
3038         };
3039     };
3040     var getTotalLength = getLengthFactory(1),
3041         getPointAtLength = getLengthFactory(),
3042         getSubpathsAtLength = getLengthFactory(0, 1);
3043     elproto.getTotalLength = function () {
3044         if (this.type != "path") {return;}
3045         if (this.node.getTotalLength) {
3046             return this.node.getTotalLength();
3047         }
3048         return getTotalLength(this.attrs.path);
3049     };
3050     elproto.getPointAtLength = function (length) {
3051         if (this.type != "path") {return;}
3052         return getPointAtLength(this.attrs.path, length);
3053     };
3054     elproto.getSubpath = function (from, to) {
3055         if (this.type != "path") {return;}
3056         if (abs(this.getTotalLength() - to) < "1e-6") {
3057             return getSubpathsAtLength(this.attrs.path, from).end;
3058         }
3059         var a = getSubpathsAtLength(this.attrs.path, to, 1);
3060         return from ? getSubpathsAtLength(a, from).end : a;
3061     };
3062
3063     // animation easing formulas
3064     R.easing_formulas = {
3065         linear: function (n) {
3066             return n;
3067         },
3068         "<": function (n) {
3069             return pow(n, 3);
3070         },
3071         ">": function (n) {
3072             return pow(n - 1, 3) + 1;
3073         },
3074         "<>": function (n) {
3075             n = n * 2;
3076             if (n < 1) {
3077                 return pow(n, 3) / 2;
3078             }
3079             n -= 2;
3080             return (pow(n, 3) + 2) / 2;
3081         },
3082         backIn: function (n) {
3083             var s = 1.70158;
3084             return n * n * ((s + 1) * n - s);
3085         },
3086         backOut: function (n) {
3087             n = n - 1;
3088             var s = 1.70158;
3089             return n * n * ((s + 1) * n + s) + 1;
3090         },
3091         elastic: function (n) {
3092             if (n == 0 || n == 1) {
3093                 return n;
3094             }
3095             var p = .3,
3096                 s = p / 4;
3097             return pow(2, -10 * n) * math.sin((n - s) * (2 * math.PI) / p) + 1;
3098         },
3099         bounce: function (n) {
3100             var s = 7.5625,
3101                 p = 2.75,
3102                 l;
3103             if (n < (1 / p)) {
3104                 l = s * n * n;
3105             } else {
3106                 if (n < (2 / p)) {
3107                     n -= (1.5 / p);
3108                     l = s * n * n + .75;
3109                 } else {
3110                     if (n < (2.5 / p)) {
3111                         n -= (2.25 / p);
3112                         l = s * n * n + .9375;
3113                     } else {
3114                         n -= (2.625 / p);
3115                         l = s * n * n + .984375;
3116                     }
3117                 }
3118             }
3119             return l;
3120         }
3121     };
3122
3123     var animationElements = [],
3124         animation = function () {
3125             var Now = +new Date;
3126             for (var l = 0; l < animationElements[length]; l++) {
3127                 var e = animationElements[l];
3128                 if (e.stop || e.el.removed) {
3129                     continue;
3130                 }
3131                 var time = Now - e.start,
3132                     ms = e.ms,
3133                     easing = e.easing,
3134                     from = e.from,
3135                     diff = e.diff,
3136                     to = e.to,
3137                     t = e.t,
3138                     that = e.el,
3139                     set = {},
3140                     now;
3141                 if (time < ms) {
3142                     var pos = easing(time / ms);
3143                     for (var attr in from) if (from[has](attr)) {
3144                         switch (availableAnimAttrs[attr]) {
3145                             case "along":
3146                                 now = pos * ms * diff[attr];
3147                                 to.back && (now = to.len - now);
3148                                 var point = getPointAtLength(to[attr], now);
3149                                 that.translate(diff.sx - diff.x || 0, diff.sy - diff.y || 0);
3150                                 diff.x = point.x;
3151                                 diff.y = point.y;
3152                                 that.translate(point.x - diff.sx, point.y - diff.sy);
3153                                 to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
3154                                 break;
3155                             case nu:
3156                                 now = +from[attr] + pos * ms * diff[attr];
3157                                 break;
3158                             case "colour":
3159                                 now = "rgb(" + [
3160                                     upto255(round(from[attr].r + pos * ms * diff[attr].r)),
3161                                     upto255(round(from[attr].g + pos * ms * diff[attr].g)),
3162                                     upto255(round(from[attr].b + pos * ms * diff[attr].b))
3163                                 ][join](",") + ")";
3164                                 break;
3165                             case "path":
3166                                 now = [];
3167                                 for (var i = 0, ii = from[attr][length]; i < ii; i++) {
3168                                     now[i] = [from[attr][i][0]];
3169                                     for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
3170                                         now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
3171                                     }
3172                                     now[i] = now[i][join](S);
3173                                 }
3174                                 now = now[join](S);
3175                                 break;
3176                             case "csv":
3177                                 switch (attr) {
3178                                     case "translation":
3179                                         var x = pos * ms * diff[attr][0] - t.x,
3180                                             y = pos * ms * diff[attr][1] - t.y;
3181                                         t.x += x;
3182                                         t.y += y;
3183                                         now = x + S + y;
3184                                     break;
3185                                     case "rotation":
3186                                         now = +from[attr][0] + pos * ms * diff[attr][0];
3187                                         from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
3188                                     break;
3189                                     case "scale":
3190                                         now = [+from[attr][0] + pos * ms * diff[attr][0], +from[attr][1] + pos * ms * diff[attr][1], (2 in to[attr] ? to[attr][2] : E), (3 in to[attr] ? to[attr][3] : E)][join](S);
3191                                     break;
3192                                     case "clip-rect":
3193                                         now = [];
3194                                         i = 4;
3195                                         while (i--) {
3196                                             now[i] = +from[attr][i] + pos * ms * diff[attr][i];
3197                                         }
3198                                     break;
3199                                 }
3200                                 break;
3201                             default:
3202                               var from2 = [].concat(from[attr]);
3203                                 now = [];
3204                                 i = that.paper.customAttributes[attr].length;
3205                                 while (i--) {
3206                                     now[i] = +from2[i] + pos * ms * diff[attr][i];
3207                                 }
3208                                 break;
3209                         }
3210                         set[attr] = now;
3211                     }
3212                     that.attr(set);
3213                     that._run && that._run.call(that);
3214                 } else {
3215                     if (to.along) {
3216                         point = getPointAtLength(to.along, to.len * !to.back);
3217                         that.translate(diff.sx - (diff.x || 0) + point.x - diff.sx, diff.sy - (diff.y || 0) + point.y - diff.sy);
3218                         to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
3219                     }
3220                     (t.x || t.y) && that.translate(-t.x, -t.y);
3221                     to.scale && (to.scale += E);
3222                     that.attr(to);
3223                     animationElements.splice(l--, 1);
3224                 }
3225             }
3226             R.svg && that && that.paper && that.paper.safari();
3227             animationElements[length] && setTimeout(animation);
3228         },
3229         keyframesRun = function (attr, element, time, prev, prevcallback) {
3230             var dif = time - prev;
3231             element.timeouts.push(setTimeout(function () {
3232                 R.is(prevcallback, "function") && prevcallback.call(element);
3233                 element.animate(attr, dif, attr.easing);
3234             }, prev));
3235         },
3236         upto255 = function (color) {
3237             return mmax(mmin(color, 255), 0);
3238         },
3239         translate = function (x, y) {
3240             if (x == null) {
3241                 return {x: this._.tx, y: this._.ty, toString: x_y};
3242             }
3243             this._.tx += +x;
3244             this._.ty += +y;
3245             switch (this.type) {
3246                 case "circle":
3247                 case "ellipse":
3248                     this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy});
3249                     break;
3250                 case "rect":
3251                 case "image":
3252                 case "text":
3253                     this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y});
3254                     break;
3255                 case "path":
3256                     var path = pathToRelative(this.attrs.path);
3257                     path[0][1] += +x;
3258                     path[0][2] += +y;
3259                     this.attr({path: path});
3260                 break;
3261             }
3262             return this;
3263         };
3264     elproto.animateWith = function (element, params, ms, easing, callback) {
3265         for (var i = 0, ii = animationElements.length; i < ii; i++) {
3266             if (animationElements[i].el.id == element.id) {
3267                 params.start = animationElements[i].start;
3268             }
3269         }
3270         return this.animate(params, ms, easing, callback);
3271     };
3272     elproto.animateAlong = along();
3273     elproto.animateAlongBack = along(1);
3274     function along(isBack) {
3275         return function (path, ms, rotate, callback) {
3276             var params = {back: isBack};
3277             R.is(rotate, "function") ? (callback = rotate) : (params.rot = rotate);
3278             path && path.constructor == Element && (path = path.attrs.path);
3279             path && (params.along = path);
3280             return this.animate(params, ms, callback);
3281         };
3282     }
3283     function CubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
3284         var cx = 3 * p1x,
3285             bx = 3 * (p2x - p1x) - cx,
3286             ax = 1 - cx - bx,
3287             cy = 3 * p1y,
3288             by = 3 * (p2y - p1y) - cy,
3289             ay = 1 - cy - by;
3290         function sampleCurveX(t) {
3291             return ((ax * t + bx) * t + cx) * t;
3292         }
3293         function solve(x, epsilon) {
3294             var t = solveCurveX(x, epsilon);
3295             return ((ay * t + by) * t + cy) * t;
3296         }
3297         function solveCurveX(x, epsilon) {
3298             var t0, t1, t2, x2, d2, i;
3299             for(t2 = x, i = 0; i < 8; i++) {
3300                 x2 = sampleCurveX(t2) - x;
3301                 if (abs(x2) < epsilon) {
3302                     return t2;
3303                 }
3304                 d2 = (3 * ax * t2 + 2 * bx) * t2 + cx;
3305                 if (abs(d2) < 1e-6) {
3306                     break;
3307                 }
3308                 t2 = t2 - x2 / d2;
3309             }
3310             t0 = 0;
3311             t1 = 1;
3312             t2 = x;
3313             if (t2 < t0) {
3314                 return t0;
3315             }
3316             if (t2 > t1) {
3317                 return t1;
3318             }
3319             while (t0 < t1) {
3320                 x2 = sampleCurveX(t2);
3321                 if (abs(x2 - x) < epsilon) {
3322                     return t2;
3323                 }
3324                 if (x > x2) {
3325                     t0 = t2;
3326                 } else {
3327                     t1 = t2;
3328                 }
3329                 t2 = (t1 - t0) / 2 + t0;
3330             }
3331             return t2;
3332         }
3333         return solve(t, 1 / (200 * duration));
3334     }
3335     elproto.onAnimation = function (f) {
3336         this._run = f || 0;
3337         return this;
3338     };
3339     elproto.animate = function (params, ms, easing, callback) {
3340         var element = this;
3341         element.timeouts = element.timeouts || [];
3342         if (R.is(easing, "function") || !easing) {
3343             callback = easing || null;
3344         }
3345         if (element.removed) {
3346             callback && callback.call(element);
3347             return element;
3348         }
3349         var from = {},
3350             to = {},
3351             animateable = false,
3352             diff = {};
3353         for (var attr in params) if (params[has](attr)) {
3354             if (availableAnimAttrs[has](attr) || element.paper.customAttributes[has](attr)) {
3355                 animateable = true;
3356                 from[attr] = element.attr(attr);
3357                 (from[attr] == null) && (from[attr] = availableAttrs[attr]);
3358                 to[attr] = params[attr];
3359                 switch (availableAnimAttrs[attr]) {
3360                     case "along":
3361                         var len = getTotalLength(params[attr]);
3362                         var point = getPointAtLength(params[attr], len * !!params.back);
3363                         var bb = element.getBBox();
3364                         diff[attr] = len / ms;
3365                         diff.tx = bb.x;
3366                         diff.ty = bb.y;
3367                         diff.sx = point.x;
3368                         diff.sy = point.y;
3369                         to.rot = params.rot;
3370                         to.back = params.back;
3371                         to.len = len;
3372                         params.rot && (diff.r = toFloat(element.rotate()) || 0);
3373                         break;
3374                     case nu:
3375                         diff[attr] = (to[attr] - from[attr]) / ms;
3376                         break;
3377                     case "colour":
3378                         from[attr] = R.getRGB(from[attr]);
3379                         var toColour = R.getRGB(to[attr]);
3380                         diff[attr] = {
3381                             r: (toColour.r - from[attr].r) / ms,
3382                             g: (toColour.g - from[attr].g) / ms,
3383                             b: (toColour.b - from[attr].b) / ms
3384                         };
3385                         break;
3386                     case "path":
3387                         var pathes = path2curve(from[attr], to[attr]);
3388                         from[attr] = pathes[0];
3389                         var toPath = pathes[1];
3390                         diff[attr] = [];
3391                         for (var i = 0, ii = from[attr][length]; i < ii; i++) {
3392                             diff[attr][i] = [0];
3393                             for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
3394                                 diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
3395                             }
3396                         }
3397                         break;
3398                     case "csv":
3399                         var values = Str(params[attr])[split](separator),
3400                             from2 = Str(from[attr])[split](separator);
3401                         switch (attr) {
3402                             case "translation":
3403                                 from[attr] = [0, 0];
3404                                 diff[attr] = [values[0] / ms, values[1] / ms];
3405                             break;
3406                             case "rotation":
3407                                 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
3408                                 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
3409                             break;
3410                             case "scale":
3411                                 params[attr] = values;
3412                                 from[attr] = Str(from[attr])[split](separator);
3413                                 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
3414                             break;
3415                             case "clip-rect":
3416                                 from[attr] = Str(from[attr])[split](separator);
3417                                 diff[attr] = [];
3418                                 i = 4;
3419                                 while (i--) {
3420                                     diff[attr][i] = (values[i] - from[attr][i]) / ms;
3421                                 }
3422                             break;
3423                         }
3424                         to[attr] = values;
3425                         break;
3426                     default:
3427                         values = [].concat(params[attr]);
3428                         from2 = [].concat(from[attr]);
3429                         diff[attr] = [];
3430                         i = element.paper.customAttributes[attr][length];
3431                         while (i--) {
3432                             diff[attr][i] = ((values[i] || 0) - (from2[i] || 0)) / ms;
3433                         }
3434                         break;
3435                 }
3436             }
3437         }
3438         if (!animateable) {
3439             var attrs = [],
3440                 lastcall;
3441             for (var key in params) if (params[has](key) && animKeyFrames.test(key)) {
3442                 attr = {value: params[key]};
3443                 key == "from" && (key = 0);
3444                 key == "to" && (key = 100);
3445                 attr.key = toInt(key, 10);
3446                 attrs.push(attr);
3447             }
3448             attrs.sort(sortByKey);
3449             if (attrs[0].key) {
3450                 attrs.unshift({key: 0, value: element.attrs});
3451             }
3452             for (i = 0, ii = attrs[length]; i < ii; i++) {
3453                 keyframesRun(attrs[i].value, element, ms / 100 * attrs[i].key, ms / 100 * (attrs[i - 1] && attrs[i - 1].key || 0), attrs[i - 1] && attrs[i - 1].value.callback);
3454             }
3455             lastcall = attrs[attrs[length] - 1].value.callback;
3456             if (lastcall) {
3457                 element.timeouts.push(setTimeout(function () {lastcall.call(element);}, ms));
3458             }
3459         } else {
3460             var easyeasy = R.easing_formulas[easing];
3461             if (!easyeasy) {
3462                 easyeasy = Str(easing).match(bezierrg);
3463                 if (easyeasy && easyeasy[length] == 5) {
3464                     var curve = easyeasy;
3465                     easyeasy = function (t) {
3466                         return CubicBezierAtTime(t, +curve[1], +curve[2], +curve[3], +curve[4], ms);
3467                     };
3468                 } else {
3469                     easyeasy = function (t) {
3470                         return t;
3471                     };
3472                 }
3473             }
3474             animationElements.push({
3475                 start: params.start || +new Date,
3476                 ms: ms,
3477                 easing: easyeasy,
3478                 from: from,
3479                 diff: diff,
3480                 to: to,
3481                 el: element,
3482                 t: {x: 0, y: 0}
3483             });
3484             R.is(callback, "function") && (element._ac = setTimeout(function () {
3485                 callback.call(element);
3486             }, ms));
3487             animationElements[length] == 1 && setTimeout(animation);
3488         }
3489         return this;
3490     };
3491     elproto.stop = function () {
3492         for (var i = 0; i < animationElements.length; i++) {
3493             animationElements[i].el.id == this.id && animationElements.splice(i--, 1);
3494         }
3495         for (i = 0, ii = this.timeouts && this.timeouts.length; i < ii; i++) {
3496             clearTimeout(this.timeouts[i]);
3497         }
3498         this.timeouts = [];
3499         clearTimeout(this._ac);
3500         delete this._ac;
3501         return this;
3502     };
3503     elproto.translate = function (x, y) {
3504         return this.attr({translation: x + " " + y});
3505     };
3506     elproto[toString] = function () {
3507         return "Rapha\xebl\u2019s object";
3508     };
3509     R.ae = animationElements;
3510  
3511     // Set
3512     var Set = function (items) {
3513         this.items = [];
3514         this[length] = 0;
3515         this.type = "set";
3516         if (items) {
3517             for (var i = 0, ii = items[length]; i < ii; i++) {
3518                 if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
3519                     this[this.items[length]] = this.items[this.items[length]] = items[i];
3520                     this[length]++;
3521                 }
3522             }
3523         }
3524     };
3525     Set[proto][push] = function () {
3526         var item,
3527             len;
3528         for (var i = 0, ii = arguments[length]; i < ii; i++) {
3529             item = arguments[i];
3530             if (item && (item.constructor == Element || item.constructor == Set)) {
3531                 len = this.items[length];
3532                 this[len] = this.items[len] = item;
3533                 this[length]++;
3534             }
3535         }
3536         return this;
3537     };
3538     Set[proto].pop = function () {
3539         delete this[this[length]--];
3540         return this.items.pop();
3541     };
3542     for (var method in elproto) if (elproto[has](method)) {
3543         Set[proto][method] = (function (methodname) {
3544             return function () {
3545                 for (var i = 0, ii = this.items[length]; i < ii; i++) {
3546                     this.items[i][methodname][apply](this.items[i], arguments);
3547                 }
3548                 return this;
3549             };
3550         })(method);
3551     }
3552     Set[proto].attr = function (name, value) {
3553         if (name && R.is(name, array) && R.is(name[0], "object")) {
3554             for (var j = 0, jj = name[length]; j < jj; j++) {
3555                 this.items[j].attr(name[j]);
3556             }
3557         } else {
3558             for (var i = 0, ii = this.items[length]; i < ii; i++) {
3559                 this.items[i].attr(name, value);
3560             }
3561         }
3562         return this;
3563     };
3564     Set[proto].animate = function (params, ms, easing, callback) {
3565         (R.is(easing, "function") || !easing) && (callback = easing || null);
3566         var len = this.items[length],
3567             i = len,
3568             item,
3569             set = this,
3570             collector;
3571         callback && (collector = function () {
3572             !--len && callback.call(set);
3573         });
3574         easing = R.is(easing, string) ? easing : collector;
3575         item = this.items[--i].animate(params, ms, easing, collector);
3576         while (i--) {
3577             this.items[i] && !this.items[i].removed && this.items[i].animateWith(item, params, ms, easing, collector);
3578         }
3579         return this;
3580     };
3581     Set[proto].insertAfter = function (el) {
3582         var i = this.items[length];
3583         while (i--) {
3584             this.items[i].insertAfter(el);
3585         }
3586         return this;
3587     };
3588     Set[proto].getBBox = function () {
3589         var x = [],
3590             y = [],
3591             w = [],
3592             h = [];
3593         for (var i = this.items[length]; i--;) {
3594             var box = this.items[i].getBBox();
3595             x[push](box.x);
3596             y[push](box.y);
3597             w[push](box.x + box.width);
3598             h[push](box.y + box.height);
3599         }
3600         x = mmin[apply](0, x);
3601         y = mmin[apply](0, y);
3602         return {
3603             x: x,
3604             y: y,
3605             width: mmax[apply](0, w) - x,
3606             height: mmax[apply](0, h) - y
3607         };
3608     };
3609     Set[proto].clone = function (s) {
3610         s = new Set;
3611         for (var i = 0, ii = this.items[length]; i < ii; i++) {
3612             s[push](this.items[i].clone());
3613         }
3614         return s;
3615     };
3616
3617     R.registerFont = function (font) {
3618         if (!font.face) {
3619             return font;
3620         }
3621         this.fonts = this.fonts || {};
3622         var fontcopy = {
3623                 w: font.w,
3624                 face: {},
3625                 glyphs: {}
3626             },
3627             family = font.face["font-family"];
3628         for (var prop in font.face) if (font.face[has](prop)) {
3629             fontcopy.face[prop] = font.face[prop];
3630         }
3631         if (this.fonts[family]) {
3632             this.fonts[family][push](fontcopy);
3633         } else {
3634             this.fonts[family] = [fontcopy];
3635         }
3636         if (!font.svg) {
3637             fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
3638             for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
3639                 var path = font.glyphs[glyph];
3640                 fontcopy.glyphs[glyph] = {
3641                     w: path.w,
3642                     k: {},
3643                     d: path.d && "M" + path.d[rp](/[mlcxtrv]/g, function (command) {
3644                             return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
3645                         }) + "z"
3646                 };
3647                 if (path.k) {
3648                     for (var k in path.k) if (path[has](k)) {
3649                         fontcopy.glyphs[glyph].k[k] = path.k[k];
3650                     }
3651                 }
3652             }
3653         }
3654         return font;
3655     };
3656     paperproto.getFont = function (family, weight, style, stretch) {
3657         stretch = stretch || "normal";
3658         style = style || "normal";
3659         weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
3660         if (!R.fonts) {
3661             return;
3662         }
3663         var font = R.fonts[family];
3664         if (!font) {
3665             var name = new RegExp("(^|\\s)" + family[rp](/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
3666             for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
3667                 if (name.test(fontName)) {
3668                     font = R.fonts[fontName];
3669                     break;
3670                 }
3671             }
3672         }
3673         var thefont;
3674         if (font) {
3675             for (var i = 0, ii = font[length]; i < ii; i++) {
3676                 thefont = font[i];
3677                 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
3678                     break;
3679                 }
3680             }
3681         }
3682         return thefont;
3683     };
3684     paperproto.print = function (x, y, string, font, size, origin, letter_spacing) {
3685         origin = origin || "middle"; // baseline|middle
3686         letter_spacing = mmax(mmin(letter_spacing || 0, 1), -1);
3687         var out = this.set(),
3688             letters = Str(string)[split](E),
3689             shift = 0,
3690             path = E,
3691             scale;
3692         R.is(font, string) && (font = this.getFont(font));
3693         if (font) {
3694             scale = (size || 16) / font.face["units-per-em"];
3695             var bb = font.face.bbox.split(separator),
3696                 top = +bb[0],
3697                 height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
3698             for (var i = 0, ii = letters[length]; i < ii; i++) {
3699                 var prev = i && font.glyphs[letters[i - 1]] || {},
3700                     curr = font.glyphs[letters[i]];
3701                 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) + (font.w * letter_spacing) : 0;
3702                 curr && curr.d && out[push](this.path(curr.d).attr({fill: "#000", stroke: "none", translation: [shift, 0]}));
3703             }
3704             out.scale(scale, scale, top, height).translate(x - top, y - height);
3705         }
3706         return out;
3707     };
3708
3709     R.format = function (token, params) {
3710         var args = R.is(params, array) ? [0][concat](params) : arguments;
3711         token && R.is(token, string) && args[length] - 1 && (token = token[rp](formatrg, function (str, i) {
3712             return args[++i] == null ? E : args[i];
3713         }));
3714         return token || E;
3715     };
3716     R.ninja = function () {
3717         oldRaphael.was ? (win.Raphael = oldRaphael.is) : delete Raphael;
3718         return R;
3719     };
3720     R.el = elproto;
3721     R.st = Set[proto];
3722
3723     oldRaphael.was ? (win.Raphael = R) : (Raphael = R);
3724 })();