fixed stroke-opacity when opacity and gradient are defined.
[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                             if (attrs.gradient && !attrs[has]("stroke-opacity")) {
1424                                 $(node, {"stroke-opacity": value > 1 ? value / 100 : value});
1425                             }
1426                             // fall
1427                         case "fill-opacity":
1428                             if (attrs.gradient) {
1429                                 var gradient = doc.getElementById(node.getAttribute(fillString)[rp](/^url\(#|\)$/g, E));
1430                                 if (gradient) {
1431                                     var stops = gradient.getElementsByTagName("stop");
1432                                     stops[stops[length] - 1][setAttribute]("stop-opacity", value);
1433                                 }
1434                                 break;
1435                             }
1436                         default:
1437                             att == "font-size" && (value = toInt(value, 10) + "px");
1438                             var cssrule = att[rp](/(\-.)/g, function (w) {
1439                                 return upperCase.call(w.substring(1));
1440                             });
1441                             node.style[cssrule] = value;
1442                             // Need following line for Firefox
1443                             node[setAttribute](att, value);
1444                             break;
1445                     }
1446                 }
1447             }
1448             
1449             tuneText(o, params);
1450             if (rotxy) {
1451                 o.rotate(rotxy.join(S));
1452             } else {
1453                 toFloat(rot) && o.rotate(rot, true);
1454             }
1455         };
1456         var leading = 1.2,
1457         tuneText = function (el, params) {
1458             if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
1459                 return;
1460             }
1461             var a = el.attrs,
1462                 node = el.node,
1463                 fontSize = node.firstChild ? toInt(doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
1464  
1465             if (params[has]("text")) {
1466                 a.text = params.text;
1467                 while (node.firstChild) {
1468                     node.removeChild(node.firstChild);
1469                 }
1470                 var texts = Str(params.text)[split]("\n");
1471                 for (var i = 0, ii = texts[length]; i < ii; i++) if (texts[i]) {
1472                     var tspan = $("tspan");
1473                     i && $(tspan, {dy: fontSize * leading, x: a.x});
1474                     tspan[appendChild](doc.createTextNode(texts[i]));
1475                     node[appendChild](tspan);
1476                 }
1477             } else {
1478                 texts = node.getElementsByTagName("tspan");
1479                 for (i = 0, ii = texts[length]; i < ii; i++) {
1480                     i && $(texts[i], {dy: fontSize * leading, x: a.x});
1481                 }
1482             }
1483             $(node, {y: a.y});
1484             var bb = el.getBBox(),
1485                 dif = a.y - (bb.y + bb.height / 2);
1486             dif && isFinite(dif) && $(node, {y: a.y + dif});
1487         },
1488         Element = function (node, svg) {
1489             var X = 0,
1490                 Y = 0;
1491             this[0] = node;
1492             this.id = R._oid++;
1493             this.node = node;
1494             node.raphael = this;
1495             this.paper = svg;
1496             this.attrs = this.attrs || {};
1497             this.transformations = []; // rotate, translate, scale
1498             this._ = {
1499                 tx: 0,
1500                 ty: 0,
1501                 rt: {deg: 0, cx: 0, cy: 0},
1502                 sx: 1,
1503                 sy: 1
1504             };
1505             !svg.bottom && (svg.bottom = this);
1506             this.prev = svg.top;
1507             svg.top && (svg.top.next = this);
1508             svg.top = this;
1509             this.next = null;
1510         };
1511         var elproto = Element[proto];
1512         Element[proto].rotate = function (deg, cx, cy) {
1513             if (this.removed) {
1514                 return this;
1515             }
1516             if (deg == null) {
1517                 if (this._.rt.cx) {
1518                     return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
1519                 }
1520                 return this._.rt.deg;
1521             }
1522             var bbox = this.getBBox();
1523             deg = Str(deg)[split](separator);
1524             if (deg[length] - 1) {
1525                 cx = toFloat(deg[1]);
1526                 cy = toFloat(deg[2]);
1527             }
1528             deg = toFloat(deg[0]);
1529             if (cx != null && cx !== false) {
1530                 this._.rt.deg = deg;
1531             } else {
1532                 this._.rt.deg += deg;
1533             }
1534             (cy == null) && (cx = null);
1535             this._.rt.cx = cx;
1536             this._.rt.cy = cy;
1537             cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1538             cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1539             if (this._.rt.deg) {
1540                 this.transformations[0] = R.format("rotate({0} {1} {2})", this._.rt.deg, cx, cy);
1541                 this.clip && $(this.clip, {transform: R.format("rotate({0} {1} {2})", -this._.rt.deg, cx, cy)});
1542             } else {
1543                 this.transformations[0] = E;
1544                 this.clip && $(this.clip, {transform: E});
1545             }
1546             $(this.node, {transform: this.transformations[join](S)});
1547             return this;
1548         };
1549         Element[proto].hide = function () {
1550             !this.removed && (this.node.style.display = "none");
1551             return this;
1552         };
1553         Element[proto].show = function () {
1554             !this.removed && (this.node.style.display = "");
1555             return this;
1556         };
1557         Element[proto].remove = function () {
1558             if (this.removed) {
1559                 return;
1560             }
1561             tear(this, this.paper);
1562             this.node.parentNode.removeChild(this.node);
1563             for (var i in this) {
1564                 delete this[i];
1565             }
1566             this.removed = true;
1567         };
1568         Element[proto].getBBox = function () {
1569             if (this.removed) {
1570                 return this;
1571             }
1572             if (this.type == "path") {
1573                 return pathDimensions(this.attrs.path);
1574             }
1575             if (this.node.style.display == "none") {
1576                 this.show();
1577                 var hide = true;
1578             }
1579             var bbox = {};
1580             try {
1581                 bbox = this.node.getBBox();
1582             } catch(e) {
1583                 // Firefox 3.0.x plays badly here
1584             } finally {
1585                 bbox = bbox || {};
1586             }
1587             if (this.type == "text") {
1588                 bbox = {x: bbox.x, y: Infinity, width: 0, height: 0};
1589                 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1590                     var bb = this.node.getExtentOfChar(i);
1591                     (bb.y < bbox.y) && (bbox.y = bb.y);
1592                     (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1593                     (bb.x + bb.width - bbox.x > bbox.width) && (bbox.width = bb.x + bb.width - bbox.x);
1594                 }
1595             }
1596             hide && this.hide();
1597             return bbox;
1598         };
1599         Element[proto].attr = function (name, value) {
1600             if (this.removed) {
1601                 return this;
1602             }
1603             if (name == null) {
1604                 var res = {};
1605                 for (var i in this.attrs) if (this.attrs[has](i)) {
1606                     res[i] = this.attrs[i];
1607                 }
1608                 this._.rt.deg && (res.rotation = this.rotate());
1609                 (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
1610                 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
1611                 return res;
1612             }
1613             if (value == null && R.is(name, string)) {
1614                 if (name == "translation") {
1615                     return translate.call(this);
1616                 }
1617                 if (name == "rotation") {
1618                     return this.rotate();
1619                 }
1620                 if (name == "scale") {
1621                     return this.scale();
1622                 }
1623                 if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
1624                     return this.attrs.gradient;
1625                 }
1626                 return this.attrs[name];
1627             }
1628             if (value == null && R.is(name, array)) {
1629                 var values = {};
1630                 for (var j = 0, jj = name.length; j < jj; j++) {
1631                     values[name[j]] = this.attr(name[j]);
1632                 }
1633                 return values;
1634             }
1635             if (value != null) {
1636                 var params = {};
1637                 params[name] = value;
1638             } else if (name != null && R.is(name, "object")) {
1639                 params = name;
1640             }
1641             for (var key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
1642                 var par = this.paper.customAttributes[key].apply(this, [][concat](params[key]));
1643                 this.attrs[key] = params[key];
1644                 for (var subkey in par) if (par[has](subkey)) {
1645                     params[subkey] = par[subkey];
1646                 }
1647             }
1648             setFillAndStroke(this, params);
1649             return this;
1650         };
1651         Element[proto].toFront = function () {
1652             if (this.removed) {
1653                 return this;
1654             }
1655             this.node.parentNode[appendChild](this.node);
1656             var svg = this.paper;
1657             svg.top != this && tofront(this, svg);
1658             return this;
1659         };
1660         Element[proto].toBack = function () {
1661             if (this.removed) {
1662                 return this;
1663             }
1664             if (this.node.parentNode.firstChild != this.node) {
1665                 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1666                 toback(this, this.paper);
1667                 var svg = this.paper;
1668             }
1669             return this;
1670         };
1671         Element[proto].insertAfter = function (element) {
1672             if (this.removed) {
1673                 return this;
1674             }
1675             var node = element.node || element[element.length - 1].node;
1676             if (node.nextSibling) {
1677                 node.parentNode.insertBefore(this.node, node.nextSibling);
1678             } else {
1679                 node.parentNode[appendChild](this.node);
1680             }
1681             insertafter(this, element, this.paper);
1682             return this;
1683         };
1684         Element[proto].insertBefore = function (element) {
1685             if (this.removed) {
1686                 return this;
1687             }
1688             var node = element.node || element[0].node;
1689             node.parentNode.insertBefore(this.node, node);
1690             insertbefore(this, element, this.paper);
1691             return this;
1692         };
1693         Element[proto].blur = function (size) {
1694             // Experimental. No Safari support. Use it on your own risk.
1695             var t = this;
1696             if (+size !== 0) {
1697                 var fltr = $("filter"),
1698                     blur = $("feGaussianBlur");
1699                 t.attrs.blur = size;
1700                 fltr.id = createUUID();
1701                 $(blur, {stdDeviation: +size || 1.5});
1702                 fltr.appendChild(blur);
1703                 t.paper.defs.appendChild(fltr);
1704                 t._blur = fltr;
1705                 $(t.node, {filter: "url(#" + fltr.id + ")"});
1706             } else {
1707                 if (t._blur) {
1708                     t._blur.parentNode.removeChild(t._blur);
1709                     delete t._blur;
1710                     delete t.attrs.blur;
1711                 }
1712                 t.node.removeAttribute("filter");
1713             }
1714         };
1715         var theCircle = function (svg, x, y, r) {
1716             var el = $("circle");
1717             svg.canvas && svg.canvas[appendChild](el);
1718             var res = new Element(el, svg);
1719             res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
1720             res.type = "circle";
1721             $(el, res.attrs);
1722             return res;
1723         },
1724         theRect = function (svg, x, y, w, h, r) {
1725             var el = $("rect");
1726             svg.canvas && svg.canvas[appendChild](el);
1727             var res = new Element(el, svg);
1728             res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
1729             res.type = "rect";
1730             $(el, res.attrs);
1731             return res;
1732         },
1733         theEllipse = function (svg, x, y, rx, ry) {
1734             var el = $("ellipse");
1735             svg.canvas && svg.canvas[appendChild](el);
1736             var res = new Element(el, svg);
1737             res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
1738             res.type = "ellipse";
1739             $(el, res.attrs);
1740             return res;
1741         },
1742         theImage = function (svg, src, x, y, w, h) {
1743             var el = $("image");
1744             $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
1745             el.setAttributeNS(svg.xlink, "href", src);
1746             svg.canvas && svg.canvas[appendChild](el);
1747             var res = new Element(el, svg);
1748             res.attrs = {x: x, y: y, width: w, height: h, src: src};
1749             res.type = "image";
1750             return res;
1751         },
1752         theText = function (svg, x, y, text) {
1753             var el = $("text");
1754             $(el, {x: x, y: y, "text-anchor": "middle"});
1755             svg.canvas && svg.canvas[appendChild](el);
1756             var res = new Element(el, svg);
1757             res.attrs = {x: x, y: y, "text-anchor": "middle", text: text, font: availableAttrs.font, stroke: "none", fill: "#000"};
1758             res.type = "text";
1759             setFillAndStroke(res, res.attrs);
1760             return res;
1761         },
1762         setSize = function (width, height) {
1763             this.width = width || this.width;
1764             this.height = height || this.height;
1765             this.canvas[setAttribute]("width", this.width);
1766             this.canvas[setAttribute]("height", this.height);
1767             return this;
1768         },
1769         create = function () {
1770             var con = getContainer[apply](0, arguments),
1771                 container = con && con.container,
1772                 x = con.x,
1773                 y = con.y,
1774                 width = con.width,
1775                 height = con.height;
1776             if (!container) {
1777                 throw new Error("SVG container not found.");
1778             }
1779             var cnvs = $("svg");
1780             x = x || 0;
1781             y = y || 0;
1782             width = width || 512;
1783             height = height || 342;
1784             $(cnvs, {
1785                 xmlns: "http://www.w3.org/2000/svg",
1786                 version: 1.1,
1787                 width: width,
1788                 height: height
1789             });
1790             if (container == 1) {
1791                 cnvs.style.cssText = "position:absolute;left:" + x + "px;top:" + y + "px";
1792                 doc.body[appendChild](cnvs);
1793             } else {
1794                 if (container.firstChild) {
1795                     container.insertBefore(cnvs, container.firstChild);
1796                 } else {
1797                     container[appendChild](cnvs);
1798                 }
1799             }
1800             container = new Paper;
1801             container.width = width;
1802             container.height = height;
1803             container.canvas = cnvs;
1804             plugins.call(container, container, R.fn);
1805             container.clear();
1806             return container;
1807         };
1808         paperproto.clear = function () {
1809             var c = this.canvas;
1810             while (c.firstChild) {
1811                 c.removeChild(c.firstChild);
1812             }
1813             this.bottom = this.top = null;
1814             (this.desc = $("desc"))[appendChild](doc.createTextNode("Created with Rapha\xebl"));
1815             c[appendChild](this.desc);
1816             c[appendChild](this.defs = $("defs"));
1817         };
1818         paperproto.remove = function () {
1819             this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
1820             for (var i in this) {
1821                 this[i] = removed(i);
1822             }
1823         };
1824     }
1825
1826     // VML
1827     if (R.vml) {
1828         var map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
1829             bites = /([clmz]),?([^clmz]*)/gi,
1830             blurregexp = / progid:\S+Blur\([^\)]+\)/g,
1831             val = /-?[^,\s-]+/g,
1832             coordsize = 1e3 + S + 1e3,
1833             zoom = 10,
1834             pathlike = {path: 1, rect: 1},
1835             path2vml = function (path) {
1836                 var total =  /[ahqstv]/ig,
1837                     command = pathToAbsolute;
1838                 Str(path).match(total) && (command = path2curve);
1839                 total = /[clmz]/g;
1840                 if (command == pathToAbsolute && !Str(path).match(total)) {
1841                     var res = Str(path)[rp](bites, function (all, command, args) {
1842                         var vals = [],
1843                             isMove = lowerCase.call(command) == "m",
1844                             res = map[command];
1845                         args[rp](val, function (value) {
1846                             if (isMove && vals[length] == 2) {
1847                                 res += vals + map[command == "m" ? "l" : "L"];
1848                                 vals = [];
1849                             }
1850                             vals[push](round(value * zoom));
1851                         });
1852                         return res + vals;
1853                     });
1854                     return res;
1855                 }
1856                 var pa = command(path), p, r;
1857                 res = [];
1858                 for (var i = 0, ii = pa[length]; i < ii; i++) {
1859                     p = pa[i];
1860                     r = lowerCase.call(pa[i][0]);
1861                     r == "z" && (r = "x");
1862                     for (var j = 1, jj = p[length]; j < jj; j++) {
1863                         r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
1864                     }
1865                     res[push](r);
1866                 }
1867                 return res[join](S);
1868             };
1869         
1870         R[toString] = function () {
1871             return  "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
1872         };
1873         thePath = function (pathString, vml) {
1874             var g = createNode("group");
1875             g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
1876             g.coordsize = vml.coordsize;
1877             g.coordorigin = vml.coordorigin;
1878             var el = createNode("shape"), ol = el.style;
1879             ol.width = vml.width + "px";
1880             ol.height = vml.height + "px";
1881             el.coordsize = coordsize;
1882             el.coordorigin = vml.coordorigin;
1883             g[appendChild](el);
1884             var p = new Element(el, g, vml),
1885                 attr = {fill: "none", stroke: "#000"};
1886             pathString && (attr.path = pathString);
1887             p.type = "path";
1888             p.path = [];
1889             p.Path = E;
1890             setFillAndStroke(p, attr);
1891             vml.canvas[appendChild](g);
1892             return p;
1893         };
1894         setFillAndStroke = function (o, params) {
1895             o.attrs = o.attrs || {};
1896             var node = o.node,
1897                 a = o.attrs,
1898                 s = node.style,
1899                 xy,
1900                 newpath = (params.x != a.x || params.y != a.y || params.width != a.width || params.height != a.height || params.r != a.r) && o.type == "rect",
1901                 res = o;
1902
1903             for (var par in params) if (params[has](par)) {
1904                 a[par] = params[par];
1905             }
1906             if (newpath) {
1907                 a.path = rectPath(a.x, a.y, a.width, a.height, a.r);
1908                 o.X = a.x;
1909                 o.Y = a.y;
1910                 o.W = a.width;
1911                 o.H = a.height;
1912             }
1913             params.href && (node.href = params.href);
1914             params.title && (node.title = params.title);
1915             params.target && (node.target = params.target);
1916             params.cursor && (s.cursor = params.cursor);
1917             "blur" in params && o.blur(params.blur);
1918             if (params.path && o.type == "path" || newpath) {
1919                 node.path = path2vml(a.path);
1920             }
1921             if (params.rotation != null) {
1922                 o.rotate(params.rotation, true);
1923             }
1924             if (params.translation) {
1925                 xy = Str(params.translation)[split](separator);
1926                 translate.call(o, xy[0], xy[1]);
1927                 if (o._.rt.cx != null) {
1928                     o._.rt.cx +=+ xy[0];
1929                     o._.rt.cy +=+ xy[1];
1930                     o.setBox(o.attrs, xy[0], xy[1]);
1931                 }
1932             }
1933             if (params.scale) {
1934                 xy = Str(params.scale)[split](separator);
1935                 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1936             }
1937             if ("clip-rect" in params) {
1938                 var rect = Str(params["clip-rect"])[split](separator);
1939                 if (rect[length] == 4) {
1940                     rect[2] = +rect[2] + (+rect[0]);
1941                     rect[3] = +rect[3] + (+rect[1]);
1942                     var div = node.clipRect || doc.createElement("div"),
1943                         dstyle = div.style,
1944                         group = node.parentNode;
1945                     dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
1946                     if (!node.clipRect) {
1947                         dstyle.position = "absolute";
1948                         dstyle.top = 0;
1949                         dstyle.left = 0;
1950                         dstyle.width = o.paper.width + "px";
1951                         dstyle.height = o.paper.height + "px";
1952                         group.parentNode.insertBefore(div, group);
1953                         div[appendChild](group);
1954                         node.clipRect = div;
1955                     }
1956                 }
1957                 if (!params["clip-rect"]) {
1958                     node.clipRect && (node.clipRect.style.clip = E);
1959                 }
1960             }
1961             if (o.type == "image" && params.src) {
1962                 node.src = params.src;
1963             }
1964             if (o.type == "image" && params.opacity) {
1965                 node.filterOpacity = ms + ".Alpha(opacity=" + (params.opacity * 100) + ")";
1966                 s.filter = (node.filterMatrix || E) + (node.filterOpacity || E);
1967             }
1968             params.font && (s.font = params.font);
1969             params["font-family"] && (s.fontFamily = '"' + params["font-family"][split](",")[0][rp](/^['"]+|['"]+$/g, E) + '"');
1970             params["font-size"] && (s.fontSize = params["font-size"]);
1971             params["font-weight"] && (s.fontWeight = params["font-weight"]);
1972             params["font-style"] && (s.fontStyle = params["font-style"]);
1973             if (params.opacity != null || 
1974                 params["stroke-width"] != null ||
1975                 params.fill != null ||
1976                 params.stroke != null ||
1977                 params["stroke-width"] != null ||
1978                 params["stroke-opacity"] != null ||
1979                 params["fill-opacity"] != null ||
1980                 params["stroke-dasharray"] != null ||
1981                 params["stroke-miterlimit"] != null ||
1982                 params["stroke-linejoin"] != null ||
1983                 params["stroke-linecap"] != null) {
1984                 node = o.shape || node;
1985                 var fill = (node.getElementsByTagName(fillString) && node.getElementsByTagName(fillString)[0]),
1986                     newfill = false;
1987                 !fill && (newfill = fill = createNode(fillString));
1988                 if ("fill-opacity" in params || "opacity" in params) {
1989                     var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
1990                     opacity = mmin(mmax(opacity, 0), 1);
1991                     fill.opacity = opacity;
1992                 }
1993                 params.fill && (fill.on = true);
1994                 if (fill.on == null || params.fill == "none") {
1995                     fill.on = false;
1996                 }
1997                 if (fill.on && params.fill) {
1998                     var isURL = params.fill.match(ISURL);
1999                     if (isURL) {
2000                         fill.src = isURL[1];
2001                         fill.type = "tile";
2002                     } else {
2003                         fill.color = R.getRGB(params.fill).hex;
2004                         fill.src = E;
2005                         fill.type = "solid";
2006                         if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || Str(params.fill).charAt() != "r") && addGradientFill(res, params.fill)) {
2007                             a.fill = "none";
2008                             a.gradient = params.fill;
2009                         }
2010                     }
2011                 }
2012                 newfill && node[appendChild](fill);
2013                 var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
2014                 newstroke = false;
2015                 !stroke && (newstroke = stroke = createNode("stroke"));
2016                 if ((params.stroke && params.stroke != "none") ||
2017                     params["stroke-width"] ||
2018                     params["stroke-opacity"] != null ||
2019                     params["stroke-dasharray"] ||
2020                     params["stroke-miterlimit"] ||
2021                     params["stroke-linejoin"] ||
2022                     params["stroke-linecap"]) {
2023                     stroke.on = true;
2024                 }
2025                 (params.stroke == "none" || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
2026                 var strokeColor = R.getRGB(params.stroke);
2027                 stroke.on && params.stroke && (stroke.color = strokeColor.hex);
2028                 opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
2029                 var width = (toFloat(params["stroke-width"]) || 1) * .75;
2030                 opacity = mmin(mmax(opacity, 0), 1);
2031                 params["stroke-width"] == null && (width = a["stroke-width"]);
2032                 params["stroke-width"] && (stroke.weight = width);
2033                 width && width < 1 && (opacity *= width) && (stroke.weight = 1);
2034                 stroke.opacity = opacity;
2035                 
2036                 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
2037                 stroke.miterlimit = params["stroke-miterlimit"] || 8;
2038                 params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
2039                 if (params["stroke-dasharray"]) {
2040                     var dasharray = {
2041                         "-": "shortdash",
2042                         ".": "shortdot",
2043                         "-.": "shortdashdot",
2044                         "-..": "shortdashdotdot",
2045                         ". ": "dot",
2046                         "- ": "dash",
2047                         "--": "longdash",
2048                         "- .": "dashdot",
2049                         "--.": "longdashdot",
2050                         "--..": "longdashdotdot"
2051                     };
2052                     stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
2053                 }
2054                 newstroke && node[appendChild](stroke);
2055             }
2056             if (res.type == "text") {
2057                 s = res.paper.span.style;
2058                 a.font && (s.font = a.font);
2059                 a["font-family"] && (s.fontFamily = a["font-family"]);
2060                 a["font-size"] && (s.fontSize = a["font-size"]);
2061                 a["font-weight"] && (s.fontWeight = a["font-weight"]);
2062                 a["font-style"] && (s.fontStyle = a["font-style"]);
2063                 res.node.string && (res.paper.span.innerHTML = Str(res.node.string)[rp](/</g, "&#60;")[rp](/&/g, "&#38;")[rp](/\n/g, "<br>"));
2064                 res.W = a.w = res.paper.span.offsetWidth;
2065                 res.H = a.h = res.paper.span.offsetHeight;
2066                 res.X = a.x;
2067                 res.Y = a.y + round(res.H / 2);
2068  
2069                 // text-anchor emulationm
2070                 switch (a["text-anchor"]) {
2071                     case "start":
2072                         res.node.style["v-text-align"] = "left";
2073                         res.bbx = round(res.W / 2);
2074                     break;
2075                     case "end":
2076                         res.node.style["v-text-align"] = "right";
2077                         res.bbx = -round(res.W / 2);
2078                     break;
2079                     default:
2080                         res.node.style["v-text-align"] = "center";
2081                     break;
2082                 }
2083             }
2084         };
2085         addGradientFill = function (o, gradient) {
2086             o.attrs = o.attrs || {};
2087             var attrs = o.attrs,
2088                 fill,
2089                 type = "linear",
2090                 fxfy = ".5 .5";
2091             o.attrs.gradient = gradient;
2092             gradient = Str(gradient)[rp](radial_gradient, function (all, fx, fy) {
2093                 type = "radial";
2094                 if (fx && fy) {
2095                     fx = toFloat(fx);
2096                     fy = toFloat(fy);
2097                     pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
2098                     fxfy = fx + S + fy;
2099                 }
2100                 return E;
2101             });
2102             gradient = gradient[split](/\s*\-\s*/);
2103             if (type == "linear") {
2104                 var angle = gradient.shift();
2105                 angle = -toFloat(angle);
2106                 if (isNaN(angle)) {
2107                     return null;
2108                 }
2109             }
2110             var dots = parseDots(gradient);
2111             if (!dots) {
2112                 return null;
2113             }
2114             o = o.shape || o.node;
2115             fill = o.getElementsByTagName(fillString)[0] || createNode(fillString);
2116             !fill.parentNode && o.appendChild(fill);
2117             if (dots[length]) {
2118                 fill.on = true;
2119                 fill.method = "none";
2120                 fill.color = dots[0].color;
2121                 fill.color2 = dots[dots[length] - 1].color;
2122                 var clrs = [];
2123                 for (var i = 0, ii = dots[length]; i < ii; i++) {
2124                     dots[i].offset && clrs[push](dots[i].offset + S + dots[i].color);
2125                 }
2126                 fill.colors && (fill.colors.value = clrs[length] ? clrs[join]() : "0% " + fill.color);
2127                 if (type == "radial") {
2128                     fill.type = "gradientradial";
2129                     fill.focus = "100%";
2130                     fill.focussize = fxfy;
2131                     fill.focusposition = fxfy;
2132                 } else {
2133                     fill.type = "gradient";
2134                     fill.angle = (270 - angle) % 360;
2135                 }
2136             }
2137             return 1;
2138         };
2139         Element = function (node, group, vml) {
2140             var Rotation = 0,
2141                 RotX = 0,
2142                 RotY = 0,
2143                 Scale = 1;
2144             this[0] = node;
2145             this.id = R._oid++;
2146             this.node = node;
2147             node.raphael = this;
2148             this.X = 0;
2149             this.Y = 0;
2150             this.attrs = {};
2151             this.Group = group;
2152             this.paper = vml;
2153             this._ = {
2154                 tx: 0,
2155                 ty: 0,
2156                 rt: {deg:0},
2157                 sx: 1,
2158                 sy: 1
2159             };
2160             !vml.bottom && (vml.bottom = this);
2161             this.prev = vml.top;
2162             vml.top && (vml.top.next = this);
2163             vml.top = this;
2164             this.next = null;
2165         };
2166         elproto = Element[proto];
2167         elproto.rotate = function (deg, cx, cy) {
2168             if (this.removed) {
2169                 return this;
2170             }
2171             if (deg == null) {
2172                 if (this._.rt.cx) {
2173                     return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
2174                 }
2175                 return this._.rt.deg;
2176             }
2177             deg = Str(deg)[split](separator);
2178             if (deg[length] - 1) {
2179                 cx = toFloat(deg[1]);
2180                 cy = toFloat(deg[2]);
2181             }
2182             deg = toFloat(deg[0]);
2183             if (cx != null) {
2184                 this._.rt.deg = deg;
2185             } else {
2186                 this._.rt.deg += deg;
2187             }
2188             cy == null && (cx = null);
2189             this._.rt.cx = cx;
2190             this._.rt.cy = cy;
2191             this.setBox(this.attrs, cx, cy);
2192             this.Group.style.rotation = this._.rt.deg;
2193             // gradient fix for rotation. TODO
2194             // var fill = (this.shape || this.node).getElementsByTagName(fillString);
2195             // fill = fill[0] || {};
2196             // var b = ((360 - this._.rt.deg) - 270) % 360;
2197             // !R.is(fill.angle, "undefined") && (fill.angle = b);
2198             return this;
2199         };
2200         elproto.setBox = function (params, cx, cy) {
2201             if (this.removed) {
2202                 return this;
2203             }
2204             var gs = this.Group.style,
2205                 os = (this.shape && this.shape.style) || this.node.style;
2206             params = params || {};
2207             for (var i in params) if (params[has](i)) {
2208                 this.attrs[i] = params[i];
2209             }
2210             cx = cx || this._.rt.cx;
2211             cy = cy || this._.rt.cy;
2212             var attr = this.attrs,
2213                 x,
2214                 y,
2215                 w,
2216                 h;
2217             switch (this.type) {
2218                 case "circle":
2219                     x = attr.cx - attr.r;
2220                     y = attr.cy - attr.r;
2221                     w = h = attr.r * 2;
2222                     break;
2223                 case "ellipse":
2224                     x = attr.cx - attr.rx;
2225                     y = attr.cy - attr.ry;
2226                     w = attr.rx * 2;
2227                     h = attr.ry * 2;
2228                     break;
2229                 case "image":
2230                     x = +attr.x;
2231                     y = +attr.y;
2232                     w = attr.width || 0;
2233                     h = attr.height || 0;
2234                     break;
2235                 case "text":
2236                     this.textpath.v = ["m", round(attr.x), ", ", round(attr.y - 2), "l", round(attr.x) + 1, ", ", round(attr.y - 2)][join](E);
2237                     x = attr.x - round(this.W / 2);
2238                     y = attr.y - this.H / 2;
2239                     w = this.W;
2240                     h = this.H;
2241                     break;
2242                 case "rect":
2243                 case "path":
2244                     if (!this.attrs.path) {
2245                         x = 0;
2246                         y = 0;
2247                         w = this.paper.width;
2248                         h = this.paper.height;
2249                     } else {
2250                         var dim = pathDimensions(this.attrs.path);
2251                         x = dim.x;
2252                         y = dim.y;
2253                         w = dim.width;
2254                         h = dim.height;
2255                     }
2256                     break;
2257                 default:
2258                     x = 0;
2259                     y = 0;
2260                     w = this.paper.width;
2261                     h = this.paper.height;
2262                     break;
2263             }
2264             cx = (cx == null) ? x + w / 2 : cx;
2265             cy = (cy == null) ? y + h / 2 : cy;
2266             var left = cx - this.paper.width / 2,
2267                 top = cy - this.paper.height / 2, t;
2268             gs.left != (t = left + "px") && (gs.left = t);
2269             gs.top != (t = top + "px") && (gs.top = t);
2270             this.X = pathlike[has](this.type) ? -left : x;
2271             this.Y = pathlike[has](this.type) ? -top : y;
2272             this.W = w;
2273             this.H = h;
2274             if (pathlike[has](this.type)) {
2275                 os.left != (t = -left * zoom + "px") && (os.left = t);
2276                 os.top != (t = -top * zoom + "px") && (os.top = t);
2277             } else if (this.type == "text") {
2278                 os.left != (t = -left + "px") && (os.left = t);
2279                 os.top != (t = -top + "px") && (os.top = t);
2280             } else {
2281                 gs.width != (t = this.paper.width + "px") && (gs.width = t);
2282                 gs.height != (t = this.paper.height + "px") && (gs.height = t);
2283                 os.left != (t = x - left + "px") && (os.left = t);
2284                 os.top != (t = y - top + "px") && (os.top = t);
2285                 os.width != (t = w + "px") && (os.width = t);
2286                 os.height != (t = h + "px") && (os.height = t);
2287             }
2288         };
2289         elproto.hide = function () {
2290             !this.removed && (this.Group.style.display = "none");
2291             return this;
2292         };
2293         elproto.show = function () {
2294             !this.removed && (this.Group.style.display = "block");
2295             return this;
2296         };
2297         elproto.getBBox = function () {
2298             if (this.removed) {
2299                 return this;
2300             }
2301             if (pathlike[has](this.type)) {
2302                 return pathDimensions(this.attrs.path);
2303             }
2304             return {
2305                 x: this.X + (this.bbx || 0),
2306                 y: this.Y,
2307                 width: this.W,
2308                 height: this.H
2309             };
2310         };
2311         elproto.remove = function () {
2312             if (this.removed) {
2313                 return;
2314             }
2315             tear(this, this.paper);
2316             this.node.parentNode.removeChild(this.node);
2317             this.Group.parentNode.removeChild(this.Group);
2318             this.shape && this.shape.parentNode.removeChild(this.shape);
2319             for (var i in this) {
2320                 delete this[i];
2321             }
2322             this.removed = true;
2323         };
2324         elproto.attr = function (name, value) {
2325             if (this.removed) {
2326                 return this;
2327             }
2328             if (name == null) {
2329                 var res = {};
2330                 for (var i in this.attrs) if (this.attrs[has](i)) {
2331                     res[i] = this.attrs[i];
2332                 }
2333                 this._.rt.deg && (res.rotation = this.rotate());
2334                 (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
2335                 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
2336                 return res;
2337             }
2338             if (value == null && R.is(name, "string")) {
2339                 if (name == "translation") {
2340                     return translate.call(this);
2341                 }
2342                 if (name == "rotation") {
2343                     return this.rotate();
2344                 }
2345                 if (name == "scale") {
2346                     return this.scale();
2347                 }
2348                 if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
2349                     return this.attrs.gradient;
2350                 }
2351                 return this.attrs[name];
2352             }
2353             if (this.attrs && value == null && R.is(name, array)) {
2354                 var ii, values = {};
2355                 for (i = 0, ii = name[length]; i < ii; i++) {
2356                     values[name[i]] = this.attr(name[i]);
2357                 }
2358                 return values;
2359             }
2360             var params;
2361             if (value != null) {
2362                 params = {};
2363                 params[name] = value;
2364             }
2365             value == null && R.is(name, "object") && (params = name);
2366             if (params) {
2367                 for (var key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
2368                     var par = this.paper.customAttributes[key].apply(this, [][concat](params[key]));
2369                     this.attrs[key] = params[key];
2370                     for (var subkey in par) if (par[has](subkey)) {
2371                         params[subkey] = par[subkey];
2372                     }
2373                 }
2374                 if (params.text && this.type == "text") {
2375                     this.node.string = params.text;
2376                 }
2377                 setFillAndStroke(this, params);
2378                 if (params.gradient && (({circle: 1, ellipse: 1})[has](this.type) || Str(params.gradient).charAt() != "r")) {
2379                     addGradientFill(this, params.gradient);
2380                 }
2381                 (!pathlike[has](this.type) || this._.rt.deg) && this.setBox(this.attrs);
2382             }
2383             return this;
2384         };
2385         elproto.toFront = function () {
2386             !this.removed && this.Group.parentNode[appendChild](this.Group);
2387             this.paper.top != this && tofront(this, this.paper);
2388             return this;
2389         };
2390         elproto.toBack = function () {
2391             if (this.removed) {
2392                 return this;
2393             }
2394             if (this.Group.parentNode.firstChild != this.Group) {
2395                 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
2396                 toback(this, this.paper);
2397             }
2398             return this;
2399         };
2400         elproto.insertAfter = function (element) {
2401             if (this.removed) {
2402                 return this;
2403             }
2404             if (element.constructor == Set) {
2405                 element = element[element.length - 1];
2406             }
2407             if (element.Group.nextSibling) {
2408                 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
2409             } else {
2410                 element.Group.parentNode[appendChild](this.Group);
2411             }
2412             insertafter(this, element, this.paper);
2413             return this;
2414         };
2415         elproto.insertBefore = function (element) {
2416             if (this.removed) {
2417                 return this;
2418             }
2419             if (element.constructor == Set) {
2420                 element = element[0];
2421             }
2422             element.Group.parentNode.insertBefore(this.Group, element.Group);
2423             insertbefore(this, element, this.paper);
2424             return this;
2425         };
2426         elproto.blur = function (size) {
2427             var s = this.node.runtimeStyle,
2428                 f = s.filter;
2429             f = f.replace(blurregexp, E);
2430             if (+size !== 0) {
2431                 this.attrs.blur = size;
2432                 s.filter = f + S + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
2433                 s.margin = R.format("-{0}px 0 0 -{0}px", round(+size || 1.5));
2434             } else {
2435                 s.filter = f;
2436                 s.margin = 0;
2437                 delete this.attrs.blur;
2438             }
2439         };
2440  
2441         theCircle = function (vml, x, y, r) {
2442             var g = createNode("group"),
2443                 o = createNode("oval"),
2444                 ol = o.style;
2445             g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2446             g.coordsize = coordsize;
2447             g.coordorigin = vml.coordorigin;
2448             g[appendChild](o);
2449             var res = new Element(o, g, vml);
2450             res.type = "circle";
2451             setFillAndStroke(res, {stroke: "#000", fill: "none"});
2452             res.attrs.cx = x;
2453             res.attrs.cy = y;
2454             res.attrs.r = r;
2455             res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
2456             vml.canvas[appendChild](g);
2457             return res;
2458         };
2459         function rectPath(x, y, w, h, r) {
2460             if (r) {
2461                 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);
2462             } else {
2463                 return R.format("M{0},{1}l{2},0,0,{3},{4},0z", x, y, w, h, -w);
2464             }
2465         }
2466         theRect = function (vml, x, y, w, h, r) {
2467             var path = rectPath(x, y, w, h, r),
2468                 res = vml.path(path),
2469                 a = res.attrs;
2470             res.X = a.x = x;
2471             res.Y = a.y = y;
2472             res.W = a.width = w;
2473             res.H = a.height = h;
2474             a.r = r;
2475             a.path = path;
2476             res.type = "rect";
2477             return res;
2478         };
2479         theEllipse = function (vml, x, y, rx, ry) {
2480             var g = createNode("group"),
2481                 o = createNode("oval"),
2482                 ol = o.style;
2483             g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2484             g.coordsize = coordsize;
2485             g.coordorigin = vml.coordorigin;
2486             g[appendChild](o);
2487             var res = new Element(o, g, vml);
2488             res.type = "ellipse";
2489             setFillAndStroke(res, {stroke: "#000"});
2490             res.attrs.cx = x;
2491             res.attrs.cy = y;
2492             res.attrs.rx = rx;
2493             res.attrs.ry = ry;
2494             res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
2495             vml.canvas[appendChild](g);
2496             return res;
2497         };
2498         theImage = function (vml, src, x, y, w, h) {
2499             var g = createNode("group"),
2500                 o = createNode("image");
2501             g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2502             g.coordsize = coordsize;
2503             g.coordorigin = vml.coordorigin;
2504             o.src = src;
2505             g[appendChild](o);
2506             var res = new Element(o, g, vml);
2507             res.type = "image";
2508             res.attrs.src = src;
2509             res.attrs.x = x;
2510             res.attrs.y = y;
2511             res.attrs.w = w;
2512             res.attrs.h = h;
2513             res.setBox({x: x, y: y, width: w, height: h});
2514             vml.canvas[appendChild](g);
2515             return res;
2516         };
2517         theText = function (vml, x, y, text) {
2518             var g = createNode("group"),
2519                 el = createNode("shape"),
2520                 ol = el.style,
2521                 path = createNode("path"),
2522                 ps = path.style,
2523                 o = createNode("textpath");
2524             g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2525             g.coordsize = coordsize;
2526             g.coordorigin = vml.coordorigin;
2527             path.v = R.format("m{0},{1}l{2},{1}", round(x * 10), round(y * 10), round(x * 10) + 1);
2528             path.textpathok = true;
2529             ol.width = vml.width;
2530             ol.height = vml.height;
2531             o.string = Str(text);
2532             o.on = true;
2533             el[appendChild](o);
2534             el[appendChild](path);
2535             g[appendChild](el);
2536             var res = new Element(o, g, vml);
2537             res.shape = el;
2538             res.textpath = path;
2539             res.type = "text";
2540             res.attrs.text = text;
2541             res.attrs.x = x;
2542             res.attrs.y = y;
2543             res.attrs.w = 1;
2544             res.attrs.h = 1;
2545             setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2546             res.setBox();
2547             vml.canvas[appendChild](g);
2548             return res;
2549         };
2550         setSize = function (width, height) {
2551             var cs = this.canvas.style;
2552             width == +width && (width += "px");
2553             height == +height && (height += "px");
2554             cs.width = width;
2555             cs.height = height;
2556             cs.clip = "rect(0 " + width + " " + height + " 0)";
2557             return this;
2558         };
2559         var createNode;
2560         doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2561         try {
2562             !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2563             createNode = function (tagName) {
2564                 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2565             };
2566         } catch (e) {
2567             createNode = function (tagName) {
2568                 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2569             };
2570         }
2571         create = function () {
2572             var con = getContainer[apply](0, arguments),
2573                 container = con.container,
2574                 height = con.height,
2575                 s,
2576                 width = con.width,
2577                 x = con.x,
2578                 y = con.y;
2579             if (!container) {
2580                 throw new Error("VML container not found.");
2581             }
2582             var res = new Paper,
2583                 c = res.canvas = doc.createElement("div"),
2584                 cs = c.style;
2585             x = x || 0;
2586             y = y || 0;
2587             width = width || 512;
2588             height = height || 342;
2589             width == +width && (width += "px");
2590             height == +height && (height += "px");
2591             res.width = 1e3;
2592             res.height = 1e3;
2593             res.coordsize = zoom * 1e3 + S + zoom * 1e3;
2594             res.coordorigin = "0 0";
2595             res.span = doc.createElement("span");
2596             res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
2597             c[appendChild](res.span);
2598             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);
2599             if (container == 1) {
2600                 doc.body[appendChild](c);
2601                 cs.left = x + "px";
2602                 cs.top = y + "px";
2603                 cs.position = "absolute";
2604             } else {
2605                 if (container.firstChild) {
2606                     container.insertBefore(c, container.firstChild);
2607                 } else {
2608                     container[appendChild](c);
2609                 }
2610             }
2611             plugins.call(res, res, R.fn);
2612             return res;
2613         };
2614         paperproto.clear = function () {
2615             this.canvas.innerHTML = E;
2616             this.span = doc.createElement("span");
2617             this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
2618             this.canvas[appendChild](this.span);
2619             this.bottom = this.top = null;
2620         };
2621         paperproto.remove = function () {
2622             this.canvas.parentNode.removeChild(this.canvas);
2623             for (var i in this) {
2624                 this[i] = removed(i);
2625             }
2626             return true;
2627         };
2628     }
2629  
2630     // rest
2631     // WebKit rendering bug workaround method
2632     var version = navigator.userAgent.match(/Version\/(.*?)\s/);
2633     if ((navigator.vendor == "Apple Computer, Inc.") && (version && version[1] < 4 || navigator.platform.slice(0, 2) == "iP")) {
2634         paperproto.safari = function () {
2635             var rect = this.rect(-99, -99, this.width + 99, this.height + 99).attr({stroke: "none"});
2636             win.setTimeout(function () {rect.remove();});
2637         };
2638     } else {
2639         paperproto.safari = function () {};
2640     }
2641  
2642     // Events
2643     var preventDefault = function () {
2644         this.returnValue = false;
2645     },
2646     preventTouch = function () {
2647         return this.originalEvent.preventDefault();
2648     },
2649     stopPropagation = function () {
2650         this.cancelBubble = true;
2651     },
2652     stopTouch = function () {
2653         return this.originalEvent.stopPropagation();
2654     },
2655     addEvent = (function () {
2656         if (doc.addEventListener) {
2657             return function (obj, type, fn, element) {
2658                 var realName = supportsTouch && touchMap[type] ? touchMap[type] : type;
2659                 var f = function (e) {
2660                     if (supportsTouch && touchMap[has](type)) {
2661                         for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
2662                             if (e.targetTouches[i].target == obj) {
2663                                 var olde = e;
2664                                 e = e.targetTouches[i];
2665                                 e.originalEvent = olde;
2666                                 e.preventDefault = preventTouch;
2667                                 e.stopPropagation = stopTouch;
2668                                 break;
2669                             }
2670                         }
2671                     }
2672                     return fn.call(element, e);
2673                 };
2674                 obj.addEventListener(realName, f, false);
2675                 return function () {
2676                     obj.removeEventListener(realName, f, false);
2677                     return true;
2678                 };
2679             };
2680         } else if (doc.attachEvent) {
2681             return function (obj, type, fn, element) {
2682                 var f = function (e) {
2683                     e = e || win.event;
2684                     e.preventDefault = e.preventDefault || preventDefault;
2685                     e.stopPropagation = e.stopPropagation || stopPropagation;
2686                     return fn.call(element, e);
2687                 };
2688                 obj.attachEvent("on" + type, f);
2689                 var detacher = function () {
2690                     obj.detachEvent("on" + type, f);
2691                     return true;
2692                 };
2693                 return detacher;
2694             };
2695         }
2696     })(),
2697     drag = [],
2698     dragMove = function (e) {
2699         var x = e.clientX,
2700             y = e.clientY,
2701             scrollY = doc.documentElement.scrollTop || doc.body.scrollTop,
2702             scrollX = doc.documentElement.scrollLeft || doc.body.scrollLeft,
2703             dragi,
2704             j = drag.length;
2705         while (j--) {
2706             dragi = drag[j];
2707             if (supportsTouch) {
2708                 var i = e.touches.length,
2709                     touch;
2710                 while (i--) {
2711                     touch = e.touches[i];
2712                     if (touch.identifier == dragi.el._drag.id) {
2713                         x = touch.clientX;
2714                         y = touch.clientY;
2715                         (e.originalEvent ? e.originalEvent : e).preventDefault();
2716                         break;
2717                     }
2718                 }
2719             } else {
2720                 e.preventDefault();
2721             }
2722             x += scrollX;
2723             y += scrollY;
2724             dragi.move && dragi.move.call(dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y);
2725         }
2726     },
2727     dragUp = function () {
2728         R.unmousemove(dragMove).unmouseup(dragUp);
2729         var i = drag.length,
2730             dragi;
2731         while (i--) {
2732             dragi = drag[i];
2733             dragi.el._drag = {};
2734             dragi.end && dragi.end.call(dragi.el);
2735         }
2736         drag = [];
2737     };
2738     for (var i = events[length]; i--;) {
2739         (function (eventName) {
2740             R[eventName] = Element[proto][eventName] = function (fn) {
2741                 if (R.is(fn, "function")) {
2742                     this.events = this.events || [];
2743                     this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || doc, eventName, fn, this)});
2744                 }
2745                 return this;
2746             };
2747             R["un" + eventName] = Element[proto]["un" + eventName] = function (fn) {
2748                 var events = this.events,
2749                     l = events[length];
2750                 while (l--) if (events[l].name == eventName && events[l].f == fn) {
2751                     events[l].unbind();
2752                     events.splice(l, 1);
2753                     !events.length && delete this.events;
2754                     return this;
2755                 }
2756                 return this;
2757             };
2758         })(events[i]);
2759     }
2760     elproto.hover = function (f_in, f_out) {
2761         return this.mouseover(f_in).mouseout(f_out);
2762     };
2763     elproto.unhover = function (f_in, f_out) {
2764         return this.unmouseover(f_in).unmouseout(f_out);
2765     };
2766     elproto.drag = function (onmove, onstart, onend) {
2767         this._drag = {};
2768         this.mousedown(function (e) {
2769             (e.originalEvent || e).preventDefault();
2770             var scrollY = doc.documentElement.scrollTop || doc.body.scrollTop,
2771                 scrollX = doc.documentElement.scrollLeft || doc.body.scrollLeft;
2772             this._drag.x = e.clientX + scrollX;
2773             this._drag.y = e.clientY + scrollY;
2774             this._drag.id = e.identifier;
2775             onstart && onstart.call(this, e.clientX + scrollX, e.clientY + scrollY);
2776             !drag.length && R.mousemove(dragMove).mouseup(dragUp);
2777             drag.push({el: this, move: onmove, end: onend});
2778         });
2779         return this;
2780     };
2781     elproto.undrag = function (onmove, onstart, onend) {
2782         var i = drag.length;
2783         while (i--) {
2784             drag[i].el == this && (drag[i].move == onmove && drag[i].end == onend) && drag.splice(i++, 1);
2785         }
2786         !drag.length && R.unmousemove(dragMove).unmouseup(dragUp);
2787     };
2788     paperproto.circle = function (x, y, r) {
2789         return theCircle(this, x || 0, y || 0, r || 0);
2790     };
2791     paperproto.rect = function (x, y, w, h, r) {
2792         return theRect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
2793     };
2794     paperproto.ellipse = function (x, y, rx, ry) {
2795         return theEllipse(this, x || 0, y || 0, rx || 0, ry || 0);
2796     };
2797     paperproto.path = function (pathString) {
2798         pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
2799         return thePath(R.format[apply](R, arguments), this);
2800     };
2801     paperproto.image = function (src, x, y, w, h) {
2802         return theImage(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
2803     };
2804     paperproto.text = function (x, y, text) {
2805         return theText(this, x || 0, y || 0, Str(text));
2806     };
2807     paperproto.set = function (itemsArray) {
2808         arguments[length] > 1 && (itemsArray = Array[proto].splice.call(arguments, 0, arguments[length]));
2809         return new Set(itemsArray);
2810     };
2811     paperproto.setSize = setSize;
2812     paperproto.top = paperproto.bottom = null;
2813     paperproto.raphael = R;
2814     function x_y() {
2815         return this.x + S + this.y;
2816     }
2817     elproto.resetScale = function () {
2818         if (this.removed) {
2819             return this;
2820         }
2821         this._.sx = 1;
2822         this._.sy = 1;
2823         this.attrs.scale = "1 1";
2824     };
2825     elproto.scale = function (x, y, cx, cy) {
2826         if (this.removed) {
2827             return this;
2828         }
2829         if (x == null && y == null) {
2830             return {
2831                 x: this._.sx,
2832                 y: this._.sy,
2833                 toString: x_y
2834             };
2835         }
2836         y = y || x;
2837         !+y && (y = x);
2838         var dx,
2839             dy,
2840             dcx,
2841             dcy,
2842             a = this.attrs;
2843         if (x != 0) {
2844             var bb = this.getBBox(),
2845                 rcx = bb.x + bb.width / 2,
2846                 rcy = bb.y + bb.height / 2,
2847                 kx = abs(x / this._.sx),
2848                 ky = abs(y / this._.sy);
2849             cx = (+cx || cx == 0) ? cx : rcx;
2850             cy = (+cy || cy == 0) ? cy : rcy;
2851             var posx = this._.sx > 0,
2852                 posy = this._.sy > 0,
2853                 dirx = ~~(x / abs(x)),
2854                 diry = ~~(y / abs(y)),
2855                 dkx = kx * dirx,
2856                 dky = ky * diry,
2857                 s = this.node.style,
2858                 ncx = cx + abs(rcx - cx) * dkx * (rcx > cx == posx ? 1 : -1),
2859                 ncy = cy + abs(rcy - cy) * dky * (rcy > cy == posy ? 1 : -1),
2860                 fr = (x * dirx > y * diry ? ky : kx);
2861             switch (this.type) {
2862                 case "rect":
2863                 case "image":
2864                     var neww = a.width * kx,
2865                         newh = a.height * ky;
2866                     this.attr({
2867                         height: newh,
2868                         r: a.r * fr,
2869                         width: neww,
2870                         x: ncx - neww / 2,
2871                         y: ncy - newh / 2
2872                     });
2873                     break;
2874                 case "circle":
2875                 case "ellipse":
2876                     this.attr({
2877                         rx: a.rx * kx,
2878                         ry: a.ry * ky,
2879                         r: a.r * fr,
2880                         cx: ncx,
2881                         cy: ncy
2882                     });
2883                     break;
2884                 case "text":
2885                     this.attr({
2886                         x: ncx,
2887                         y: ncy
2888                     });
2889                     break;
2890                 case "path":
2891                     var path = pathToRelative(a.path),
2892                         skip = true,
2893                         fx = posx ? dkx : kx,
2894                         fy = posy ? dky : ky;
2895                     for (var i = 0, ii = path[length]; i < ii; i++) {
2896                         var p = path[i],
2897                             P0 = upperCase.call(p[0]);
2898                         if (P0 == "M" && skip) {
2899                             continue;
2900                         } else {
2901                             skip = false;
2902                         }
2903                         if (P0 == "A") {
2904                             p[path[i][length] - 2] *= fx;
2905                             p[path[i][length] - 1] *= fy;
2906                             p[1] *= kx;
2907                             p[2] *= ky;
2908                             p[5] = +(dirx + diry ? !+p[4] : !!+p[4]);
2909                         } else if (P0 == "H") {
2910                             for (var j = 1, jj = p[length]; j < jj; j++) {
2911                                 p[j] *= fx;
2912                             }
2913                         } else if (P0 == "V") {
2914                             for (j = 1, jj = p[length]; j < jj; j++) {
2915                                 p[j] *= fy;
2916                             }
2917                          } else {
2918                             for (j = 1, jj = p[length]; j < jj; j++) {
2919                                 p[j] *= (j % 2) ? fx : fy;
2920                             }
2921                         }
2922                     }
2923                     var dim2 = pathDimensions(path);
2924                     dx = ncx - dim2.x - dim2.width / 2;
2925                     dy = ncy - dim2.y - dim2.height / 2;
2926                     path[0][1] += dx;
2927                     path[0][2] += dy;
2928                     this.attr({path: path});
2929                 break;
2930             }
2931             if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2932                 if (this.transformations) {
2933                     this.transformations[2] = "scale("[concat](dirx, ",", diry, ")");
2934                     this.node[setAttribute]("transform", this.transformations[join](S));
2935                     dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2936                     dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2937                     this.attr({x: dx, y: dy});
2938                     a.fx = dirx - 1;
2939                     a.fy = diry - 1;
2940                 } else {
2941                     this.node.filterMatrix = ms + ".Matrix(M11="[concat](dirx,
2942                         ", M12=0, M21=0, M22=", diry,
2943                         ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2944                     s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
2945                 }
2946             } else {
2947                 if (this.transformations) {
2948                     this.transformations[2] = E;
2949                     this.node[setAttribute]("transform", this.transformations[join](S));
2950                     a.fx = 0;
2951                     a.fy = 0;
2952                 } else {
2953                     this.node.filterMatrix = E;
2954                     s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
2955                 }
2956             }
2957             a.scale = [x, y, cx, cy][join](S);
2958             this._.sx = x;
2959             this._.sy = y;
2960         }
2961         return this;
2962     };
2963     elproto.clone = function () {
2964         if (this.removed) {
2965             return null;
2966         }
2967         var attr = this.attr();
2968         delete attr.scale;
2969         delete attr.translation;
2970         return this.paper[this.type]().attr(attr);
2971     };
2972     var curveslengths = {},
2973     getPointAtSegmentLength = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
2974         var len = 0,
2975             precision = 100,
2976             name = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y].join(),
2977             cache = curveslengths[name],
2978             old, dot;
2979         !cache && (curveslengths[name] = cache = {data: []});
2980         cache.timer && clearTimeout(cache.timer);
2981         cache.timer = setTimeout(function () {delete curveslengths[name];}, 2000);
2982         if (length != null) {
2983             var total = getPointAtSegmentLength(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y);
2984             precision = ~~total * 10;
2985         }
2986         for (var i = 0; i < precision + 1; i++) {
2987             if (cache.data[length] > i) {
2988                 dot = cache.data[i * precision];
2989             } else {
2990                 dot = R.findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i / precision);
2991                 cache.data[i] = dot;
2992             }
2993             i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
2994             if (length != null && len >= length) {
2995                 return dot;
2996             }
2997             old = dot;
2998         }
2999         if (length == null) {
3000             return len;
3001         }
3002     },
3003     getLengthFactory = function (istotal, subpath) {
3004         return function (path, length, onlystart) {
3005             path = path2curve(path);
3006             var x, y, p, l, sp = "", subpaths = {}, point,
3007                 len = 0;
3008             for (var i = 0, ii = path.length; i < ii; i++) {
3009                 p = path[i];
3010                 if (p[0] == "M") {
3011                     x = +p[1];
3012                     y = +p[2];
3013                 } else {
3014                     l = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
3015                     if (len + l > length) {
3016                         if (subpath && !subpaths.start) {
3017                             point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
3018                             sp += ["C", point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
3019                             if (onlystart) {return sp;}
3020                             subpaths.start = sp;
3021                             sp = ["M", point.x, point.y + "C", point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]][join]();
3022                             len += l;
3023                             x = +p[5];
3024                             y = +p[6];
3025                             continue;
3026                         }
3027                         if (!istotal && !subpath) {
3028                             point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
3029                             return {x: point.x, y: point.y, alpha: point.alpha};
3030                         }
3031                     }
3032                     len += l;
3033                     x = +p[5];
3034                     y = +p[6];
3035                 }
3036                 sp += p;
3037             }
3038             subpaths.end = sp;
3039             point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[1], p[2], p[3], p[4], p[5], p[6], 1);
3040             point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha});
3041             return point;
3042         };
3043     };
3044     var getTotalLength = getLengthFactory(1),
3045         getPointAtLength = getLengthFactory(),
3046         getSubpathsAtLength = getLengthFactory(0, 1);
3047     elproto.getTotalLength = function () {
3048         if (this.type != "path") {return;}
3049         if (this.node.getTotalLength) {
3050             return this.node.getTotalLength();
3051         }
3052         return getTotalLength(this.attrs.path);
3053     };
3054     elproto.getPointAtLength = function (length) {
3055         if (this.type != "path") {return;}
3056         return getPointAtLength(this.attrs.path, length);
3057     };
3058     elproto.getSubpath = function (from, to) {
3059         if (this.type != "path") {return;}
3060         if (abs(this.getTotalLength() - to) < "1e-6") {
3061             return getSubpathsAtLength(this.attrs.path, from).end;
3062         }
3063         var a = getSubpathsAtLength(this.attrs.path, to, 1);
3064         return from ? getSubpathsAtLength(a, from).end : a;
3065     };
3066
3067     // animation easing formulas
3068     R.easing_formulas = {
3069         linear: function (n) {
3070             return n;
3071         },
3072         "<": function (n) {
3073             return pow(n, 3);
3074         },
3075         ">": function (n) {
3076             return pow(n - 1, 3) + 1;
3077         },
3078         "<>": function (n) {
3079             n = n * 2;
3080             if (n < 1) {
3081                 return pow(n, 3) / 2;
3082             }
3083             n -= 2;
3084             return (pow(n, 3) + 2) / 2;
3085         },
3086         backIn: function (n) {
3087             var s = 1.70158;
3088             return n * n * ((s + 1) * n - s);
3089         },
3090         backOut: function (n) {
3091             n = n - 1;
3092             var s = 1.70158;
3093             return n * n * ((s + 1) * n + s) + 1;
3094         },
3095         elastic: function (n) {
3096             if (n == 0 || n == 1) {
3097                 return n;
3098             }
3099             var p = .3,
3100                 s = p / 4;
3101             return pow(2, -10 * n) * math.sin((n - s) * (2 * math.PI) / p) + 1;
3102         },
3103         bounce: function (n) {
3104             var s = 7.5625,
3105                 p = 2.75,
3106                 l;
3107             if (n < (1 / p)) {
3108                 l = s * n * n;
3109             } else {
3110                 if (n < (2 / p)) {
3111                     n -= (1.5 / p);
3112                     l = s * n * n + .75;
3113                 } else {
3114                     if (n < (2.5 / p)) {
3115                         n -= (2.25 / p);
3116                         l = s * n * n + .9375;
3117                     } else {
3118                         n -= (2.625 / p);
3119                         l = s * n * n + .984375;
3120                     }
3121                 }
3122             }
3123             return l;
3124         }
3125     };
3126
3127     var animationElements = [],
3128         animation = function () {
3129             var Now = +new Date;
3130             for (var l = 0; l < animationElements[length]; l++) {
3131                 var e = animationElements[l];
3132                 if (e.stop || e.el.removed) {
3133                     continue;
3134                 }
3135                 var time = Now - e.start,
3136                     ms = e.ms,
3137                     easing = e.easing,
3138                     from = e.from,
3139                     diff = e.diff,
3140                     to = e.to,
3141                     t = e.t,
3142                     that = e.el,
3143                     set = {},
3144                     now;
3145                 if (time < ms) {
3146                     var pos = easing(time / ms);
3147                     for (var attr in from) if (from[has](attr)) {
3148                         switch (availableAnimAttrs[attr]) {
3149                             case "along":
3150                                 now = pos * ms * diff[attr];
3151                                 to.back && (now = to.len - now);
3152                                 var point = getPointAtLength(to[attr], now);
3153                                 that.translate(diff.sx - diff.x || 0, diff.sy - diff.y || 0);
3154                                 diff.x = point.x;
3155                                 diff.y = point.y;
3156                                 that.translate(point.x - diff.sx, point.y - diff.sy);
3157                                 to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
3158                                 break;
3159                             case nu:
3160                                 now = +from[attr] + pos * ms * diff[attr];
3161                                 break;
3162                             case "colour":
3163                                 now = "rgb(" + [
3164                                     upto255(round(from[attr].r + pos * ms * diff[attr].r)),
3165                                     upto255(round(from[attr].g + pos * ms * diff[attr].g)),
3166                                     upto255(round(from[attr].b + pos * ms * diff[attr].b))
3167                                 ][join](",") + ")";
3168                                 break;
3169                             case "path":
3170                                 now = [];
3171                                 for (var i = 0, ii = from[attr][length]; i < ii; i++) {
3172                                     now[i] = [from[attr][i][0]];
3173                                     for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
3174                                         now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
3175                                     }
3176                                     now[i] = now[i][join](S);
3177                                 }
3178                                 now = now[join](S);
3179                                 break;
3180                             case "csv":
3181                                 switch (attr) {
3182                                     case "translation":
3183                                         var x = pos * ms * diff[attr][0] - t.x,
3184                                             y = pos * ms * diff[attr][1] - t.y;
3185                                         t.x += x;
3186                                         t.y += y;
3187                                         now = x + S + y;
3188                                     break;
3189                                     case "rotation":
3190                                         now = +from[attr][0] + pos * ms * diff[attr][0];
3191                                         from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
3192                                     break;
3193                                     case "scale":
3194                                         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);
3195                                     break;
3196                                     case "clip-rect":
3197                                         now = [];
3198                                         i = 4;
3199                                         while (i--) {
3200                                             now[i] = +from[attr][i] + pos * ms * diff[attr][i];
3201                                         }
3202                                     break;
3203                                 }
3204                                 break;
3205                             default:
3206                               var from2 = [].concat(from[attr]);
3207                                 now = [];
3208                                 i = that.paper.customAttributes[attr].length;
3209                                 while (i--) {
3210                                     now[i] = +from2[i] + pos * ms * diff[attr][i];
3211                                 }
3212                                 break;
3213                         }
3214                         set[attr] = now;
3215                     }
3216                     that.attr(set);
3217                     that._run && that._run.call(that);
3218                 } else {
3219                     if (to.along) {
3220                         point = getPointAtLength(to.along, to.len * !to.back);
3221                         that.translate(diff.sx - (diff.x || 0) + point.x - diff.sx, diff.sy - (diff.y || 0) + point.y - diff.sy);
3222                         to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
3223                     }
3224                     (t.x || t.y) && that.translate(-t.x, -t.y);
3225                     to.scale && (to.scale += E);
3226                     that.attr(to);
3227                     animationElements.splice(l--, 1);
3228                 }
3229             }
3230             R.svg && that && that.paper && that.paper.safari();
3231             animationElements[length] && setTimeout(animation);
3232         },
3233         keyframesRun = function (attr, element, time, prev, prevcallback) {
3234             var dif = time - prev;
3235             element.timeouts.push(setTimeout(function () {
3236                 R.is(prevcallback, "function") && prevcallback.call(element);
3237                 element.animate(attr, dif, attr.easing);
3238             }, prev));
3239         },
3240         upto255 = function (color) {
3241             return mmax(mmin(color, 255), 0);
3242         },
3243         translate = function (x, y) {
3244             if (x == null) {
3245                 return {x: this._.tx, y: this._.ty, toString: x_y};
3246             }
3247             this._.tx += +x;
3248             this._.ty += +y;
3249             switch (this.type) {
3250                 case "circle":
3251                 case "ellipse":
3252                     this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy});
3253                     break;
3254                 case "rect":
3255                 case "image":
3256                 case "text":
3257                     this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y});
3258                     break;
3259                 case "path":
3260                     var path = pathToRelative(this.attrs.path);
3261                     path[0][1] += +x;
3262                     path[0][2] += +y;
3263                     this.attr({path: path});
3264                 break;
3265             }
3266             return this;
3267         };
3268     elproto.animateWith = function (element, params, ms, easing, callback) {
3269         for (var i = 0, ii = animationElements.length; i < ii; i++) {
3270             if (animationElements[i].el.id == element.id) {
3271                 params.start = animationElements[i].start;
3272             }
3273         }
3274         return this.animate(params, ms, easing, callback);
3275     };
3276     elproto.animateAlong = along();
3277     elproto.animateAlongBack = along(1);
3278     function along(isBack) {
3279         return function (path, ms, rotate, callback) {
3280             var params = {back: isBack};
3281             R.is(rotate, "function") ? (callback = rotate) : (params.rot = rotate);
3282             path && path.constructor == Element && (path = path.attrs.path);
3283             path && (params.along = path);
3284             return this.animate(params, ms, callback);
3285         };
3286     }
3287     function CubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
3288         var cx = 3 * p1x,
3289             bx = 3 * (p2x - p1x) - cx,
3290             ax = 1 - cx - bx,
3291             cy = 3 * p1y,
3292             by = 3 * (p2y - p1y) - cy,
3293             ay = 1 - cy - by;
3294         function sampleCurveX(t) {
3295             return ((ax * t + bx) * t + cx) * t;
3296         }
3297         function solve(x, epsilon) {
3298             var t = solveCurveX(x, epsilon);
3299             return ((ay * t + by) * t + cy) * t;
3300         }
3301         function solveCurveX(x, epsilon) {
3302             var t0, t1, t2, x2, d2, i;
3303             for(t2 = x, i = 0; i < 8; i++) {
3304                 x2 = sampleCurveX(t2) - x;
3305                 if (abs(x2) < epsilon) {
3306                     return t2;
3307                 }
3308                 d2 = (3 * ax * t2 + 2 * bx) * t2 + cx;
3309                 if (abs(d2) < 1e-6) {
3310                     break;
3311                 }
3312                 t2 = t2 - x2 / d2;
3313             }
3314             t0 = 0;
3315             t1 = 1;
3316             t2 = x;
3317             if (t2 < t0) {
3318                 return t0;
3319             }
3320             if (t2 > t1) {
3321                 return t1;
3322             }
3323             while (t0 < t1) {
3324                 x2 = sampleCurveX(t2);
3325                 if (abs(x2 - x) < epsilon) {
3326                     return t2;
3327                 }
3328                 if (x > x2) {
3329                     t0 = t2;
3330                 } else {
3331                     t1 = t2;
3332                 }
3333                 t2 = (t1 - t0) / 2 + t0;
3334             }
3335             return t2;
3336         }
3337         return solve(t, 1 / (200 * duration));
3338     }
3339     elproto.onAnimation = function (f) {
3340         this._run = f || 0;
3341         return this;
3342     };
3343     elproto.animate = function (params, ms, easing, callback) {
3344         var element = this;
3345         element.timeouts = element.timeouts || [];
3346         if (R.is(easing, "function") || !easing) {
3347             callback = easing || null;
3348         }
3349         if (element.removed) {
3350             callback && callback.call(element);
3351             return element;
3352         }
3353         var from = {},
3354             to = {},
3355             animateable = false,
3356             diff = {};
3357         for (var attr in params) if (params[has](attr)) {
3358             if (availableAnimAttrs[has](attr) || element.paper.customAttributes[has](attr)) {
3359                 animateable = true;
3360                 from[attr] = element.attr(attr);
3361                 (from[attr] == null) && (from[attr] = availableAttrs[attr]);
3362                 to[attr] = params[attr];
3363                 switch (availableAnimAttrs[attr]) {
3364                     case "along":
3365                         var len = getTotalLength(params[attr]);
3366                         var point = getPointAtLength(params[attr], len * !!params.back);
3367                         var bb = element.getBBox();
3368                         diff[attr] = len / ms;
3369                         diff.tx = bb.x;
3370                         diff.ty = bb.y;
3371                         diff.sx = point.x;
3372                         diff.sy = point.y;
3373                         to.rot = params.rot;
3374                         to.back = params.back;
3375                         to.len = len;
3376                         params.rot && (diff.r = toFloat(element.rotate()) || 0);
3377                         break;
3378                     case nu:
3379                         diff[attr] = (to[attr] - from[attr]) / ms;
3380                         break;
3381                     case "colour":
3382                         from[attr] = R.getRGB(from[attr]);
3383                         var toColour = R.getRGB(to[attr]);
3384                         diff[attr] = {
3385                             r: (toColour.r - from[attr].r) / ms,
3386                             g: (toColour.g - from[attr].g) / ms,
3387                             b: (toColour.b - from[attr].b) / ms
3388                         };
3389                         break;
3390                     case "path":
3391                         var pathes = path2curve(from[attr], to[attr]);
3392                         from[attr] = pathes[0];
3393                         var toPath = pathes[1];
3394                         diff[attr] = [];
3395                         for (var i = 0, ii = from[attr][length]; i < ii; i++) {
3396                             diff[attr][i] = [0];
3397                             for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
3398                                 diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
3399                             }
3400                         }
3401                         break;
3402                     case "csv":
3403                         var values = Str(params[attr])[split](separator),
3404                             from2 = Str(from[attr])[split](separator);
3405                         switch (attr) {
3406                             case "translation":
3407                                 from[attr] = [0, 0];
3408                                 diff[attr] = [values[0] / ms, values[1] / ms];
3409                             break;
3410                             case "rotation":
3411                                 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
3412                                 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
3413                             break;
3414                             case "scale":
3415                                 params[attr] = values;
3416                                 from[attr] = Str(from[attr])[split](separator);
3417                                 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
3418                             break;
3419                             case "clip-rect":
3420                                 from[attr] = Str(from[attr])[split](separator);
3421                                 diff[attr] = [];
3422                                 i = 4;
3423                                 while (i--) {
3424                                     diff[attr][i] = (values[i] - from[attr][i]) / ms;
3425                                 }
3426                             break;
3427                         }
3428                         to[attr] = values;
3429                         break;
3430                     default:
3431                         values = [].concat(params[attr]);
3432                         from2 = [].concat(from[attr]);
3433                         diff[attr] = [];
3434                         i = element.paper.customAttributes[attr][length];
3435                         while (i--) {
3436                             diff[attr][i] = ((values[i] || 0) - (from2[i] || 0)) / ms;
3437                         }
3438                         break;
3439                 }
3440             }
3441         }
3442         if (!animateable) {
3443             var attrs = [],
3444                 lastcall;
3445             for (var key in params) if (params[has](key) && animKeyFrames.test(key)) {
3446                 attr = {value: params[key]};
3447                 key == "from" && (key = 0);
3448                 key == "to" && (key = 100);
3449                 attr.key = toInt(key, 10);
3450                 attrs.push(attr);
3451             }
3452             attrs.sort(sortByKey);
3453             if (attrs[0].key) {
3454                 attrs.unshift({key: 0, value: element.attrs});
3455             }
3456             for (i = 0, ii = attrs[length]; i < ii; i++) {
3457                 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);
3458             }
3459             lastcall = attrs[attrs[length] - 1].value.callback;
3460             if (lastcall) {
3461                 element.timeouts.push(setTimeout(function () {lastcall.call(element);}, ms));
3462             }
3463         } else {
3464             var easyeasy = R.easing_formulas[easing];
3465             if (!easyeasy) {
3466                 easyeasy = Str(easing).match(bezierrg);
3467                 if (easyeasy && easyeasy[length] == 5) {
3468                     var curve = easyeasy;
3469                     easyeasy = function (t) {
3470                         return CubicBezierAtTime(t, +curve[1], +curve[2], +curve[3], +curve[4], ms);
3471                     };
3472                 } else {
3473                     easyeasy = function (t) {
3474                         return t;
3475                     };
3476                 }
3477             }
3478             animationElements.push({
3479                 start: params.start || +new Date,
3480                 ms: ms,
3481                 easing: easyeasy,
3482                 from: from,
3483                 diff: diff,
3484                 to: to,
3485                 el: element,
3486                 t: {x: 0, y: 0}
3487             });
3488             R.is(callback, "function") && (element._ac = setTimeout(function () {
3489                 callback.call(element);
3490             }, ms));
3491             animationElements[length] == 1 && setTimeout(animation);
3492         }
3493         return this;
3494     };
3495     elproto.stop = function () {
3496         for (var i = 0; i < animationElements.length; i++) {
3497             animationElements[i].el.id == this.id && animationElements.splice(i--, 1);
3498         }
3499         for (i = 0, ii = this.timeouts && this.timeouts.length; i < ii; i++) {
3500             clearTimeout(this.timeouts[i]);
3501         }
3502         this.timeouts = [];
3503         clearTimeout(this._ac);
3504         delete this._ac;
3505         return this;
3506     };
3507     elproto.translate = function (x, y) {
3508         return this.attr({translation: x + " " + y});
3509     };
3510     elproto[toString] = function () {
3511         return "Rapha\xebl\u2019s object";
3512     };
3513     R.ae = animationElements;
3514  
3515     // Set
3516     var Set = function (items) {
3517         this.items = [];
3518         this[length] = 0;
3519         this.type = "set";
3520         if (items) {
3521             for (var i = 0, ii = items[length]; i < ii; i++) {
3522                 if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
3523                     this[this.items[length]] = this.items[this.items[length]] = items[i];
3524                     this[length]++;
3525                 }
3526             }
3527         }
3528     };
3529     Set[proto][push] = function () {
3530         var item,
3531             len;
3532         for (var i = 0, ii = arguments[length]; i < ii; i++) {
3533             item = arguments[i];
3534             if (item && (item.constructor == Element || item.constructor == Set)) {
3535                 len = this.items[length];
3536                 this[len] = this.items[len] = item;
3537                 this[length]++;
3538             }
3539         }
3540         return this;
3541     };
3542     Set[proto].pop = function () {
3543         delete this[this[length]--];
3544         return this.items.pop();
3545     };
3546     for (var method in elproto) if (elproto[has](method)) {
3547         Set[proto][method] = (function (methodname) {
3548             return function () {
3549                 for (var i = 0, ii = this.items[length]; i < ii; i++) {
3550                     this.items[i][methodname][apply](this.items[i], arguments);
3551                 }
3552                 return this;
3553             };
3554         })(method);
3555     }
3556     Set[proto].attr = function (name, value) {
3557         if (name && R.is(name, array) && R.is(name[0], "object")) {
3558             for (var j = 0, jj = name[length]; j < jj; j++) {
3559                 this.items[j].attr(name[j]);
3560             }
3561         } else {
3562             for (var i = 0, ii = this.items[length]; i < ii; i++) {
3563                 this.items[i].attr(name, value);
3564             }
3565         }
3566         return this;
3567     };
3568     Set[proto].animate = function (params, ms, easing, callback) {
3569         (R.is(easing, "function") || !easing) && (callback = easing || null);
3570         var len = this.items[length],
3571             i = len,
3572             item,
3573             set = this,
3574             collector;
3575         callback && (collector = function () {
3576             !--len && callback.call(set);
3577         });
3578         easing = R.is(easing, string) ? easing : collector;
3579         item = this.items[--i].animate(params, ms, easing, collector);
3580         while (i--) {
3581             this.items[i] && !this.items[i].removed && this.items[i].animateWith(item, params, ms, easing, collector);
3582         }
3583         return this;
3584     };
3585     Set[proto].insertAfter = function (el) {
3586         var i = this.items[length];
3587         while (i--) {
3588             this.items[i].insertAfter(el);
3589         }
3590         return this;
3591     };
3592     Set[proto].getBBox = function () {
3593         var x = [],
3594             y = [],
3595             w = [],
3596             h = [];
3597         for (var i = this.items[length]; i--;) {
3598             var box = this.items[i].getBBox();
3599             x[push](box.x);
3600             y[push](box.y);
3601             w[push](box.x + box.width);
3602             h[push](box.y + box.height);
3603         }
3604         x = mmin[apply](0, x);
3605         y = mmin[apply](0, y);
3606         return {
3607             x: x,
3608             y: y,
3609             width: mmax[apply](0, w) - x,
3610             height: mmax[apply](0, h) - y
3611         };
3612     };
3613     Set[proto].clone = function (s) {
3614         s = new Set;
3615         for (var i = 0, ii = this.items[length]; i < ii; i++) {
3616             s[push](this.items[i].clone());
3617         }
3618         return s;
3619     };
3620
3621     R.registerFont = function (font) {
3622         if (!font.face) {
3623             return font;
3624         }
3625         this.fonts = this.fonts || {};
3626         var fontcopy = {
3627                 w: font.w,
3628                 face: {},
3629                 glyphs: {}
3630             },
3631             family = font.face["font-family"];
3632         for (var prop in font.face) if (font.face[has](prop)) {
3633             fontcopy.face[prop] = font.face[prop];
3634         }
3635         if (this.fonts[family]) {
3636             this.fonts[family][push](fontcopy);
3637         } else {
3638             this.fonts[family] = [fontcopy];
3639         }
3640         if (!font.svg) {
3641             fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
3642             for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
3643                 var path = font.glyphs[glyph];
3644                 fontcopy.glyphs[glyph] = {
3645                     w: path.w,
3646                     k: {},
3647                     d: path.d && "M" + path.d[rp](/[mlcxtrv]/g, function (command) {
3648                             return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
3649                         }) + "z"
3650                 };
3651                 if (path.k) {
3652                     for (var k in path.k) if (path[has](k)) {
3653                         fontcopy.glyphs[glyph].k[k] = path.k[k];
3654                     }
3655                 }
3656             }
3657         }
3658         return font;
3659     };
3660     paperproto.getFont = function (family, weight, style, stretch) {
3661         stretch = stretch || "normal";
3662         style = style || "normal";
3663         weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
3664         if (!R.fonts) {
3665             return;
3666         }
3667         var font = R.fonts[family];
3668         if (!font) {
3669             var name = new RegExp("(^|\\s)" + family[rp](/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
3670             for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
3671                 if (name.test(fontName)) {
3672                     font = R.fonts[fontName];
3673                     break;
3674                 }
3675             }
3676         }
3677         var thefont;
3678         if (font) {
3679             for (var i = 0, ii = font[length]; i < ii; i++) {
3680                 thefont = font[i];
3681                 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
3682                     break;
3683                 }
3684             }
3685         }
3686         return thefont;
3687     };
3688     paperproto.print = function (x, y, string, font, size, origin, letter_spacing) {
3689         origin = origin || "middle"; // baseline|middle
3690         letter_spacing = mmax(mmin(letter_spacing || 0, 1), -1);
3691         var out = this.set(),
3692             letters = Str(string)[split](E),
3693             shift = 0,
3694             path = E,
3695             scale;
3696         R.is(font, string) && (font = this.getFont(font));
3697         if (font) {
3698             scale = (size || 16) / font.face["units-per-em"];
3699             var bb = font.face.bbox.split(separator),
3700                 top = +bb[0],
3701                 height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
3702             for (var i = 0, ii = letters[length]; i < ii; i++) {
3703                 var prev = i && font.glyphs[letters[i - 1]] || {},
3704                     curr = font.glyphs[letters[i]];
3705                 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) + (font.w * letter_spacing) : 0;
3706                 curr && curr.d && out[push](this.path(curr.d).attr({fill: "#000", stroke: "none", translation: [shift, 0]}));
3707             }
3708             out.scale(scale, scale, top, height).translate(x - top, y - height);
3709         }
3710         return out;
3711     };
3712
3713     R.format = function (token, params) {
3714         var args = R.is(params, array) ? [0][concat](params) : arguments;
3715         token && R.is(token, string) && args[length] - 1 && (token = token[rp](formatrg, function (str, i) {
3716             return args[++i] == null ? E : args[i];
3717         }));
3718         return token || E;
3719     };
3720     R.ninja = function () {
3721         oldRaphael.was ? (win.Raphael = oldRaphael.is) : delete Raphael;
3722         return R;
3723     };
3724     R.el = elproto;
3725     R.st = Set[proto];
3726
3727     oldRaphael.was ? (win.Raphael = R) : (Raphael = R);
3728 })();