Splitting fixes
[raphael] / raphael.js
1 // ┌─────────────────────────────────────────────────────────────────────┐ \\
2 // │ Raphaël 2 - JavaScript Vector Library                               │ \\
3 // ├─────────────────────────────────────────────────────────────────────┤ \\
4 // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com)   │ \\
5 // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com)             │ \\
6 // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
7 // └─────────────────────────────────────────────────────────────────────┘ \\
8 (function () {
9     /*\
10      * Raphael
11      [ method ]
12      **
13      * Creates a canvas object on which to draw.
14      * You must do this first, as all future calls to drawing methods
15      * from this instance will be bound to this canvas.
16      > Parameters
17      **
18      - container (HTMLElement|string) DOM element or its ID which is going to be a parent for drawing surface
19      - width (number)
20      - height (number)
21      - callback (function) #optional callback function which is going to be executed in the context of newly created paper
22      * or
23      - x (number)
24      - y (number)
25      - width (number)
26      - height (number)
27      - callback (function) #optional callback function which is going to be executed in the context of newly created paper
28      * or
29      - all (array) (first 3 or 4 elements in the array are equal to [containerID, width, height] or [x, y, width, height]. The rest are element descriptions in format {type: type, <attributes>})
30      - callback (function) #optional callback function which is going to be executed in the context of newly created paper
31      * or
32      - onReadyCallback (function) function that is going to be called on DOM ready event. You can also subscribe to this event via Eve’s “DOMLoad” event. In this case method returns `undefined`.
33      = (object) @Paper
34      > Usage
35      | // Each of the following examples create a canvas
36      | // that is 320px wide by 200px high.
37      | // Canvas is created at the viewport’s 10,50 coordinate.
38      | var paper = Raphael(10, 50, 320, 200);
39      | // Canvas is created at the top left corner of the #notepad element
40      | // (or its top right corner in dir="rtl" elements)
41      | var paper = Raphael(document.getElementById("notepad"), 320, 200);
42      | // Same as above
43      | var paper = Raphael("notepad", 320, 200);
44      | // Image dump
45      | var set = Raphael(["notepad", 320, 200, {
46      |     type: "rect",
47      |     x: 10,
48      |     y: 10,
49      |     width: 25,
50      |     height: 25,
51      |     stroke: "#f00"
52      | }, {
53      |     type: "text",
54      |     x: 30,
55      |     y: 40,
56      |     text: "Dump"
57      | }]);
58     \*/
59     function R(first) {
60         if (R.is(first, "function")) {
61             return loaded ? first() : eve.on("DOMload", first);
62         } else if (R.is(first, array)) {
63             var a = first,
64                 cnv = R._engine.create[apply](R, a.splice(0, 3 + R.is(a[0], nu))),
65                 res = cnv.set(),
66                 i = 0,
67                 ii = a.length,
68                 j;
69             for (; i < ii; i++) {
70                 j = a[i] || {};
71                 elements[has](j.type) && res.push(cnv[j.type]().attr(j));
72             }
73             return res;
74         } else {
75             var args = Array.prototype.slice.call(arguments, 0);
76             if (R.is(args[args.length - 1], "function")) {
77                 var f = args.pop();
78                 return loaded ? f.call(R._engine.create[apply](R, args)) : eve.on("DOMload", function () {
79                     f.call(R._engine.create[apply](R, args));
80                 });
81             } else {
82                 return R._engine.create[apply](R, arguments);
83             }
84         }
85     }
86     R.version = "2.0.0";
87     var loaded,
88         separator = /[, ]+/,
89         elements = {circle: 1, rect: 1, path: 1, ellipse: 1, text: 1, image: 1},
90         formatrg = /\{(\d+)\}/g,
91         proto = "prototype",
92         has = "hasOwnProperty",
93         g = {
94             doc: document,
95             win: window
96         },
97         oldRaphael = {
98             was: Object.prototype[has].call(g.win, "Raphael"),
99             is: g.win.Raphael
100         },
101         Paper = function () {},
102         paperproto,
103         appendChild = "appendChild",
104         apply = "apply",
105         concat = "concat",
106         supportsTouch = "createTouch" in g.doc,
107         E = "",
108         S = " ",
109         Str = String,
110         split = "split",
111         events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend orientationchange touchcancel gesturestart gesturechange gestureend".split(S),
112         touchMap = {
113             mousedown: "touchstart",
114             mousemove: "touchmove",
115             mouseup: "touchend"
116         },
117         lowerCase = Str.prototype.toLowerCase,
118         math = Math,
119         mmax = math.max,
120         mmin = math.min,
121         abs = math.abs,
122         pow = math.pow,
123         PI = math.PI,
124         nu = "number",
125         string = "string",
126         array = "array",
127         toString = "toString",
128         fillString = "fill",
129         objectToString = Object.prototype.toString,
130         paper = {},
131         push = "push",
132         ISURL = R._ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
133         colourRegExp = /^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+%?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\)|hsba?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\)|hsla?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\))\s*$/i,
134         isnan = {"NaN": 1, "Infinity": 1, "-Infinity": 1},
135         bezierrg = /^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
136         round = math.round,
137         setAttribute = "setAttribute",
138         toFloat = parseFloat,
139         toInt = parseInt,
140         ms = " progid:DXImageTransform.Microsoft",
141         upperCase = Str.prototype.toUpperCase,
142         availableAttrs = R._availableAttrs = {
143             "arrow-end": "none",
144             "arrow-start": "none",
145             blur: 0,
146             "clip-rect": "0 0 1e9 1e9",
147             cursor: "default",
148             cx: 0,
149             cy: 0,
150             fill: "#fff",
151             "fill-opacity": 1,
152             font: '10px "Arial"',
153             "font-family": '"Arial"',
154             "font-size": "10",
155             "font-style": "normal",
156             "font-weight": 400,
157             gradient: 0,
158             height: 0,
159             href: "http://raphaeljs.com/",
160             opacity: 1,
161             path: "M0,0",
162             r: 0,
163             rx: 0,
164             ry: 0,
165             src: "",
166             stroke: "#000",
167             "stroke-dasharray": "",
168             "stroke-linecap": "butt",
169             "stroke-linejoin": "butt",
170             "stroke-miterlimit": 0,
171             "stroke-opacity": 1,
172             "stroke-width": 1,
173             target: "_blank",
174             "text-anchor": "middle",
175             title: "Raphael",
176             transform: "",
177             width: 0,
178             x: 0,
179             y: 0
180         },
181         availableAnimAttrs = R._availableAnimAttrs = {
182             blur: nu,
183             "clip-rect": "csv",
184             cx: nu,
185             cy: nu,
186             fill: "colour",
187             "fill-opacity": nu,
188             "font-size": nu,
189             height: nu,
190             opacity: nu,
191             path: "path",
192             r: nu,
193             rx: nu,
194             ry: nu,
195             stroke: "colour",
196             "stroke-opacity": nu,
197             "stroke-width": nu,
198             transform: "transform",
199             width: nu,
200             x: nu,
201             y: nu
202         },
203         commaSpaces = /\s*,\s*/,
204         hsrg = {hs: 1, rg: 1},
205         p2s = /,?([achlmqrstvxz]),?/gi,
206         pathCommand = /([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,
207         tCommand = /([rstm])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,
208         pathValues = /(-?\d*\.?\d*(?:e[\-+]?\d+)?)\s*,?\s*/ig,
209         radial_gradient = R._radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/,
210         sortByKey = function (a, b) {
211             return a.key - b.key;
212         },
213         sortByNumber = function (a, b) {
214             return a - b;
215         },
216         fun = function () {},
217         pipe = function (x) {
218             return x;
219         },
220         rectPath = R._rectPath = function (x, y, w, h, r) {
221             if (r) {
222                 return [["M", x + r, y], ["l", w - r * 2, 0], ["a", r, r, 0, 0, 1, r, r], ["l", 0, h - r * 2], ["a", r, r, 0, 0, 1, -r, r], ["l", r * 2 - w, 0], ["a", r, r, 0, 0, 1, -r, -r], ["l", 0, r * 2 - h], ["a", r, r, 0, 0, 1, r, -r], ["z"]];
223             }
224             return [["M", x, y], ["l", w, 0], ["l", 0, h], ["l", -w, 0], ["z"]];
225         },
226         ellipsePath = function (x, y, rx, ry) {
227             if (ry == null) {
228                 ry = rx;
229             }
230             return [["M", x, y], ["m", 0, -ry], ["a", rx, ry, 0, 1, 1, 0, 2 * ry], ["a", rx, ry, 0, 1, 1, 0, -2 * ry], ["z"]];
231         },
232         getPath = R._getPath = {
233             path: function (el) {
234                 return el.attr("path");
235             },
236             circle: function (el) {
237                 var a = el.attrs;
238                 return ellipsePath(a.cx, a.cy, a.r);
239             },
240             ellipse: function (el) {
241                 var a = el.attrs;
242                 return ellipsePath(a.cx, a.cy, a.rx, a.ry);
243             },
244             rect: function (el) {
245                 var a = el.attrs;
246                 return rectPath(a.x, a.y, a.width, a.height, a.r);
247             },
248             image: function (el) {
249                 var a = el.attrs;
250                 return rectPath(a.x, a.y, a.width, a.height);
251             },
252             text: function (el) {
253                 var bbox = el._getBBox();
254                 return rectPath(bbox.x, bbox.y, bbox.width, bbox.height);
255             }
256         },
257         mapPath = function (path, matrix) {
258             if (!matrix) {
259                 return path;
260             }
261             var x, y, i, j, pathi;
262             path = path2curve(path);
263             for (i = 0, ii = path.length; i < ii; i++) {
264                 pathi = path[i];
265                 for (j = 1, jj = pathi.length; j < jj; j += 2) {
266                     x = matrix.x(pathi[j], pathi[j + 1]);
267                     y = matrix.y(pathi[j], pathi[j + 1]);
268                     pathi[j] = x;
269                     pathi[j + 1] = y;
270                 }
271             }
272             return path;
273         };
274
275     R._g = g;
276     /*\
277      * Raphael.type
278      [ property (string) ]
279      **
280      * Can be “SVG”, “VML” or empty, depending on browser support.
281     \*/
282     R.type = (g.win.SVGAngle || g.doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
283     if (R.type == "VML") {
284         var d = g.doc.createElement("div"),
285             b;
286         d.innerHTML = '<v:shape adj="1"/>';
287         b = d.firstChild;
288         b.style.behavior = "url(#default#VML)";
289         if (!(b && typeof b.adj == "object")) {
290             return (R.type = E);
291         }
292         d = null;
293     }
294     /*\
295      * Raphael.svg
296      [ property (boolean) ]
297      **
298      * `true` if browser supports SVG.
299     \*/
300     /*\
301      * Raphael.vml
302      [ property (boolean) ]
303      **
304      * `true` if browser supports VML.
305     \*/
306     R.svg = !(R.vml = R.type == "VML");
307     R._Paper = Paper;
308     /*\
309      * Raphael.fn
310      [ property (object) ]
311      **
312      * You can add your own method to the canvas. For example if you want to draw a pie chart,
313      * you can create your own pie chart function and ship it as a Raphaël plugin. To do this
314      * you need to extend the `Raphael.fn` object. Please note that you can create your own namespaces
315      * inside the `fn` object — methods will be run in the context of canvas anyway. You should alter
316      * the `fn` object before a Raphaël instance is created, otherwise it will take no effect.
317      > Usage
318      | Raphael.fn.arrow = function (x1, y1, x2, y2, size) {
319      |     return this.path( ... );
320      | };
321      | // or create namespace
322      | Raphael.fn.mystuff = {
323      |     arrow: function () {…},
324      |     star: function () {…},
325      |     // etc…
326      | };
327      | var paper = Raphael(10, 10, 630, 480);
328      | // then use it
329      | paper.arrow(10, 10, 30, 30, 5).attr({fill: "#f00"});
330      | paper.mystuff.arrow();
331      | paper.mystuff.star();
332     \*/
333     R.fn = paperproto = Paper.prototype = R.prototype;
334     /*\
335      * Paper.customAttributes
336      [ property (object) ]
337      **
338      * If you have a set of attributes that you would like to represent
339      * as a function of some number you can do it easily with custom attributes:
340      > Usage
341      | paper.customAttributes.hue = function (num) {
342      |     num = num % 1;
343      |     return {fill: "hsb(" + num + ", .75, 1)"};
344      | };
345      | // Custom attribute “hue” will change fill
346      | // to be given hue with fixed saturation and brightness.
347      | // Now you can use it like this:
348      | var c = paper.circle(10, 10, 10).attr({hue: .45});
349      | // or even like this:
350      | c.animate({hue: 1}, 1e3);
351      | 
352      | // You could also create custom attribute
353      | // with multiple parameters:
354      | paper.customAttributes.hsb = function (h, s, b) {
355      |     return {fill: "hsb(" + [h, s, b].join(",") + ")"};
356      | };
357      | c.attr({hsb: ".5 .8 1"});
358      | c.animate({hsb: "1 0 .5"}, 1e3);
359     \*/
360     paperproto.customAttributes = {};
361     R._id = 0;
362     R._oid = 0;
363     /*\
364      * Raphael.is
365      [ method ]
366      **
367      * Handfull replacement for `typeof` operator.
368      > Parameters
369      - o (…) any object or primitive
370      - type (string) name of the type, i.e. “string”, “function”, “number”, etc.
371      = (boolean) is given value is of given type
372     \*/
373     R.is = function (o, type) {
374         type = lowerCase.call(type);
375         if (type == "finite") {
376             return !isnan[has](+o);
377         }
378         if (type == "array") {
379             return o instanceof Array;
380         }
381         return  (type == "null" && o === null) ||
382                 (type == typeof o) ||
383                 (type == "object" && o === Object(o)) ||
384                 (type == "array" && Array.isArray && Array.isArray(o)) ||
385                 objectToString.call(o).slice(8, -1).toLowerCase() == type;
386     };
387     /*\
388      * Raphael.angle
389      [ method ]
390      **
391      * Returns angle between two or three points
392      > Parameters
393      - x1 (number) x coord of first point
394      - y1 (number) y coord of first point
395      - x2 (number) x coord of second point
396      - y2 (number) y coord of second point
397      - x3 (number) #optional x coord of third point
398      - y3 (number) #optional y coord of third point
399      = (number) angle in degrees.
400     \*/
401     R.angle = function (x1, y1, x2, y2, x3, y3) {
402         if (x3 == null) {
403             var x = x1 - x2,
404                 y = y1 - y2;
405             if (!x && !y) {
406                 return 0;
407             }
408             return (180 + math.atan2(-y, -x) * 180 / PI + 360) % 360;
409         } else {
410             return R.angle(x1, y1, x3, y3) - R.angle(x2, y2, x3, y3);
411         }
412     };
413     /*\
414      * Raphael.rad
415      [ method ]
416      **
417      * Transform angle to radians
418      > Parameters
419      - deg (number) angle in degrees
420      = (number) angle in radians.
421     \*/
422     R.rad = function (deg) {
423         return deg % 360 * PI / 180;
424     };
425     /*\
426      * Raphael.deg
427      [ method ]
428      **
429      * Transform angle to degrees
430      > Parameters
431      - deg (number) angle in radians
432      = (number) angle in degrees.
433     \*/
434     R.deg = function (rad) {
435         return rad * 180 / PI % 360;
436     };
437     /*\
438      * Raphael.snapTo
439      [ method ]
440      **
441      * Snaps given value to given grid.
442      > Parameters
443      - values (array|number) given array of values or step of the grid
444      - value (number) value to adjust
445      - tolerance (number) #optional tolerance for snapping. Default is `10`.
446      = (number) adjusted value.
447     \*/
448     R.snapTo = function (values, value, tolerance) {
449         tolerance = R.is(tolerance, "finite") ? tolerance : 10;
450         if (R.is(values, array)) {
451             var i = values.length;
452             while (i--) if (abs(values[i] - value) <= tolerance) {
453                 return values[i];
454             }
455         } else {
456             values = +values;
457             var rem = value % values;
458             if (rem < tolerance) {
459                 return value - rem;
460             }
461             if (rem > values - tolerance) {
462                 return value - rem + values;
463             }
464         }
465         return value;
466     };
467     
468     var createUUID = R._createUUID = (function (uuidRegEx, uuidReplacer) {
469         return function () {
470             return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(uuidRegEx, uuidReplacer).toUpperCase();
471         };
472     })(/[xy]/g, function (c) {
473         var r = math.random() * 16 | 0,
474             v = c == "x" ? r : (r & 3 | 8);
475         return v.toString(16);
476     });
477
478     /*\
479      * Raphael.setWindow
480      [ method ]
481      **
482      * Used when you need to draw in `&lt;iframe>`. Switched window to the iframe one.
483      > Parameters
484      - newwin (window) new window object
485     \*/
486     R.setWindow = function (newwin) {
487         eve("setWindow", R, g.win, newwin);
488         g.win = newwin;
489         g.doc = g.win.document;
490         if (initWin) {
491             initWin(g.win);
492         }
493     };
494     // colour utilities
495     var toHex = function (color) {
496         if (R.vml) {
497             // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
498             var trim = /^\s+|\s+$/g;
499             var bod;
500             try {
501                 var docum = new ActiveXObject("htmlfile");
502                 docum.write("<body>");
503                 docum.close();
504                 bod = docum.body;
505             } catch(e) {
506                 bod = createPopup().document.body;
507             }
508             var range = bod.createTextRange();
509             toHex = cacher(function (color) {
510                 try {
511                     bod.style.color = Str(color).replace(trim, E);
512                     var value = range.queryCommandValue("ForeColor");
513                     value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
514                     return "#" + ("000000" + value.toString(16)).slice(-6);
515                 } catch(e) {
516                     return "none";
517                 }
518             });
519         } else {
520             var i = g.doc.createElement("i");
521             i.title = "Rapha\xebl Colour Picker";
522             i.style.display = "none";
523             g.doc.body.appendChild(i);
524             toHex = cacher(function (color) {
525                 i.style.color = color;
526                 return g.doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
527             });
528         }
529         return toHex(color);
530     },
531     hsbtoString = function () {
532         return "hsb(" + [this.h, this.s, this.b] + ")";
533     },
534     hsltoString = function () {
535         return "hsl(" + [this.h, this.s, this.l] + ")";
536     },
537     rgbtoString = function () {
538         return this.hex;
539     },
540     prepareRGB = function (r, g, b) {
541         if (g == null && R.is(r, "object") && "r" in r && "g" in r && "b" in r) {
542             b = r.b;
543             g = r.g;
544             r = r.r;
545         }
546         if (g == null && R.is(r, string)) {
547             var clr = R.getRGB(r);
548             r = clr.r;
549             g = clr.g;
550             b = clr.b;
551         }
552         if (r > 1 || g > 1 || b > 1) {
553             r /= 255;
554             g /= 255;
555             b /= 255;
556         }
557         
558         return [r, g, b];
559     },
560     packageRGB = function (r, g, b, o) {
561         r *= 255;
562         g *= 255;
563         b *= 255;
564         var rgb = {
565             r: r,
566             g: g,
567             b: b,
568             hex: R.rgb(r, g, b),
569             toString: rgbtoString
570         };
571         R.is(o, "finite") && (rgb.opacity = o);
572         return rgb;
573     };
574     
575     /*\
576      * Raphael.color
577      [ method ]
578      **
579      * Parses the color string and returns object with all values for the given color.
580      > Parameters
581      - clr (string) color string in one of the supported formats (see @Raphael.getRGB)
582      = (object) Combined RGB & HSB object in format:
583      o {
584      o     r (number) red,
585      o     g (number) green,
586      o     b (number) blue,
587      o     hex (string) color in HTML/CSS format: #••••••,
588      o     error (boolean) `true` if string can’t be parsed,
589      o     h (number) hue,
590      o     s (number) saturation,
591      o     v (number) value (brightness),
592      o     l (number) lightness
593      o }
594     \*/
595     R.color = function (clr) {
596         var rgb;
597         if (R.is(clr, "object") && "h" in clr && "s" in clr && "b" in clr) {
598             rgb = R.hsb2rgb(clr);
599             clr.r = rgb.r;
600             clr.g = rgb.g;
601             clr.b = rgb.b;
602             clr.hex = rgb.hex;
603         } else if (R.is(clr, "object") && "h" in clr && "s" in clr && "l" in clr) {
604             rgb = R.hsl2rgb(clr);
605             clr.r = rgb.r;
606             clr.g = rgb.g;
607             clr.b = rgb.b;
608             clr.hex = rgb.hex;
609         } else {
610             if (R.is(clr, "string")) {
611                 clr = R.getRGB(clr);
612             }
613             if (R.is(clr, "object") && "r" in clr && "g" in clr && "b" in clr) {
614                 rgb = R.rgb2hsl(clr);
615                 clr.h = rgb.h;
616                 clr.s = rgb.s;
617                 clr.l = rgb.l;
618                 rgb = R.rgb2hsb(clr);
619                 clr.v = rgb.b;
620             } else {
621                 clr = {hex: "none"};
622                 crl.r = clr.g = clr.b = clr.h = clr.s = clr.v = clr.l = -1;
623             }
624         }
625         clr.toString = rgbtoString;
626         return clr;
627     };
628     /*\
629      * Raphael.hsb2rgb
630      [ method ]
631      **
632      * Converts HSB values to RGB object.
633      > Parameters
634      - h (number) hue
635      - s (number) saturation
636      - v (number) value or brightness
637      = (object) RGB object in format:
638      o {
639      o     r (number) red,
640      o     g (number) green,
641      o     b (number) blue,
642      o     hex (string) color in HTML/CSS format: #••••••
643      o }
644     \*/
645     R.hsb2rgb = function (h, s, v, o) {
646         if (this.is(h, "object") && "h" in h && "s" in h && "b" in h) {
647             v = h.b;
648             s = h.s;
649             h = h.h;
650             o = h.o;
651         }
652         h *= 360;
653         var R, G, B, X, C;
654         h = (h % 360) / 60;
655         C = v * s;
656         X = C * (1 - abs(h % 2 - 1));
657         R = G = B = v - C;
658
659         h = ~~h;
660         R += [C, X, 0, 0, X, C][h];
661         G += [X, C, C, X, 0, 0][h];
662         B += [0, 0, X, C, C, X][h];
663         return packageRGB(R, G, B, o);
664     };
665     /*\
666      * Raphael.hsl2rgb
667      [ method ]
668      **
669      * Converts HSL values to RGB object.
670      > Parameters
671      - h (number) hue
672      - s (number) saturation
673      - l (number) luminosity
674      = (object) RGB object in format:
675      o {
676      o     r (number) red,
677      o     g (number) green,
678      o     b (number) blue,
679      o     hex (string) color in HTML/CSS format: #••••••
680      o }
681     \*/
682     R.hsl2rgb = function (h, s, l, o) {
683         if (this.is(h, "object") && "h" in h && "s" in h && "l" in h) {
684             l = h.l;
685             s = h.s;
686             h = h.h;
687         }
688         if (h > 1 || s > 1 || l > 1) {
689             h /= 360;
690             s /= 100;
691             l /= 100;
692         }
693         h *= 360;
694         var R, G, B, X, C;
695         h = (h % 360) / 60;
696         C = 2 * s * (l < .5 ? l : 1 - l);
697         X = C * (1 - abs(h % 2 - 1));
698         R = G = B = l - C / 2;
699
700         h = ~~h;
701         R += [C, X, 0, 0, X, C][h];
702         G += [X, C, C, X, 0, 0][h];
703         B += [0, 0, X, C, C, X][h];
704         return packageRGB(R, G, B, o);
705     };
706     /*\
707      * Raphael.rgb2hsb
708      [ method ]
709      **
710      * Converts RGB values to HSB object.
711      > Parameters
712      - r (number) red
713      - g (number) green
714      - b (number) blue
715      = (object) HSB object in format:
716      o {
717      o     h (number) hue
718      o     s (number) saturation
719      o     b (number) brightness
720      o }
721     \*/
722     R.rgb2hsb = function (r, g, b) {
723         b = prepareRGB(r, g, b);
724         r = b[0];
725         g = b[1];
726         b = b[2];
727
728         var H, S, V, C;
729         V = mmax(r, g, b);
730         C = V - mmin(r, g, b);
731         H = (C == 0 ? null :
732              V == r ? (g - b) / C :
733              V == g ? (b - r) / C + 2 :
734                       (r - g) / C + 4
735             );
736         H = ((H + 360) % 6) * 60 / 360;
737         S = C == 0 ? 0 : C / V;
738         return {h: H, s: S, b: V, toString: hsbtoString};
739     };
740     /*\
741      * Raphael.rgb2hsl
742      [ method ]
743      **
744      * Converts RGB values to HSL object.
745      > Parameters
746      - r (number) red
747      - g (number) green
748      - b (number) blue
749      = (object) HSL object in format:
750      o {
751      o     h (number) hue
752      o     s (number) saturation
753      o     l (number) luminosity
754      o }
755     \*/
756     R.rgb2hsl = function (r, g, b) {
757         b = prepareRGB(r, g, b);
758         r = b[0];
759         g = b[1];
760         b = b[2];
761
762         var H, S, L, M, m, C;
763         M = mmax(r, g, b);
764         m = mmin(r, g, b);
765         C = M - m;
766         H = (C == 0 ? null :
767              M == r ? (g - b) / C :
768              M == g ? (b - r) / C + 2 :
769                       (r - g) / C + 4);
770         H = ((H + 360) % 6) * 60 / 360;
771         L = (M + m) / 2;
772         S = (C == 0 ? 0 :
773              L < .5 ? C / (2 * L) :
774                       C / (2 - 2 * L));
775         return {h: H, s: S, l: L, toString: hsltoString};
776     };
777     R._path2string = function () {
778         return this.join(",").replace(p2s, "$1");
779     };
780     function repush(array, item) {
781         for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) {
782             return array.push(array.splice(i, 1)[0]);
783         }
784     }
785     function cacher(f, scope, postprocessor) {
786         function newf() {
787             var arg = Array.prototype.slice.call(arguments, 0),
788                 args = arg.join("\u2400"),
789                 cache = newf.cache = newf.cache || {},
790                 count = newf.count = newf.count || [];
791             if (cache[has](args)) {
792                 repush(count, args);
793                 return postprocessor ? postprocessor(cache[args]) : cache[args];
794             }
795             count.length >= 1e3 && delete cache[count.shift()];
796             count.push(args);
797             cache[args] = f[apply](scope, arg);
798             return postprocessor ? postprocessor(cache[args]) : cache[args];
799         }
800         return newf;
801     }
802
803     var preload = R._preload = function (src, f) {
804         var img = g.doc.createElement("img");
805         img.style.cssText = "position:absolute;left:-9999em;top-9999em";
806         img.onload = function () {
807             f.call(this);
808             this.onload = null;
809             g.doc.body.removeChild(this);
810         };
811         img.onerror = function () {
812             g.doc.body.removeChild(this);
813         };
814         g.doc.body.appendChild(img);
815         img.src = src;
816     };
817     
818     function clrToString() {
819         return this.hex;
820     }
821
822     /*\
823      * Raphael.getRGB
824      [ method ]
825      **
826      * Parses colour string as RGB object
827      > Parameters
828      - colour (string) colour string in one of formats:
829      # <ul>
830      #     <li>Colour name (“<code>red</code>”, “<code>green</code>”, “<code>cornflowerblue</code>”, etc)</li>
831      #     <li>#••• — shortened HTML colour: (“<code>#000</code>”, “<code>#fc0</code>”, etc)</li>
832      #     <li>#•••••• — full length HTML colour: (“<code>#000000</code>”, “<code>#bd2300</code>”)</li>
833      #     <li>rgb(•••, •••, •••) — red, green and blue channels’ values: (“<code>rgb(200,&nbsp;100,&nbsp;0)</code>”)</li>
834      #     <li>rgb(•••%, •••%, •••%) — same as above, but in %: (“<code>rgb(100%,&nbsp;175%,&nbsp;0%)</code>”)</li>
835      #     <li>hsb(•••, •••, •••) — hue, saturation and brightness values: (“<code>hsb(0.5,&nbsp;0.25,&nbsp;1)</code>”)</li>
836      #     <li>hsb(•••%, •••%, •••%) — same as above, but in %</li>
837      #     <li>hsl(•••, •••, •••) — same as hsb</li>
838      #     <li>hsl(•••%, •••%, •••%) — same as hsb</li>
839      # </ul>
840      = (object) RGB object in format:
841      o {
842      o     r (number) red,
843      o     g (number) green,
844      o     b (number) blue
845      o     hex (string) color in HTML/CSS format: #••••••,
846      o     error (boolean) true if string can’t be parsed
847      o }
848     \*/
849     R.getRGB = cacher(function (colour) {
850         if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) {
851             return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
852         }
853         if (colour == "none") {
854             return {r: -1, g: -1, b: -1, hex: "none", toString: clrToString};
855         }
856         !(hsrg[has](colour.toLowerCase().substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
857         var res,
858             red,
859             green,
860             blue,
861             opacity,
862             t,
863             values,
864             rgb = colour.match(colourRegExp);
865         if (rgb) {
866             if (rgb[2]) {
867                 blue = toInt(rgb[2].substring(5), 16);
868                 green = toInt(rgb[2].substring(3, 5), 16);
869                 red = toInt(rgb[2].substring(1, 3), 16);
870             }
871             if (rgb[3]) {
872                 blue = toInt((t = rgb[3].charAt(3)) + t, 16);
873                 green = toInt((t = rgb[3].charAt(2)) + t, 16);
874                 red = toInt((t = rgb[3].charAt(1)) + t, 16);
875             }
876             if (rgb[4]) {
877                 values = rgb[4].split(commaSpaces);
878                 red = toFloat(values[0]);
879                 values[0].slice(-1) == "%" && (red *= 2.55);
880                 green = toFloat(values[1]);
881                 values[1].slice(-1) == "%" && (green *= 2.55);
882                 blue = toFloat(values[2]);
883                 values[2].slice(-1) == "%" && (blue *= 2.55);
884                 rgb[1].toLowerCase().slice(0, 4) == "rgba" && (opacity = toFloat(values[3]));
885                 values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
886             }
887             if (rgb[5]) {
888                 values = rgb[5].split(commaSpaces);
889                 red = toFloat(values[0]);
890                 values[0].slice(-1) == "%" && (red *= 2.55);
891                 green = toFloat(values[1]);
892                 values[1].slice(-1) == "%" && (green *= 2.55);
893                 blue = toFloat(values[2]);
894                 values[2].slice(-1) == "%" && (blue *= 2.55);
895                 (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
896                 rgb[1].toLowerCase().slice(0, 4) == "hsba" && (opacity = toFloat(values[3]));
897                 values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
898                 return R.hsb2rgb(red, green, blue, opacity);
899             }
900             if (rgb[6]) {
901                 values = rgb[6].split(commaSpaces);
902                 red = toFloat(values[0]);
903                 values[0].slice(-1) == "%" && (red *= 2.55);
904                 green = toFloat(values[1]);
905                 values[1].slice(-1) == "%" && (green *= 2.55);
906                 blue = toFloat(values[2]);
907                 values[2].slice(-1) == "%" && (blue *= 2.55);
908                 (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
909                 rgb[1].toLowerCase().slice(0, 4) == "hsla" && (opacity = toFloat(values[3]));
910                 values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
911                 return R.hsl2rgb(red, green, blue, opacity);
912             }
913             rgb = {r: red, g: green, b: blue, toString: clrToString};
914             rgb.hex = "#" + (16777216 | blue | (green << 8) | (red << 16)).toString(16).slice(1);
915             R.is(opacity, "finite") && (rgb.opacity = opacity);
916             return rgb;
917         }
918         return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
919     }, R);
920     /*\
921      * Raphael.hsb
922      [ method ]
923      **
924      * Converts HSB values to hex representation of the colour.
925      > Parameters
926      - h (number) hue
927      - s (number) saturation
928      - b (number) value or brightness
929      = (string) hex representation of the colour.
930     \*/
931     R.hsb = cacher(function (h, s, b) {
932         return R.hsb2rgb(h, s, b).hex;
933     });
934     /*\
935      * Raphael.hsl
936      [ method ]
937      **
938      * Converts HSL values to hex representation of the colour.
939      > Parameters
940      - h (number) hue
941      - s (number) saturation
942      - l (number) luminosity
943      = (string) hex representation of the colour.
944     \*/
945     R.hsl = cacher(function (h, s, l) {
946         return R.hsl2rgb(h, s, l).hex;
947     });
948     /*\
949      * Raphael.rgb
950      [ method ]
951      **
952      * Converts RGB values to hex representation of the colour.
953      > Parameters
954      - r (number) red
955      - g (number) green
956      - b (number) blue
957      = (string) hex representation of the colour.
958     \*/
959     R.rgb = cacher(function (r, g, b) {
960         return "#" + (16777216 | b | (g << 8) | (r << 16)).toString(16).slice(1);
961     });
962     /*\
963      * Raphael.getColor
964      [ method ]
965      **
966      * On each call returns next colour in the spectrum. To reset it back to red call @Raphael.getColor.reset
967      > Parameters
968      - value (number) #optional brightness, default is `0.75`
969      = (string) hex representation of the colour.
970     \*/
971     R.getColor = function (value) {
972         var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
973             rgb = this.hsb2rgb(start.h, start.s, start.b);
974         start.h += .075;
975         if (start.h > 1) {
976             start.h = 0;
977             start.s -= .2;
978             start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
979         }
980         return rgb.hex;
981     };
982     /*\
983      * Raphael.getColor.reset
984      [ method ]
985      **
986      * Resets spectrum position for @Raphael.getColor back to red.
987     \*/
988     R.getColor.reset = function () {
989         delete this.start;
990     };
991
992     /*\
993      * Raphael.parsePathString
994      [ method ]
995      **
996      * Utility method
997      **
998      * Parses given path string into an array of arrays of path segments.
999      > Parameters
1000      - pathString (string|array) path string or array of segments (in the last case it will be returned straight away)
1001      = (array) array of segments.
1002     \*/
1003     R.parsePathString = cacher(function (pathString) {
1004         if (!pathString) {
1005             return null;
1006         }
1007         var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
1008             data = [];
1009         if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
1010             data = pathClone(pathString);
1011         }
1012         if (!data.length) {
1013             Str(pathString).replace(pathCommand, function (a, b, c) {
1014                 var params = [],
1015                     name = lowerCase.call(b);
1016                 c.replace(pathValues, function (a, b) {
1017                     b && params.push(+b);
1018                 });
1019                 if (name == "m" && params.length > 2) {
1020                     data.push([b][concat](params.splice(0, 2)));
1021                     name = "l";
1022                     b = b == "m" ? "l" : "L";
1023                 }
1024                 while (params.length >= paramCounts[name]) {
1025                     data.push([b][concat](params.splice(0, paramCounts[name])));
1026                     if (!paramCounts[name]) {
1027                         break;
1028                     }
1029                 }
1030             });
1031         }
1032         data.toString = R._path2string;
1033         return data;
1034     });
1035     /*\
1036      * Raphael.parseTransformString
1037      [ method ]
1038      **
1039      * Utility method
1040      **
1041      * Parses given path string into an array of transformations.
1042      > Parameters
1043      - TString (string|array) transform string or array of transformations (in the last case it will be returned straight away)
1044      = (array) array of transformations.
1045     \*/
1046     R.parseTransformString = cacher(function (TString) {
1047         if (!TString) {
1048             return null;
1049         }
1050         var paramCounts = {r: 3, s: 4, t: 2, m: 6},
1051             data = [];
1052         if (R.is(TString, array) && R.is(TString[0], array)) { // rough assumption
1053             data = pathClone(TString);
1054         }
1055         if (!data.length) {
1056             Str(TString).replace(tCommand, function (a, b, c) {
1057                 var params = [],
1058                     name = lowerCase.call(b);
1059                 c.replace(pathValues, function (a, b) {
1060                     b && params.push(+b);
1061                 });
1062                 data.push([name][concat](params));
1063             });
1064         }
1065         data.toString = R._path2string;
1066         return data;
1067     });
1068     /*\
1069      * Raphael.findDotsAtSegment
1070      [ method ]
1071      **
1072      * Utility method
1073      **
1074      * Find dot coordinates on the given cubic bezier curve at the given t.
1075      > Parameters
1076      - p1x (number) x of the first point of the curve
1077      - p1y (number) y of the first point of the curve
1078      - c1x (number) x of the first anchor of the curve
1079      - c1y (number) y of the first anchor of the curve
1080      - c2x (number) x of the second anchor of the curve
1081      - c2y (number) y of the second anchor of the curve
1082      - p2x (number) x of the second point of the curve
1083      - p2y (number) y of the second point of the curve
1084      - t (number) position on the curve (0..1)
1085      = (object) point information in format:
1086      o {
1087      o     x: (number) x coordinate of the point
1088      o     y: (number) y coordinate of the point
1089      o     m: {
1090      o         x: (number) x coordinate of the left anchor
1091      o         y: (number) y coordinate of the left anchor
1092      o     }
1093      o     n: {
1094      o         x: (number) x coordinate of the right anchor
1095      o         y: (number) y coordinate of the right anchor
1096      o     }
1097      o     start: {
1098      o         x: (number) x coordinate of the start of the curve
1099      o         y: (number) y coordinate of the start of the curve
1100      o     }
1101      o     end: {
1102      o         x: (number) x coordinate of the end of the curve
1103      o         y: (number) y coordinate of the end of the curve
1104      o     }
1105      o     alpha: (number) angle of the curve derivative at the point
1106      o }
1107     \*/
1108     R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
1109         var t1 = 1 - t,
1110             x = pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
1111             y = pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y,
1112             mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x),
1113             my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y),
1114             nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x),
1115             ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y),
1116             ax = (1 - t) * p1x + t * c1x,
1117             ay = (1 - t) * p1y + t * c1y,
1118             cx = (1 - t) * c2x + t * p2x,
1119             cy = (1 - t) * c2y + t * p2y,
1120             alpha = (90 - math.atan2(mx - nx, my - ny) * 180 / PI);
1121         (mx > nx || my < ny) && (alpha += 180);
1122         return {
1123             x: x,
1124             y: y,
1125             m: {x: mx, y: my},
1126             n: {x: nx, y: ny},
1127             start: {x: ax, y: ay},
1128             end: {x: cx, y: cy},
1129             alpha: alpha
1130         };
1131     };
1132     var pathDimensions = cacher(function (path) {
1133         if (!path) {
1134             return {x: 0, y: 0, width: 0, height: 0};
1135         }
1136         path = path2curve(path);
1137         var x = 0, 
1138             y = 0,
1139             X = [],
1140             Y = [],
1141             p;
1142         for (var i = 0, ii = path.length; i < ii; i++) {
1143             p = path[i];
1144             if (p[0] == "M") {
1145                 x = p[1];
1146                 y = p[2];
1147                 X.push(x);
1148                 Y.push(y);
1149             } else {
1150                 var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
1151                 X = X[concat](dim.min.x, dim.max.x);
1152                 Y = Y[concat](dim.min.y, dim.max.y);
1153                 x = p[5];
1154                 y = p[6];
1155             }
1156         }
1157         var xmin = mmin[apply](0, X),
1158             ymin = mmin[apply](0, Y);
1159         return {
1160             x: xmin,
1161             y: ymin,
1162             width: mmax[apply](0, X) - xmin,
1163             height: mmax[apply](0, Y) - ymin
1164         };
1165     }, null, function (o) {
1166         return {
1167             x: o.x,
1168             y: o.y,
1169             width: o.width,
1170             height: o.height
1171         };
1172     }),
1173         pathClone = function (pathArray) {
1174             var res = [];
1175             if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
1176                 pathArray = R.parsePathString(pathArray);
1177             }
1178             for (var i = 0, ii = pathArray.length; i < ii; i++) {
1179                 res[i] = [];
1180                 for (var j = 0, jj = pathArray[i].length; j < jj; j++) {
1181                     res[i][j] = pathArray[i][j];
1182                 }
1183             }
1184             res.toString = R._path2string;
1185             return res;
1186         },
1187         pathToRelative = R._pathToRelative = cacher(function (pathArray) {
1188             if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
1189                 pathArray = R.parsePathString(pathArray);
1190             }
1191             var res = [],
1192                 x = 0,
1193                 y = 0,
1194                 mx = 0,
1195                 my = 0,
1196                 start = 0;
1197             if (pathArray[0][0] == "M") {
1198                 x = pathArray[0][1];
1199                 y = pathArray[0][2];
1200                 mx = x;
1201                 my = y;
1202                 start++;
1203                 res.push(["M", x, y]);
1204             }
1205             for (var i = start, ii = pathArray.length; i < ii; i++) {
1206                 var r = res[i] = [],
1207                     pa = pathArray[i];
1208                 if (pa[0] != lowerCase.call(pa[0])) {
1209                     r[0] = lowerCase.call(pa[0]);
1210                     switch (r[0]) {
1211                         case "a":
1212                             r[1] = pa[1];
1213                             r[2] = pa[2];
1214                             r[3] = pa[3];
1215                             r[4] = pa[4];
1216                             r[5] = pa[5];
1217                             r[6] = +(pa[6] - x).toFixed(3);
1218                             r[7] = +(pa[7] - y).toFixed(3);
1219                             break;
1220                         case "v":
1221                             r[1] = +(pa[1] - y).toFixed(3);
1222                             break;
1223                         case "m":
1224                             mx = pa[1];
1225                             my = pa[2];
1226                         default:
1227                             for (var j = 1, jj = pa.length; j < jj; j++) {
1228                                 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
1229                             }
1230                     }
1231                 } else {
1232                     r = res[i] = [];
1233                     if (pa[0] == "m") {
1234                         mx = pa[1] + x;
1235                         my = pa[2] + y;
1236                     }
1237                     for (var k = 0, kk = pa.length; k < kk; k++) {
1238                         res[i][k] = pa[k];
1239                     }
1240                 }
1241                 var len = res[i].length;
1242                 switch (res[i][0]) {
1243                     case "z":
1244                         x = mx;
1245                         y = my;
1246                         break;
1247                     case "h":
1248                         x += +res[i][len - 1];
1249                         break;
1250                     case "v":
1251                         y += +res[i][len - 1];
1252                         break;
1253                     default:
1254                         x += +res[i][len - 2];
1255                         y += +res[i][len - 1];
1256                 }
1257             }
1258             res.toString = R._path2string;
1259             return res;
1260         }, 0, pathClone),
1261         pathToAbsolute = R._pathToAbsolute = cacher(function (pathArray) {
1262             if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
1263                 pathArray = R.parsePathString(pathArray);
1264             }
1265             if (!pathArray || !pathArray.length) {
1266                 return [["M", 0, 0]];
1267             }
1268             var res = [],
1269                 x = 0,
1270                 y = 0,
1271                 mx = 0,
1272                 my = 0,
1273                 start = 0;
1274             if (pathArray[0][0] == "M") {
1275                 x = +pathArray[0][1];
1276                 y = +pathArray[0][2];
1277                 mx = x;
1278                 my = y;
1279                 start++;
1280                 res[0] = ["M", x, y];
1281             }
1282             for (var i = start, ii = pathArray.length; i < ii; i++) {
1283                 var r = res[i] = [],
1284                     pa = pathArray[i];
1285                 if (pa[0] != upperCase.call(pa[0])) {
1286                     r[0] = upperCase.call(pa[0]);
1287                     switch (r[0]) {
1288                         case "A":
1289                             r[1] = pa[1];
1290                             r[2] = pa[2];
1291                             r[3] = pa[3];
1292                             r[4] = pa[4];
1293                             r[5] = pa[5];
1294                             r[6] = +(pa[6] + x);
1295                             r[7] = +(pa[7] + y);
1296                             break;
1297                         case "V":
1298                             r[1] = +pa[1] + y;
1299                             break;
1300                         case "H":
1301                             r[1] = +pa[1] + x;
1302                             break;
1303                         case "M":
1304                             mx = +pa[1] + x;
1305                             my = +pa[2] + y;
1306                         default:
1307                             for (var j = 1, jj = pa.length; j < jj; j++) {
1308                                 r[j] = +pa[j] + ((j % 2) ? x : y);
1309                             }
1310                     }
1311                 } else {
1312                     for (var k = 0, kk = pa.length; k < kk; k++) {
1313                         res[i][k] = pa[k];
1314                     }
1315                 }
1316                 switch (r[0]) {
1317                     case "Z":
1318                         x = mx;
1319                         y = my;
1320                         break;
1321                     case "H":
1322                         x = r[1];
1323                         break;
1324                     case "V":
1325                         y = r[1];
1326                         break;
1327                     case "M":
1328                         mx = res[i][res[i].length - 2];
1329                         my = res[i][res[i].length - 1];
1330                     default:
1331                         x = res[i][res[i].length - 2];
1332                         y = res[i][res[i].length - 1];
1333                 }
1334             }
1335             res.toString = R._path2string;
1336             return res;
1337         }, null, pathClone),
1338         l2c = function (x1, y1, x2, y2) {
1339             return [x1, y1, x2, y2, x2, y2];
1340         },
1341         q2c = function (x1, y1, ax, ay, x2, y2) {
1342             var _13 = 1 / 3,
1343                 _23 = 2 / 3;
1344             return [
1345                     _13 * x1 + _23 * ax,
1346                     _13 * y1 + _23 * ay,
1347                     _13 * x2 + _23 * ax,
1348                     _13 * y2 + _23 * ay,
1349                     x2,
1350                     y2
1351                 ];
1352         },
1353         a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
1354             // for more information of where this math came from visit:
1355             // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
1356             var _120 = PI * 120 / 180,
1357                 rad = PI / 180 * (+angle || 0),
1358                 res = [],
1359                 xy,
1360                 rotate = cacher(function (x, y, rad) {
1361                     var X = x * math.cos(rad) - y * math.sin(rad),
1362                         Y = x * math.sin(rad) + y * math.cos(rad);
1363                     return {x: X, y: Y};
1364                 });
1365             if (!recursive) {
1366                 xy = rotate(x1, y1, -rad);
1367                 x1 = xy.x;
1368                 y1 = xy.y;
1369                 xy = rotate(x2, y2, -rad);
1370                 x2 = xy.x;
1371                 y2 = xy.y;
1372                 var cos = math.cos(PI / 180 * angle),
1373                     sin = math.sin(PI / 180 * angle),
1374                     x = (x1 - x2) / 2,
1375                     y = (y1 - y2) / 2;
1376                 var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
1377                 if (h > 1) {
1378                     h = math.sqrt(h);
1379                     rx = h * rx;
1380                     ry = h * ry;
1381                 }
1382                 var rx2 = rx * rx,
1383                     ry2 = ry * ry,
1384                     k = (large_arc_flag == sweep_flag ? -1 : 1) *
1385                         math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
1386                     cx = k * rx * y / ry + (x1 + x2) / 2,
1387                     cy = k * -ry * x / rx + (y1 + y2) / 2,
1388                     f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
1389                     f2 = math.asin(((y2 - cy) / ry).toFixed(9));
1390
1391                 f1 = x1 < cx ? PI - f1 : f1;
1392                 f2 = x2 < cx ? PI - f2 : f2;
1393                 f1 < 0 && (f1 = PI * 2 + f1);
1394                 f2 < 0 && (f2 = PI * 2 + f2);
1395                 if (sweep_flag && f1 > f2) {
1396                     f1 = f1 - PI * 2;
1397                 }
1398                 if (!sweep_flag && f2 > f1) {
1399                     f2 = f2 - PI * 2;
1400                 }
1401             } else {
1402                 f1 = recursive[0];
1403                 f2 = recursive[1];
1404                 cx = recursive[2];
1405                 cy = recursive[3];
1406             }
1407             var df = f2 - f1;
1408             if (abs(df) > _120) {
1409                 var f2old = f2,
1410                     x2old = x2,
1411                     y2old = y2;
1412                 f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
1413                 x2 = cx + rx * math.cos(f2);
1414                 y2 = cy + ry * math.sin(f2);
1415                 res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
1416             }
1417             df = f2 - f1;
1418             var c1 = math.cos(f1),
1419                 s1 = math.sin(f1),
1420                 c2 = math.cos(f2),
1421                 s2 = math.sin(f2),
1422                 t = math.tan(df / 4),
1423                 hx = 4 / 3 * rx * t,
1424                 hy = 4 / 3 * ry * t,
1425                 m1 = [x1, y1],
1426                 m2 = [x1 + hx * s1, y1 - hy * c1],
1427                 m3 = [x2 + hx * s2, y2 - hy * c2],
1428                 m4 = [x2, y2];
1429             m2[0] = 2 * m1[0] - m2[0];
1430             m2[1] = 2 * m1[1] - m2[1];
1431             if (recursive) {
1432                 return [m2, m3, m4][concat](res);
1433             } else {
1434                 res = [m2, m3, m4][concat](res).join().split(",");
1435                 var newres = [];
1436                 for (var i = 0, ii = res.length; i < ii; i++) {
1437                     newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
1438                 }
1439                 return newres;
1440             }
1441         },
1442         findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
1443             var t1 = 1 - t;
1444             return {
1445                 x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
1446                 y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
1447             };
1448         },
1449         curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
1450             var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
1451                 b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
1452                 c = p1x - c1x,
1453                 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
1454                 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
1455                 y = [p1y, p2y],
1456                 x = [p1x, p2x],
1457                 dot;
1458             abs(t1) > "1e12" && (t1 = .5);
1459             abs(t2) > "1e12" && (t2 = .5);
1460             if (t1 > 0 && t1 < 1) {
1461                 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
1462                 x.push(dot.x);
1463                 y.push(dot.y);
1464             }
1465             if (t2 > 0 && t2 < 1) {
1466                 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
1467                 x.push(dot.x);
1468                 y.push(dot.y);
1469             }
1470             a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
1471             b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
1472             c = p1y - c1y;
1473             t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
1474             t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
1475             abs(t1) > "1e12" && (t1 = .5);
1476             abs(t2) > "1e12" && (t2 = .5);
1477             if (t1 > 0 && t1 < 1) {
1478                 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
1479                 x.push(dot.x);
1480                 y.push(dot.y);
1481             }
1482             if (t2 > 0 && t2 < 1) {
1483                 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
1484                 x.push(dot.x);
1485                 y.push(dot.y);
1486             }
1487             return {
1488                 min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
1489                 max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
1490             };
1491         }),
1492         path2curve = cacher(function (path, path2) {
1493             var p = pathToAbsolute(path),
1494                 p2 = path2 && pathToAbsolute(path2),
1495                 attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
1496                 attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
1497                 processPath = function (path, d) {
1498                     var nx, ny;
1499                     if (!path) {
1500                         return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
1501                     }
1502                     !(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null);
1503                     switch (path[0]) {
1504                         case "M":
1505                             d.X = path[1];
1506                             d.Y = path[2];
1507                             break;
1508                         case "A":
1509                             path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
1510                             break;
1511                         case "S":
1512                             nx = d.x + (d.x - (d.bx || d.x));
1513                             ny = d.y + (d.y - (d.by || d.y));
1514                             path = ["C", nx, ny][concat](path.slice(1));
1515                             break;
1516                         case "T":
1517                             d.qx = d.x + (d.x - (d.qx || d.x));
1518                             d.qy = d.y + (d.y - (d.qy || d.y));
1519                             path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
1520                             break;
1521                         case "Q":
1522                             d.qx = path[1];
1523                             d.qy = path[2];
1524                             path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
1525                             break;
1526                         case "L":
1527                             path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
1528                             break;
1529                         case "H":
1530                             path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
1531                             break;
1532                         case "V":
1533                             path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
1534                             break;
1535                         case "Z":
1536                             path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
1537                             break;
1538                     }
1539                     return path;
1540                 },
1541                 fixArc = function (pp, i) {
1542                     if (pp[i].length > 7) {
1543                         pp[i].shift();
1544                         var pi = pp[i];
1545                         while (pi.length) {
1546                             pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
1547                         }
1548                         pp.splice(i, 1);
1549                         ii = mmax(p.length, p2 && p2.length || 0);
1550                     }
1551                 },
1552                 fixM = function (path1, path2, a1, a2, i) {
1553                     if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
1554                         path2.splice(i, 0, ["M", a2.x, a2.y]);
1555                         a1.bx = 0;
1556                         a1.by = 0;
1557                         a1.x = path1[i][1];
1558                         a1.y = path1[i][2];
1559                         ii = mmax(p.length, p2 && p2.length || 0);
1560                     }
1561                 };
1562             for (var i = 0, ii = mmax(p.length, p2 && p2.length || 0); i < ii; i++) {
1563                 p[i] = processPath(p[i], attrs);
1564                 fixArc(p, i);
1565                 p2 && (p2[i] = processPath(p2[i], attrs2));
1566                 p2 && fixArc(p2, i);
1567                 fixM(p, p2, attrs, attrs2, i);
1568                 fixM(p2, p, attrs2, attrs, i);
1569                 var seg = p[i],
1570                     seg2 = p2 && p2[i],
1571                     seglen = seg.length,
1572                     seg2len = p2 && seg2.length;
1573                 attrs.x = seg[seglen - 2];
1574                 attrs.y = seg[seglen - 1];
1575                 attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
1576                 attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
1577                 attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
1578                 attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
1579                 attrs2.x = p2 && seg2[seg2len - 2];
1580                 attrs2.y = p2 && seg2[seg2len - 1];
1581             }
1582             return p2 ? [p, p2] : p;
1583         }, null, pathClone),
1584         parseDots = R._parseDots = cacher(function (gradient) {
1585             var dots = [];
1586             for (var i = 0, ii = gradient.length; i < ii; i++) {
1587                 var dot = {},
1588                     par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
1589                 dot.color = R.getRGB(par[1]);
1590                 if (dot.color.error) {
1591                     return null;
1592                 }
1593                 dot.color = dot.color.hex;
1594                 par[2] && (dot.offset = par[2] + "%");
1595                 dots.push(dot);
1596             }
1597             for (i = 1, ii = dots.length - 1; i < ii; i++) {
1598                 if (!dots[i].offset) {
1599                     var start = toFloat(dots[i - 1].offset || 0),
1600                         end = 0;
1601                     for (var j = i + 1; j < ii; j++) {
1602                         if (dots[j].offset) {
1603                             end = dots[j].offset;
1604                             break;
1605                         }
1606                     }
1607                     if (!end) {
1608                         end = 100;
1609                         j = ii;
1610                     }
1611                     end = toFloat(end);
1612                     var d = (end - start) / (j - i + 1);
1613                     for (; i < j; i++) {
1614                         start += d;
1615                         dots[i].offset = start + "%";
1616                     }
1617                 }
1618             }
1619             return dots;
1620         }),
1621         tear = R._tear = function (el, paper) {
1622             el == paper.top && (paper.top = el.prev);
1623             el == paper.bottom && (paper.bottom = el.next);
1624             el.next && (el.next.prev = el.prev);
1625             el.prev && (el.prev.next = el.next);
1626         },
1627         tofront = R._tofront = function (el, paper) {
1628             if (paper.top === el) {
1629                 return;
1630             }
1631             tear(el, paper);
1632             el.next = null;
1633             el.prev = paper.top;
1634             paper.top.next = el;
1635             paper.top = el;
1636         },
1637         toback = R._toback = function (el, paper) {
1638             if (paper.bottom === el) {
1639                 return;
1640             }
1641             tear(el, paper);
1642             el.next = paper.bottom;
1643             el.prev = null;
1644             paper.bottom.prev = el;
1645             paper.bottom = el;
1646         },
1647         insertafter = R._insertafter = function (el, el2, paper) {
1648             tear(el, paper);
1649             el2 == paper.top && (paper.top = el);
1650             el2.next && (el2.next.prev = el);
1651             el.next = el2.next;
1652             el.prev = el2;
1653             el2.next = el;
1654         },
1655         insertbefore = R._insertbefore = function (el, el2, paper) {
1656             tear(el, paper);
1657             el2 == paper.bottom && (paper.bottom = el);
1658             el2.prev && (el2.prev.next = el);
1659             el.prev = el2.prev;
1660             el2.prev = el;
1661             el.next = el2;
1662         },
1663         removed = function (methodname) {
1664             return function () {
1665                 throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object");
1666             };
1667         },
1668         extractTransform = R._extractTransform = function (el, tstr) {
1669             if (tstr == null) {
1670                 return el._.transform;
1671             }
1672             tstr = Str(tstr).replace(/\.{3}|\u2026/g, el._.transform || E);
1673             var tdata = R.parseTransformString(tstr),
1674                 deg = 0,
1675                 dx = 0,
1676                 dy = 0,
1677                 sx = 1,
1678                 sy = 1,
1679                 _ = el._,
1680                 m = new Matrix;
1681             _.transform = tdata || [];
1682             if (tdata) {
1683                 for (var i = 0, ii = tdata.length; i < ii; i++) {
1684                     var t = tdata[i],
1685                         tlen = t.length,
1686                         bb;
1687                     t[0] = Str(t[0]).toLowerCase();
1688                     if (t[0] == "t" && tlen == 3) {
1689                         m.translate(t[1], t[2]);
1690                     } else if (t[0] == "r") {
1691                         if (tlen == 2) {
1692                             bb = bb || el.getBBox(1);
1693                             m.rotate(t[1], bb.x + bb.width / 2, bb.y + bb.height / 2);
1694                             deg += t[1];
1695                         } else if (tlen == 4) {
1696                             m.rotate(t[1], t[2], t[3]);
1697                             deg += t[1];
1698                         }
1699                     } else if (t[0] == "s") {
1700                         if (tlen == 2 || tlen == 3) {
1701                             bb = bb || el.getBBox(1);
1702                             m.scale(t[1], t[tlen - 1], bb.x + bb.width / 2, bb.y + bb.height / 2);
1703                             sx *= t[1];
1704                             sy *= t[tlen - 1];
1705                         } else if (tlen == 5) {
1706                             m.scale(t[1], t[2], t[3], t[4]);
1707                             sx *= t[1];
1708                             sy *= t[2];
1709                         }
1710                     } else if (t[0] == "m" && tlen == 7) {
1711                         m.add(t[1], t[2], t[3], t[4], t[5], t[6]);
1712                     }
1713                     _.dirtyT = 1;
1714                     el.matrix = m;
1715                 }
1716             }
1717
1718             el.matrix = m;
1719
1720             _.sx = sx;
1721             _.sy = sy;
1722             _.deg = deg;
1723             _.dx = dx = m.e;
1724             _.dy = dy = m.f;
1725
1726             if (sx == 1 && sy == 1 && !deg && _.bbox) {
1727                 _.bbox.x += +dx;
1728                 _.bbox.y += +dy;
1729             } else {
1730                 _.dirtyT = 1;
1731             }
1732         },
1733         getEmpty = function (item) {
1734             switch (item[0]) {
1735                 case "t": return ["t", 0, 0];
1736                 case "m": return ["m", 1, 0, 0, 1, 0, 0];
1737                 case "r": if (item.length == 4) {
1738                     return ["r", 0, item[2], item[3]];
1739                 } else {
1740                     return ["r", 0];
1741                 }
1742                 case "s": if (item.length == 5) {
1743                     return ["s", 1, 1, item[3], item[4]];
1744                 } else if (item.length == 3) {
1745                     return ["s", 1, 1];
1746                 } else {
1747                     return ["s", 1];
1748                 }
1749             }
1750         },
1751         equaliseTransform = R._equaliseTransform = function (t1, t2) {
1752             t2 = Str(t2).replace(/\.{3}|\u2026/g, t1);
1753             t1 = R.parseTransformString(t1) || [];
1754             t2 = R.parseTransformString(t2) || [];
1755             var maxlength = mmax(t1.length, t2.length),
1756                 from = [],
1757                 to = [],
1758                 i = 0, j, jj,
1759                 tt1, tt2;
1760             for (; i < maxlength; i++) {
1761                 tt1 = t1[i] || getEmpty(t2[i]);
1762                 tt2 = t2[i] || getEmpty(tt1);
1763                 if ((tt1[0] != tt2[0]) ||
1764                     (tt1[0] == "r" && (tt1[2] != tt2[2] || tt1[3] != tt2[3])) ||
1765                     (tt1[0] == "s" && (tt1[3] != tt2[3] || tt1[4] != tt2[4]))
1766                     ) {
1767                     return;
1768                 }
1769                 from[i] = [];
1770                 to[i] = [];
1771                 for (j = 0, jj = mmax(tt1.length, tt2.length); j < jj; j++) {
1772                     j in tt1 && (from[i][j] = tt1[j]);
1773                     j in tt2 && (to[i][j] = tt2[j]);
1774                 }
1775             }
1776             return {
1777                 from: from,
1778                 to: to
1779             };
1780         };
1781     R._getContainer = function (x, y, w, h) {
1782         var container;
1783         container = h == null && !R.is(x, "object") ? g.doc.getElementById(x) : x;
1784         if (container == null) {
1785             return;
1786         }
1787         if (container.tagName) {
1788             if (y == null) {
1789                 return {
1790                     container: container,
1791                     width: container.style.pixelWidth || container.offsetWidth,
1792                     height: container.style.pixelHeight || container.offsetHeight
1793                 };
1794             } else {
1795                 return {
1796                     container: container,
1797                     width: y,
1798                     height: w
1799                 };
1800             }
1801         }
1802         return {
1803             container: 1,
1804             x: x,
1805             y: y,
1806             width: w,
1807             height: h
1808         };
1809     };
1810     /*\
1811      * Raphael.pathToRelative
1812      [ method ]
1813      **
1814      * Utility method
1815      **
1816      * Converts path to relative form
1817      > Parameters
1818      - pathString (string|array) path string or array of segments
1819      = (array) array of segments.
1820     \*/
1821     R.pathToRelative = pathToRelative;
1822     R._engine = {};
1823     /*\
1824      * Raphael.path2curve
1825      [ method ]
1826      **
1827      * Utility method
1828      **
1829      * Converts path to a new path where all segments are cubic bezier curves.
1830      > Parameters
1831      - pathString (string|array) path string or array of segments
1832      = (array) array of segments.
1833     \*/
1834     R.path2curve = path2curve;
1835     /*\
1836      * Raphael.matrix
1837      [ method ]
1838      **
1839      * Utility method
1840      **
1841      * Returns matrix based on given parameters.
1842      > Parameters
1843      - a (number)
1844      - b (number)
1845      - c (number)
1846      - d (number)
1847      - e (number)
1848      - f (number)
1849      = (object) @Matrix
1850     \*/
1851     R.matrix = function (a, b, c, d, e, f) {
1852         return new Matrix(a, b, c, d, e, f);
1853     };
1854     function Matrix(a, b, c, d, e, f) {
1855         if (a != null) {
1856             this.a = +a;
1857             this.b = +b;
1858             this.c = +c;
1859             this.d = +d;
1860             this.e = +e;
1861             this.f = +f;
1862         } else {
1863             this.a = 1;
1864             this.b = 0;
1865             this.c = 0;
1866             this.d = 1;
1867             this.e = 0;
1868             this.f = 0;
1869         }
1870     }
1871     (function (matrixproto) {
1872         matrixproto.add = function (a, b, c, d, e, f) {
1873             var out = [[], [], []],
1874                 m = [[this.a, this.c, this.e], [this.b, this.d, this.f], [0, 0, 1]],
1875                 matrix = [[a, c, e], [b, d, f], [0, 0, 1]],
1876                 x, y, z, res;
1877
1878             if (a && a instanceof Matrix) {
1879                 matrix = [[a.a, a.c, a.e], [a.b, a.d, a.f], [0, 0, 1]];
1880             }
1881
1882             for (x = 0; x < 3; x++) {
1883                 for (y = 0; y < 3; y++) {
1884                     res = 0;
1885                     for (z = 0; z < 3; z++) {
1886                         res += m[x][z] * matrix[z][y];
1887                     }
1888                     out[x][y] = res;
1889                 }
1890             }
1891             this.a = out[0][0];
1892             this.b = out[1][0];
1893             this.c = out[0][1];
1894             this.d = out[1][1];
1895             this.e = out[0][2];
1896             this.f = out[1][2];
1897         };
1898         matrixproto.invert = function () {
1899             var me = this,
1900                 x = me.a * me.d - me.b * me.c;
1901             return new Matrix(me.d / x, -me.b / x, -me.c / x, me.a / x, (me.c * me.f - me.d * me.e) / x, (me.b * me.e - me.a * me.f) / x);
1902         };
1903         matrixproto.clone = function () {
1904             return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f);
1905         };
1906         matrixproto.translate = function (x, y) {
1907             this.add(1, 0, 0, 1, x, y);
1908         };
1909         matrixproto.scale = function (x, y, cx, cy) {
1910             y == null && (y = x);
1911             this.add(1, 0, 0, 1, cx, cy);
1912             this.add(x, 0, 0, y, 0, 0);
1913             this.add(1, 0, 0, 1, -cx, -cy);
1914         };
1915         matrixproto.rotate = function (a, x, y) {
1916             a = R.rad(a);
1917             var cos = +math.cos(a).toFixed(9),
1918                 sin = +math.sin(a).toFixed(9);
1919             this.add(cos, sin, -sin, cos, x, y);
1920             this.add(1, 0, 0, 1, -x, -y);
1921         };
1922         matrixproto.x = function (x, y) {
1923             return x * this.a + y * this.c + this.e;
1924         };
1925         matrixproto.y = function (x, y) {
1926             return x * this.b + y * this.d + this.f;
1927         };
1928         matrixproto.get = function (i) {
1929             return +this[Str.fromCharCode(97 + i)].toFixed(4);
1930         };
1931         matrixproto.toString = function () {
1932             return R.svg ?
1933                 "matrix(" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)].join() + ")" :
1934                 [this.get(0), this.get(2), this.get(1), this.get(3), 0, 0].join();
1935         };
1936         matrixproto.toFilter = function () {
1937             return "progid:DXImageTransform.Microsoft.Matrix(M11=" + this.get(0) +
1938                 ", M12=" + this.get(2) + ", M21=" + this.get(1) + ", M22=" + this.get(3) +
1939                 ", Dx=" + this.get(4) + ", Dy=" + this.get(5) + ", sizingmethod='auto expand')";
1940         };
1941         matrixproto.offset = function () {
1942             return [this.e.toFixed(4), this.f.toFixed(4)];
1943         };
1944         function norm(a) {
1945             return a[0] * a[0] + a[1] * a[1];
1946         }
1947         function normalize(a) {
1948             var mag = math.sqrt(norm(a));
1949             a[0] && (a[0] /= mag);
1950             a[1] && (a[1] /= mag);
1951         }
1952         matrixproto.split = function () {
1953             var out = {};
1954             // translation
1955             out.dx = this.e;
1956             out.dy = this.f;
1957
1958             // scale and shear
1959             var row = [[this.a, this.c], [this.b, this.d]];
1960             out.scalex = math.sqrt(norm(row[0]));
1961             normalize(row[0]);
1962
1963             out.shear = row[0][0] * row[1][0] + row[0][1] * row[1][1];
1964             row[1] = [row[1][0] - row[0][0] * out.shear, row[1][1] - row[0][1] * out.shear];
1965
1966             out.scaley = math.sqrt(norm(row[1]));
1967             normalize(row[1]);
1968             out.shear /= out.scaley;
1969
1970             // rotation
1971             var sin = -row[0][1],
1972                 cos = row[1][1];
1973             if (cos < 0) {
1974                 out.rotate = R.deg(math.acos(cos));
1975                 if (sin < 0) {
1976                     out.rotate = 360 - out.rotate;
1977                 }
1978             } else {
1979                 out.rotate = R.deg(math.asin(sin));
1980             }
1981
1982             out.isSimple = !+out.shear.toFixed(9) && (out.scalex.toFixed(9) == out.scaley.toFixed(9) || !out.rotate);
1983             out.isSuperSimple = !+out.shear.toFixed(9) && out.scalex.toFixed(9) == out.scaley.toFixed(9) && !out.rotate;
1984             out.noRotation = !+out.shear.toFixed(9) && !out.rotate;
1985             return out;
1986         };
1987         matrixproto.toTransformString = function () {
1988             var s = this.split();
1989             if (s.isSimple) {
1990                 return "t" + [s.dx, s.dy] + "s" + [s.scalex, s.scaley, 0, 0] + "r" + [s.rotate, 0, 0];
1991             } else {
1992                 return "m" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)];
1993             }
1994         };
1995     })(Matrix.prototype);
1996
1997     // WebKit rendering bug workaround method
1998     var version = navigator.userAgent.match(/Version\/(.*?)\s/) || navigator.userAgent.match(/Chrome\/(\d+)/);
1999     if ((navigator.vendor == "Apple Computer, Inc.") && (version && version[1] < 4 || navigator.platform.slice(0, 2) == "iP") ||
2000         (navigator.vendor == "Google Inc." && version && version[1] < 8)) {
2001         /*\
2002          * Paper.safari
2003          [ method ]
2004          **
2005          * There is an inconvenient rendering bug in Safari (WebKit):
2006          * sometimes the rendering should be forced.
2007          * This method should help with dealing with this bug.
2008         \*/
2009         paperproto.safari = function () {
2010             var rect = this.rect(-99, -99, this.width + 99, this.height + 99).attr({stroke: "none"});
2011             setTimeout(function () {rect.remove();});
2012         };
2013     } else {
2014         paperproto.safari = fun;
2015     }
2016  
2017     // Events
2018     var preventDefault = function () {
2019         this.returnValue = false;
2020     },
2021     preventTouch = function () {
2022         return this.originalEvent.preventDefault();
2023     },
2024     stopPropagation = function () {
2025         this.cancelBubble = true;
2026     },
2027     stopTouch = function () {
2028         return this.originalEvent.stopPropagation();
2029     },
2030     addEvent = (function () {
2031         if (g.doc.addEventListener) {
2032             return function (obj, type, fn, element) {
2033                 var realName = supportsTouch && touchMap[type] ? touchMap[type] : type,
2034                     f = function (e) {
2035                         var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
2036                             scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
2037                             x = e.clientX + scrollX,
2038                             y = e.clientY + scrollY;
2039                     if (supportsTouch && touchMap[has](type)) {
2040                         for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
2041                             if (e.targetTouches[i].target == obj) {
2042                                 var olde = e;
2043                                 e = e.targetTouches[i];
2044                                 e.originalEvent = olde;
2045                                 e.preventDefault = preventTouch;
2046                                 e.stopPropagation = stopTouch;
2047                                 break;
2048                             }
2049                         }
2050                     }
2051                     return fn.call(element, e, x, y);
2052                 };
2053                 obj.addEventListener(realName, f, false);
2054                 return function () {
2055                     obj.removeEventListener(realName, f, false);
2056                     return true;
2057                 };
2058             };
2059         } else if (g.doc.attachEvent) {
2060             return function (obj, type, fn, element) {
2061                 var f = function (e) {
2062                     e = e || g.win.event;
2063                     var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
2064                         scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
2065                         x = e.clientX + scrollX,
2066                         y = e.clientY + scrollY;
2067                     e.preventDefault = e.preventDefault || preventDefault;
2068                     e.stopPropagation = e.stopPropagation || stopPropagation;
2069                     return fn.call(element, e, x, y);
2070                 };
2071                 obj.attachEvent("on" + type, f);
2072                 var detacher = function () {
2073                     obj.detachEvent("on" + type, f);
2074                     return true;
2075                 };
2076                 return detacher;
2077             };
2078         }
2079     })(),
2080     drag = [],
2081     dragMove = function (e) {
2082         var x = e.clientX,
2083             y = e.clientY,
2084             scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
2085             scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
2086             dragi,
2087             j = drag.length;
2088         while (j--) {
2089             dragi = drag[j];
2090             if (supportsTouch) {
2091                 var i = e.touches.length,
2092                     touch;
2093                 while (i--) {
2094                     touch = e.touches[i];
2095                     if (touch.identifier == dragi.el._drag.id) {
2096                         x = touch.clientX;
2097                         y = touch.clientY;
2098                         (e.originalEvent ? e.originalEvent : e).preventDefault();
2099                         break;
2100                     }
2101                 }
2102             } else {
2103                 e.preventDefault();
2104             }
2105             var node = dragi.el.node,
2106                 o,
2107                 next = node.nextSibling,
2108                 parent = node.parentNode,
2109                 display = node.style.display;
2110             g.win.opera && parent.removeChild(node);
2111             node.style.display = "none";
2112             o = dragi.el.paper.getElementByPoint(x, y);
2113             node.style.display = display;
2114             g.win.opera && (next ? parent.insertBefore(node, next) : parent.appendChild(node));
2115             o && eve("drag.over." + dragi.el.id, dragi.el, o);
2116             x += scrollX;
2117             y += scrollY;
2118             eve("drag.move." + dragi.el.id, dragi.move_scope || dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y, e);
2119         }
2120     },
2121     dragUp = function (e) {
2122         R.unmousemove(dragMove).unmouseup(dragUp);
2123         var i = drag.length,
2124             dragi;
2125         while (i--) {
2126             dragi = drag[i];
2127             dragi.el._drag = {};
2128             eve("drag.end." + dragi.el.id, dragi.end_scope || dragi.start_scope || dragi.move_scope || dragi.el, e);
2129         }
2130         drag = [];
2131     },
2132     /*\
2133      * Raphael.el
2134      [ property (object) ]
2135      **
2136      * You can add your own method to elements. This is usefull when you want to hack default functionality or
2137      * want to wrap some common transformation or attributes in one method. In difference to canvas methods,
2138      * you can redefine element method at any time. Expending element methods wouldn’t affect set.
2139      > Usage
2140      | Raphael.el.red = function () {
2141      |     this.attr({fill: "#f00"});
2142      | };
2143      | // then use it
2144      | paper.circle(100, 100, 20).red();
2145     \*/
2146     elproto = R.el = {};
2147     for (var i = events.length; i--;) {
2148         (function (eventName) {
2149             R[eventName] = elproto[eventName] = function (fn, scope) {
2150                 if (R.is(fn, "function")) {
2151                     this.events = this.events || [];
2152                     this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || g.doc, eventName, fn, scope || this)});
2153                 }
2154                 return this;
2155             };
2156             R["un" + eventName] = elproto["un" + eventName] = function (fn) {
2157                 var events = this.events,
2158                     l = events.length;
2159                 while (l--) if (events[l].name == eventName && events[l].f == fn) {
2160                     events[l].unbind();
2161                     events.splice(l, 1);
2162                     !events.length && delete this.events;
2163                     return this;
2164                 }
2165                 return this;
2166             };
2167         })(events[i]);
2168     }
2169     
2170     /*\
2171      * Element.hover
2172      [ method ]
2173      **
2174      * Adds event handlers for hover for the element.
2175      > Parameters
2176      - f_in (function) handler for hover in
2177      - f_out (function) handler for hover out
2178      - icontext (object) #optional context for hover in handler
2179      - ocontext (object) #optional context for hover out handler
2180      = (object) @Element
2181     \*/
2182     elproto.hover = function (f_in, f_out, scope_in, scope_out) {
2183         return this.mouseover(f_in, scope_in).mouseout(f_out, scope_out || scope_in);
2184     };
2185     /*\
2186      * Element.unhover
2187      [ method ]
2188      **
2189      * Removes event handlers for hover for the element.
2190      > Parameters
2191      - f_in (function) handler for hover in
2192      - f_out (function) handler for hover out
2193      = (object) @Element
2194     \*/
2195     elproto.unhover = function (f_in, f_out) {
2196         return this.unmouseover(f_in).unmouseout(f_out);
2197     };
2198     /*\
2199      * Element.drag
2200      [ method ]
2201      **
2202      * Adds event handlers for drag of the element.
2203      > Parameters
2204      - onmove (function) handler for moving
2205      - onstart (function) handler for drag start
2206      - onend (function) handler for drag end
2207      - mcontext (object) #optional context for moving handler
2208      - scontext (object) #optional context for drag start handler
2209      - econtext (object) #optional context for drag end handler
2210      * Additionaly following `drag` events will be triggered: `drag.start.<id>` on start, 
2211      * `drag.end.<id>` on end and `drag.move.<id>` on every move. When element will be dragged over another element 
2212      * `drag.over.<id>` will be fired as well.
2213      *
2214      * Start event and start handler will be called in specified context or in context of the element with following parameters:
2215      o x (number) x position of the mouse
2216      o y (number) y position of the mouse
2217      o event (object) DOM event object
2218      * Move event and move handler will be called in specified context or in context of the element with following parameters:
2219      o dx (number) shift by x from the start point
2220      o dy (number) shift by y from the start point
2221      o x (number) x position of the mouse
2222      o y (number) y position of the mouse
2223      o event (object) DOM event object
2224      * End event and end handler will be called in specified context or in context of the element with following parameters:
2225      o event (object) DOM event object
2226      = (object) @Element
2227     \*/
2228     elproto.drag = function (onmove, onstart, onend, move_scope, start_scope, end_scope) {
2229         function start(e) {
2230             (e.originalEvent || e).preventDefault();
2231             var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
2232                 scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft;
2233             this._drag.x = e.clientX + scrollX;
2234             this._drag.y = e.clientY + scrollY;
2235             this._drag.id = e.identifier;
2236             !drag.length && R.mousemove(dragMove).mouseup(dragUp);
2237             drag.push({el: this, move_scope: move_scope, start_scope: start_scope, end_scope: end_scope});
2238             onstart && eve.on("drag.start." + this.id, onstart);
2239             onmove && eve.on("drag.move." + this.id, onmove);
2240             onend && eve.on("drag.end." + this.id, onend);
2241             eve("drag.start." + this.id, start_scope || move_scope || this, e.clientX + scrollX, e.clientY + scrollY, e);
2242         }
2243         this._drag = {};
2244         this.mousedown(start);
2245         return this;
2246     };
2247     /*\
2248      * Element.onDragOver
2249      [ method ]
2250      **
2251      * Shortcut for assigning event handler for `drag.over.<id>` event, where id is id of the element (see @Element.id).
2252      > Parameters
2253      - f (function) handler for event
2254     \*/
2255     elproto.onDragOver = function (f) {
2256         f ? eve.on("drag.over." + this.id, f) : eve.unbind("drag.over." + this.id);
2257     };
2258     /*\
2259      * Element.undrag
2260      [ method ]
2261      **
2262      * Removes all drag event handlers from given element.
2263     \*/
2264     elproto.undrag = function () {
2265         var i = drag.length;
2266         while (i--) if (drag[i].el == this) {
2267             R.unmousedown(drag[i].start);
2268             drag.splice(i++, 1);
2269             eve.unbind("drag.*." + this.id);
2270         }
2271         !drag.length && R.unmousemove(dragMove).unmouseup(dragUp);
2272     };
2273     /*\
2274      * Paper.circle
2275      [ method ]
2276      **
2277      * Draws a circle.
2278      **
2279      > Parameters
2280      **
2281      - x (number) x coordinate of the centre
2282      - y (number) y coordinate of the centre
2283      - r (number) radius
2284      = (object) Raphaël element object with type “circle”
2285      **
2286      > Usage
2287      | var c = paper.circle(50, 50, 40);
2288     \*/
2289     paperproto.circle = function (x, y, r) {
2290         var out = R._engine.circle(this, x || 0, y || 0, r || 0);
2291         this.__set__ && this.__set__.push(out);
2292         return out;
2293     };
2294     /*\
2295      * Paper.rect
2296      [ method ]
2297      *
2298      * Draws a rectangle.
2299      **
2300      > Parameters
2301      **
2302      - x (number) x coordinate of the top left corner
2303      - y (number) y coordinate of the top left corner
2304      - width (number) width
2305      - height (number) height
2306      - r (number) #optional radius for rounded corners, default is 0
2307      = (object) Raphaël element object with type “rect”
2308      **
2309      > Usage
2310      | // regular rectangle
2311      | var c = paper.rect(10, 10, 50, 50);
2312      | // rectangle with rounded corners
2313      | var c = paper.rect(40, 40, 50, 50, 10);
2314     \*/
2315     paperproto.rect = function (x, y, w, h, r) {
2316         var out = R._engine.rect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
2317         this.__set__ && this.__set__.push(out);
2318         return out;
2319     };
2320     /*\
2321      * Paper.ellipse
2322      [ method ]
2323      **
2324      * Draws an ellipse.
2325      **
2326      > Parameters
2327      **
2328      - x (number) x coordinate of the centre
2329      - y (number) y coordinate of the centre
2330      - rx (number) horizontal radius
2331      - ry (number) vertical radius
2332      = (object) Raphaël element object with type “ellipse”
2333      **
2334      > Usage
2335      | var c = paper.ellipse(50, 50, 40, 20);
2336     \*/
2337     paperproto.ellipse = function (x, y, rx, ry) {
2338         var out = R._engine.ellipse(this, x || 0, y || 0, rx || 0, ry || 0);
2339         this.__set__ && this.__set__.push(out);
2340         return out;
2341     };
2342     /*\
2343      * Paper.path
2344      [ method ]
2345      **
2346      * Creates a path element by given path data string.
2347      **
2348      > Parameters
2349      **
2350      - pathString (string) path data in SVG path string format.
2351      = (object) Raphaël element object with type “path”
2352      # Details of a path's data attribute's format are described in the <a href="http://www.w3.org/TR/SVG/paths.html#PathData">SVG specification</a>.
2353      **
2354      > Usage
2355      | var c = paper.path("M10 10L90 90");
2356      | // draw a diagonal line:
2357      | // move to 10,10, line to 90,90
2358     \*/
2359     paperproto.path = function (pathString) {
2360         pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
2361         var out = R._engine.path(R.format[apply](R, arguments), this);
2362         this.__set__ && this.__set__.push(out);
2363         return out;
2364     };
2365     /*\
2366      * Paper.image
2367      [ method ]
2368      **
2369      * Embeds an image into the surface.
2370      **
2371      > Parameters
2372      **
2373      - src (string) URI of the source image
2374      - x (number) x coordinate position
2375      - y (number) y coordinate position
2376      - width (number) width of the image
2377      - height (number) height of the image
2378      = (object) Raphaël element object with type “image”
2379      **
2380      > Usage
2381      | var c = paper.image("apple.png", 10, 10, 80, 80);
2382     \*/
2383     paperproto.image = function (src, x, y, w, h) {
2384         var out = R._engine.image(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
2385         this.__set__ && this.__set__.push(out);
2386         return out;
2387     };
2388     /*\
2389      * Paper.text
2390      [ method ]
2391      **
2392      * Draws a text string. If you need line breaks, put “\n” in the string.
2393      **
2394      > Parameters
2395      **
2396      - x (number) x coordinate position
2397      - y (number) y coordinate position
2398      - text (string) The text string to draw
2399      = (object) Raphaël element object with type “text”
2400      **
2401      > Usage
2402      | var t = paper.text(50, 50, "Raphaël\nkicks\nbutt!");
2403     \*/
2404     paperproto.text = function (x, y, text) {
2405         var out = R._engine.text(this, x || 0, y || 0, Str(text));
2406         this.__set__ && this.__set__.push(out);
2407         return out;
2408     };
2409     /*\
2410      * Paper.set
2411      [ method ]
2412      **
2413      * Creates array-like object to keep and operate several elements at once.
2414      * Warning: it doesn’t create any elements for itself in the page, it just groups existing elements.
2415      * Sets act as pseudo elements — all methods available to an element can be used on a set.
2416      = (object) array-like object that represents set of elements
2417      **
2418      > Usage
2419      | var st = paper.set();
2420      | st.push(
2421      |     paper.circle(10, 10, 5),
2422      |     paper.circle(30, 10, 5)
2423      | );
2424      | st.attr({fill: "red"}); // changes the fill of both circles
2425     \*/
2426     paperproto.set = function (itemsArray) {
2427         !R.is(itemsArray, "array") && (itemsArray = Array.prototype.splice.call(arguments, 0, arguments.length));
2428         var out = new Set(itemsArray);
2429         this.__set__ && this.__set__.push(out);
2430         return out;
2431     };
2432     /*\
2433      * Paper.setStart
2434      [ method ]
2435      **
2436      * Creates @Paper.set. All elements that will be created after calling this method and before calling
2437      * @Paper.setFinish will be added to the set.
2438      **
2439      > Usage
2440      | paper.setStart();
2441      | paper.circle(10, 10, 5),
2442      | paper.circle(30, 10, 5)
2443      | var st = paper.setFinish();
2444      | st.attr({fill: "red"}); // changes the fill of both circles
2445     \*/
2446     paperproto.setStart = function (set) {
2447         this.__set__ = set || this.set();
2448     };
2449     /*\
2450      * Paper.setFinish
2451      [ method ]
2452      **
2453      * See @Paper.setStart. This method finishes catching and returns resulting set.
2454      **
2455      = (object) set
2456     \*/
2457     paperproto.setFinish = function (set) {
2458         var out = this.__set__;
2459         delete this.__set__;
2460         return out;
2461     };
2462     /*\
2463      * Paper.setSize
2464      [ method ]
2465      **
2466      * If you need to change dimensions of the canvas call this method
2467      **
2468      > Parameters
2469      **
2470      - width (number) new width of the canvas
2471      - height (number) new height of the canvas
2472      > Usage
2473      | var st = paper.set();
2474      | st.push(
2475      |     paper.circle(10, 10, 5),
2476      |     paper.circle(30, 10, 5)
2477      | );
2478      | st.attr({fill: "red"});
2479     \*/
2480     paperproto.setSize = R._engine.setSize;
2481     /*\
2482      * Paper.setViewBox
2483      [ method ]
2484      **
2485      * Sets the view box of the paper. Practically it gives you ability to zoom and pan whole paper surface by 
2486      * specifying new boundaries.
2487      **
2488      > Parameters
2489      **
2490      x, y, w, h, fit
2491      - x (number) new x position, default is `0`
2492      - y (number) new y position, default is `0`
2493      - w (number) new width of the canvas
2494      - h (number) new height of the canvas
2495      - fit (boolean) `true` if you want graphics to fit into new boundary box
2496     \*/
2497     paperproto.setViewBox = R._engine.setViewBox;
2498     /*\
2499      * Paper.top
2500      [ property ]
2501      **
2502      * Points to the topmost element on the paper
2503     \*/
2504     /*\
2505      * Paper.bottom
2506      [ property ]
2507      **
2508      * Points to the bottom element on the paper
2509     \*/
2510     paperproto.top = paperproto.bottom = null;
2511     /*\
2512      * Paper.raphael
2513      [ property ]
2514      **
2515      * Points to the @Raphael object/function
2516     \*/
2517     paperproto.raphael = R;
2518     var getOffset = function (elem) {
2519         var box = elem.getBoundingClientRect(),
2520             doc = elem.ownerDocument,
2521             body = doc.body,
2522             docElem = doc.documentElement,
2523             clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0,
2524             top  = box.top  + (g.win.pageYOffset || docElem.scrollTop || body.scrollTop ) - clientTop,
2525             left = box.left + (g.win.pageXOffset || docElem.scrollLeft || body.scrollLeft) - clientLeft;
2526         return {
2527             y: top,
2528             x: left
2529         };
2530     };
2531     /*\
2532      * Paper.getElementByPoint
2533      [ method ]
2534      **
2535      * Returns you topmost element under given point.
2536      **
2537      = (object) Raphaël element object
2538      > Parameters
2539      **
2540      - x (number) x coordinate from the top left corner of the window
2541      - y (number) y coordinate from the top left corner of the window
2542      > Usage
2543      | paper.getElementByPoint(mouseX, mouseY).attr({stroke: "#f00"});
2544     \*/
2545     paperproto.getElementByPoint = function (x, y) {
2546         var paper = this,
2547             svg = paper.canvas,
2548             target = g.doc.elementFromPoint(x, y);
2549         if (g.win.opera && target.tagName == "svg") {
2550             var so = getOffset(svg),
2551                 sr = svg.createSVGRect();
2552             sr.x = x - so.x;
2553             sr.y = y - so.y;
2554             sr.width = sr.height = 1;
2555             var hits = svg.getIntersectionList(sr, null);
2556             if (hits.length) {
2557                 target = hits[hits.length - 1];
2558             }
2559         }
2560         if (!target) {
2561             return null;
2562         }
2563         while (target.parentNode && target != svg.parentNode && !target.raphael) {
2564             target = target.parentNode;
2565         }
2566         target == paper.canvas.parentNode && (target = svg);
2567         target = target && target.raphael ? paper.getById(target.raphaelid) : null;
2568         return target;
2569     };
2570     /*\
2571      * Paper.getById
2572      [ method ]
2573      **
2574      * Returns you element by its internal ID.
2575      **
2576      > Parameters
2577      **
2578      - id (number) id
2579      = (object) Raphaël element object
2580     \*/
2581     paperproto.getById = function (id) {
2582         var bot = this.bottom;
2583         while (bot) {
2584             if (bot.id == id) {
2585                 return bot;
2586             }
2587             bot = bot.next;
2588         }
2589         return null;
2590     };
2591     /*\
2592      * Paper.forEach
2593      [ method ]
2594      **
2595      * Executes given function for each element on the paper
2596      *
2597      * If callback function returns `false` it will stop loop running.
2598      **
2599      > Parameters
2600      **
2601      - callback (function) function to run
2602      - thisArg (object) context object for the callback
2603      = (object) Paper object
2604     \*/
2605     paperproto.forEach = function (callback, thisArg) {
2606         var bot = this.bottom;
2607         while (bot) {
2608             if (callback.call(thisArg, bot) === false) {
2609                 return this;
2610             }
2611             bot = bot.next;
2612         }
2613         return this;
2614     };
2615     function x_y() {
2616         return this.x + S + this.y;
2617     }
2618     function x_y_w_h() {
2619         return this.x + S + this.y + S + this.width + " \xd7 " + this.height;
2620     }
2621     /*\
2622      * Element.getBBox
2623      [ method ]
2624      **
2625      * Return bounding box for a given element
2626      **
2627      > Parameters
2628      **
2629      - isWithoutTransform (boolean) flag, `true` if you want to have bounding box before transformations. Default is `false`.
2630      = (object) Bounding box object:
2631      o {
2632      o     x: (number) top left corner x
2633      o     y: (number) top left corner y
2634      o     width: (number) width
2635      o     height: (number) height
2636      o }
2637     \*/
2638     elproto.getBBox = function (isWithoutTransform) {
2639         if (this.removed) {
2640             return {};
2641         }
2642         var _ = this._;
2643         if (isWithoutTransform) {
2644             if (_.dirty || !_.bboxwt) {
2645                 this.realPath = getPath[this.type](this);
2646                 _.bboxwt = pathDimensions(this.realPath);
2647                 _.bboxwt.toString = x_y_w_h;
2648                 _.dirty = 0;
2649             }
2650             return _.bboxwt;
2651         }
2652         if (_.dirty || _.dirtyT || !_.bbox) {
2653             if (_.dirty || !this.realPath) {
2654                 _.bboxwt = 0;
2655                 this.realPath = getPath[this.type](this);
2656             }
2657             _.bbox = pathDimensions(mapPath(this.realPath, this.matrix));
2658             _.bbox.toString = x_y_w_h;
2659             _.dirty = _.dirtyT = 0;
2660         }
2661         return _.bbox;
2662     };
2663     /*\
2664      * Element.clone
2665      [ method ]
2666      **
2667      = (object) clone of a given element
2668      **
2669     \*/
2670     elproto.clone = function () {
2671         if (this.removed) {
2672             return null;
2673         }
2674         return this.paper[this.type]().attr(this.attr());
2675     };
2676     /*\
2677      * Element.glow
2678      [ method ]
2679      **
2680      * Return set of elements that create glow-like effect around given element. See @Paper.set.
2681      *
2682      * Note: Glow is not connected to the element. If you change element attributes it won’t adjust itself.
2683      **
2684      > Parameters
2685      **
2686      - glow (object) #optional parameters object with all properties optional:
2687      o {
2688      o     width (number) size of the glow, default is `10`
2689      o     fill (boolean) will it be filled, default is `false`
2690      o     opacity: opacity, default is `0.5`
2691      o     offsetx: horizontal offset, default is `0`
2692      o     offsety: vertical offset, default is `0`
2693      o     color: glow colour, default is `black`
2694      o }
2695      = (object) @Paper.set of elements that represents glow
2696     \*/
2697     elproto.glow = function (glow) {
2698         if (this.type == "text") {
2699             return null;
2700         }
2701         glow = glow || {};
2702         var s = {
2703             width: (glow.width || 10) + (+this.attr("stroke-width") || 1),
2704             fill: glow.fill || false,
2705             opacity: glow.opacity || .5,
2706             offsetx: glow.offsetx || 0,
2707             offsety: glow.offsety || 0,
2708             color: glow.color || "#000"
2709         },
2710             c = s.width / 2,
2711             r = this.paper,
2712             out = r.set(),
2713             path = this.realPath || getPath[this.type](this);
2714         path = this.matrix ? mapPath(path, this.matrix) : path;
2715         for (var i = 1; i < c + 1; i++) {
2716             out.push(r.path(path).attr({
2717                 stroke: s.color,
2718                 fill: s.fill ? s.color : "none",
2719                 "stroke-linejoin": "round",
2720                 "stroke-linecap": "round",
2721                 "stroke-width": +(s.width / c * i).toFixed(3),
2722                 opacity: +(s.opacity / c).toFixed(3)
2723             }));
2724         }
2725         return out.insertBefore(this).translate(s.offsetx, s.offsety);
2726     };
2727     var curveslengths = {},
2728     getPointAtSegmentLength = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
2729         var len = 0,
2730             precision = 100,
2731             name = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y].join(),
2732             cache = curveslengths[name],
2733             old, dot;
2734         !cache && (curveslengths[name] = cache = {data: []});
2735         cache.timer && clearTimeout(cache.timer);
2736         cache.timer = setTimeout(function () {delete curveslengths[name];}, 2e3);
2737         if (length != null && !cache.precision) {
2738             var total = getPointAtSegmentLength(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y);
2739             cache.precision = ~~total * 10;
2740             cache.data = [];
2741         }
2742         precision = cache.precision || precision;
2743         for (var i = 0; i < precision + 1; i++) {
2744             if (cache.data[i * precision]) {
2745                 dot = cache.data[i * precision];
2746             } else {
2747                 dot = R.findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i / precision);
2748                 cache.data[i * precision] = dot;
2749             }
2750             i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
2751             if (length != null && len >= length) {
2752                 return dot;
2753             }
2754             old = dot;
2755         }
2756         if (length == null) {
2757             return len;
2758         }
2759     },
2760     getLengthFactory = function (istotal, subpath) {
2761         return function (path, length, onlystart) {
2762             path = path2curve(path);
2763             var x, y, p, l, sp = "", subpaths = {}, point,
2764                 len = 0;
2765             for (var i = 0, ii = path.length; i < ii; i++) {
2766                 p = path[i];
2767                 if (p[0] == "M") {
2768                     x = +p[1];
2769                     y = +p[2];
2770                 } else {
2771                     l = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
2772                     if (len + l > length) {
2773                         if (subpath && !subpaths.start) {
2774                             point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
2775                             sp += ["C" + point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
2776                             if (onlystart) {return sp;}
2777                             subpaths.start = sp;
2778                             sp = ["M" + point.x, point.y + "C" + point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]].join();
2779                             len += l;
2780                             x = +p[5];
2781                             y = +p[6];
2782                             continue;
2783                         }
2784                         if (!istotal && !subpath) {
2785                             point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
2786                             return {x: point.x, y: point.y, alpha: point.alpha};
2787                         }
2788                     }
2789                     len += l;
2790                     x = +p[5];
2791                     y = +p[6];
2792                 }
2793                 sp += p.shift() + p;
2794             }
2795             subpaths.end = sp;
2796             point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[1], p[2], p[3], p[4], p[5], p[6], 1);
2797             point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha});
2798             return point;
2799         };
2800     };
2801     var getTotalLength = getLengthFactory(1),
2802         getPointAtLength = getLengthFactory(),
2803         getSubpathsAtLength = getLengthFactory(0, 1);
2804     /*\
2805      * Raphael.getTotalLength
2806      [ method ]
2807      **
2808      * Returns length of the given path in pixels.
2809      **
2810      > Parameters
2811      **
2812      - path (string) SVG path string.
2813      **
2814      = (number) length.
2815     \*/
2816     R.getTotalLength = getTotalLength;
2817     /*\
2818      * Raphael.getPointAtLength
2819      [ method ]
2820      **
2821      * Return coordinates of the point located at the given length on the given path.
2822      **
2823      > Parameters
2824      **
2825      - path (string) SVG path string
2826      - length (number)
2827      **
2828      = (object) representation of the point:
2829      o {
2830      o     x: (number) x coordinate
2831      o     y: (number) y coordinate
2832      o     alpha: (number) angle of derivative
2833      o }
2834     \*/
2835     R.getPointAtLength = getPointAtLength;
2836     /*\
2837      * Raphael.getSubpath
2838      [ method ]
2839      **
2840      * Return subpath of a given path from given length to given length.
2841      **
2842      > Parameters
2843      **
2844      - path (string) SVG path string
2845      - from (number) position of the start of the segment
2846      - to (number) position of the end of the segment
2847      **
2848      = (string) pathstring for the segment
2849     \*/
2850     R.getSubpath = function (path, from, to) {
2851         if (abs(this.getTotalLength(path) - to) < 1e-6) {
2852             return getSubpathsAtLength(path, from).end;
2853         }
2854         var a = getSubpathsAtLength(path, to, 1);
2855         return from ? getSubpathsAtLength(a, from).end : a;
2856     };
2857     /*\
2858      * Element.getTotalLength
2859      [ method ]
2860      **
2861      * Returns length of the path in pixels. Only works for element of “path” type.
2862      = (number) length.
2863     \*/
2864     elproto.getTotalLength = function () {
2865         if (this.type != "path") {return;}
2866         if (this.node.getTotalLength) {
2867             return this.node.getTotalLength();
2868         }
2869         return getTotalLength(this.attrs.path);
2870     };
2871     /*\
2872      * Element.getPointAtLength
2873      [ method ]
2874      **
2875      * Return coordinates of the point located at the given length on the given path. Only works for element of “path” type.
2876      **
2877      > Parameters
2878      **
2879      - length (number)
2880      **
2881      = (object) representation of the point:
2882      o {
2883      o     x: (number) x coordinate
2884      o     y: (number) y coordinate
2885      o     alpha: (number) angle of derivative
2886      o }
2887     \*/
2888     elproto.getPointAtLength = function (length) {
2889         if (this.type != "path") {return;}
2890         return getPointAtLength(this.attrs.path, length);
2891     };
2892     /*\
2893      * Element.getSubpath
2894      [ method ]
2895      **
2896      * Return subpath of a given element from given length to given length. Only works for element of “path” type.
2897      **
2898      > Parameters
2899      **
2900      - from (number) position of the start of the segment
2901      - to (number) position of the end of the segment
2902      **
2903      = (string) pathstring for the segment
2904     \*/
2905     elproto.getSubpath = function (from, to) {
2906         if (this.type != "path") {return;}
2907         return R.getSubpath(this.attrs.path, from, to);
2908     };
2909     /*\
2910      * Raphael.easing_formulas
2911      [ property ]
2912      **
2913      * Object that contains easing formulas for animation. You could extend it with your own. By default it has following list of easing:
2914      # <ul>
2915      #     <li>“linear”</li>
2916      #     <li>“&lt;” or “easeIn” or “ease-in”</li>
2917      #     <li>“>” or “easeOut” or “ease-out”</li>
2918      #     <li>“&lt;>” or “easeInOut” or “ease-in-out”</li>
2919      #     <li>“backIn” or “back-in”</li>
2920      #     <li>“backOut” or “back-out”</li>
2921      #     <li>“elastic”</li>
2922      #     <li>“bounce”</li>
2923      # </ul>
2924      # <p>See also <a href="http://raphaeljs.com/easing.html">Easing demo</a>.</p>
2925     \*/
2926     var ef = R.easing_formulas = {
2927         linear: function (n) {
2928             return n;
2929         },
2930         "<": function (n) {
2931             return pow(n, 1.7);
2932         },
2933         ">": function (n) {
2934             return pow(n, .48);
2935         },
2936         "<>": function (n) {
2937             var q = .48 - n / 1.04,
2938                 Q = math.sqrt(.1734 + q * q),
2939                 x = Q - q,
2940                 X = pow(abs(x), 1 / 3) * (x < 0 ? -1 : 1),
2941                 y = -Q - q,
2942                 Y = pow(abs(y), 1 / 3) * (y < 0 ? -1 : 1),
2943                 t = X + Y + .5;
2944             return (1 - t) * 3 * t * t + t * t * t;
2945         },
2946         backIn: function (n) {
2947             var s = 1.70158;
2948             return n * n * ((s + 1) * n - s);
2949         },
2950         backOut: function (n) {
2951             n = n - 1;
2952             var s = 1.70158;
2953             return n * n * ((s + 1) * n + s) + 1;
2954         },
2955         elastic: function (n) {
2956             if (n == !!n) {
2957                 return n;
2958             }
2959             return pow(2, -10 * n) * math.sin((n - .075) * (2 * PI) / .3) + 1;
2960         },
2961         bounce: function (n) {
2962             var s = 7.5625,
2963                 p = 2.75,
2964                 l;
2965             if (n < (1 / p)) {
2966                 l = s * n * n;
2967             } else {
2968                 if (n < (2 / p)) {
2969                     n -= (1.5 / p);
2970                     l = s * n * n + .75;
2971                 } else {
2972                     if (n < (2.5 / p)) {
2973                         n -= (2.25 / p);
2974                         l = s * n * n + .9375;
2975                     } else {
2976                         n -= (2.625 / p);
2977                         l = s * n * n + .984375;
2978                     }
2979                 }
2980             }
2981             return l;
2982         }
2983     };
2984     ef.easeIn = ef["ease-in"] = ef["<"];
2985     ef.easeOut = ef["ease-out"] = ef[">"];
2986     ef.easeInOut = ef["ease-in-out"] = ef["<>"];
2987     ef["back-in"] = ef.backIn;
2988     ef["back-out"] = ef.backOut;
2989
2990     var animationElements = [],
2991         requestAnimFrame = window.requestAnimationFrame       ||
2992                            window.webkitRequestAnimationFrame ||
2993                            window.mozRequestAnimationFrame    ||
2994                            window.oRequestAnimationFrame      ||
2995                            window.msRequestAnimationFrame     ||
2996                            function (callback) {
2997                                setTimeout(callback, 16);
2998                            },
2999         animation = function () {
3000             var Now = +new Date,
3001                 l = 0;
3002             for (; l < animationElements.length; l++) {
3003                 var e = animationElements[l];
3004                 if (e.el.removed || e.paused) {
3005                     continue;
3006                 }
3007                 var time = Now - e.start,
3008                     ms = e.ms,
3009                     easing = e.easing,
3010                     from = e.from,
3011                     diff = e.diff,
3012                     to = e.to,
3013                     t = e.t,
3014                     that = e.el,
3015                     set = {},
3016                     now;
3017                 if (e.initstatus) {
3018                     time = (e.initstatus * e.anim.top - e.prev) / (e.percent - e.prev) * ms;
3019                     e.status = e.initstatus;
3020                     delete e.initstatus;
3021                     e.stop && animationElements.splice(l--, 1);
3022                 } else {
3023                     e.status = (e.prev + (e.percent - e.prev) * (time / ms)) / e.anim.top;
3024                 }
3025                 if (time < 0) {
3026                     continue;
3027                 }
3028                 if (time < ms) {
3029                     var pos = easing(time / ms);
3030                     for (var attr in from) if (from[has](attr)) {
3031                         switch (availableAnimAttrs[attr]) {
3032                             case nu:
3033                                 now = +from[attr] + pos * ms * diff[attr];
3034                                 break;
3035                             case "colour":
3036                                 now = "rgb(" + [
3037                                     upto255(round(from[attr].r + pos * ms * diff[attr].r)),
3038                                     upto255(round(from[attr].g + pos * ms * diff[attr].g)),
3039                                     upto255(round(from[attr].b + pos * ms * diff[attr].b))
3040                                 ].join(",") + ")";
3041                                 break;
3042                             case "path":
3043                                 now = [];
3044                                 for (var i = 0, ii = from[attr].length; i < ii; i++) {
3045                                     now[i] = [from[attr][i][0]];
3046                                     for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
3047                                         now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
3048                                     }
3049                                     now[i] = now[i].join(S);
3050                                 }
3051                                 now = now.join(S);
3052                                 break;
3053                             case "transform":
3054                                 if (diff[attr].real) {
3055                                     now = [];
3056                                     for (i = 0, ii = from[attr].length; i < ii; i++) {
3057                                         now[i] = [from[attr][i][0]];
3058                                         for (j = 1, jj = from[attr][i].length; j < jj; j++) {
3059                                             now[i][j] = from[attr][i][j] + pos * ms * diff[attr][i][j];
3060                                         }
3061                                     }
3062                                 } else {
3063                                     var get = function (i) {
3064                                         return +from[attr][i] + pos * ms * diff[attr][i];
3065                                     };
3066                                     // now = [["r", get(2), 0, 0], ["t", get(3), get(4)], ["s", get(0), get(1), 0, 0]];
3067                                     now = [["m", get(0), get(1), get(2), get(3), get(4), get(5)]];
3068                                 }
3069                                 break;
3070                             case "csv":
3071                                 if (attr == "clip-rect") {
3072                                     now = [];
3073                                     i = 4;
3074                                     while (i--) {
3075                                         now[i] = +from[attr][i] + pos * ms * diff[attr][i];
3076                                     }
3077                                 }
3078                                 break;
3079                             default:
3080                                 var from2 = [].concat(from[attr]);
3081                                 now = [];
3082                                 i = that.paper.customAttributes[attr].length;
3083                                 while (i--) {
3084                                     now[i] = +from2[i] + pos * ms * diff[attr][i];
3085                                 }
3086                                 break;
3087                         }
3088                         set[attr] = now;
3089                     }
3090                     that.attr(set);
3091                     (function (id, that, anim) {
3092                         setTimeout(function () {
3093                             eve("anim.frame." + id, that, anim);
3094                         });
3095                     })(that.id, that, e.anim);
3096                 } else {
3097                     (function(f, el, a) {
3098                         setTimeout(function() {
3099                             eve("anim.frame." + el.id, el, a);
3100                             eve("anim.finish." + el.id, el, a);
3101                             R.is(f, "function") && f.call(el);
3102                         });
3103                     })(e.callback, that, e.anim);
3104                     that.attr(to);
3105                     animationElements.splice(l--, 1);
3106                     if (e.repeat > 1 && !e.next) {
3107                         runAnimation(e.anim, e.el, e.anim.percents[0], null, e.totalOrigin, e.repeat - 1);
3108                     }
3109                     if (e.next && !e.stop) {
3110                         runAnimation(e.anim, e.el, e.next, null, e.totalOrigin, e.repeat);
3111                     }
3112                 }
3113             }
3114             R.svg && that && that.paper && that.paper.safari();
3115             animationElements.length && requestAnimFrame(animation);
3116         },
3117         upto255 = function (color) {
3118             return color > 255 ? 255 : color < 0 ? 0 : color;
3119         };
3120     /*\
3121      * Element.animateWith
3122      [ method ]
3123      **
3124      * Acts similar to @Element.animate, but ensure that given animation runs in sync with another given element.
3125      **
3126      > Parameters
3127      **
3128      - params (object) final attributes for the element, see also @Element.attr
3129      - ms (number) number of milliseconds for animation to run
3130      - easing (string) #optional easing type. Accept on of @Raphael.easing_formulas or CSS format: `cubic&#x2010;bezier(XX,&#160;XX,&#160;XX,&#160;XX)`
3131      - callback (function) #optional callback function. Will be called at the end of animation.
3132      * or
3133      - animation (object) animation object, see @Raphael.animation
3134      **
3135      = (object) original element
3136     \*/
3137     elproto.animateWith = function (element, params, ms, easing, callback) {
3138         this.animate(params, ms, easing, callback);
3139         var start, el;
3140         for (var i = 0, ii = animationElements.length; i < ii; i++) {
3141             el = animationElements[i];
3142             if (el.el.id == element.id) {
3143                 start = el.timestamp;
3144             } else if (el.el.id == this.id) {
3145                 el.start = start;
3146             }
3147         }
3148         return this.animate(params, ms, easing, callback);
3149     };
3150     function CubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
3151         var cx = 3 * p1x,
3152             bx = 3 * (p2x - p1x) - cx,
3153             ax = 1 - cx - bx,
3154             cy = 3 * p1y,
3155             by = 3 * (p2y - p1y) - cy,
3156             ay = 1 - cy - by;
3157         function sampleCurveX(t) {
3158             return ((ax * t + bx) * t + cx) * t;
3159         }
3160         function solve(x, epsilon) {
3161             var t = solveCurveX(x, epsilon);
3162             return ((ay * t + by) * t + cy) * t;
3163         }
3164         function solveCurveX(x, epsilon) {
3165             var t0, t1, t2, x2, d2, i;
3166             for(t2 = x, i = 0; i < 8; i++) {
3167                 x2 = sampleCurveX(t2) - x;
3168                 if (abs(x2) < epsilon) {
3169                     return t2;
3170                 }
3171                 d2 = (3 * ax * t2 + 2 * bx) * t2 + cx;
3172                 if (abs(d2) < 1e-6) {
3173                     break;
3174                 }
3175                 t2 = t2 - x2 / d2;
3176             }
3177             t0 = 0;
3178             t1 = 1;
3179             t2 = x;
3180             if (t2 < t0) {
3181                 return t0;
3182             }
3183             if (t2 > t1) {
3184                 return t1;
3185             }
3186             while (t0 < t1) {
3187                 x2 = sampleCurveX(t2);
3188                 if (abs(x2 - x) < epsilon) {
3189                     return t2;
3190                 }
3191                 if (x > x2) {
3192                     t0 = t2;
3193                 } else {
3194                     t1 = t2;
3195                 }
3196                 t2 = (t1 - t0) / 2 + t0;
3197             }
3198             return t2;
3199         }
3200         return solve(t, 1 / (200 * duration));
3201     }
3202     elproto.onAnimation = function (f) {
3203         f ? eve.on("anim.frame." + this.id, f) : eve.unbind("anim.frame." + this.id);
3204         return this;
3205     };
3206     function Animation(anim, ms) {
3207         var percents = [];
3208         this.anim = anim;
3209         this.ms = ms;
3210         this.times = 1;
3211         if (this.anim) {
3212             for (var attr in this.anim) if (this.anim[has](attr)) {
3213                 percents.push(+attr);
3214             }
3215             percents.sort(sortByNumber);
3216         }
3217         this.top = percents[percents.length - 1];
3218         this.percents = percents;
3219     }
3220     /*\
3221      * Animation.delay
3222      [ method ]
3223      **
3224      * Creates a copy of existing animation object with given delay.
3225      **
3226      > Parameters
3227      **
3228      - delay (number) number of ms to pass between animation start and actual animation
3229      **
3230      = (object) new altered Animation object
3231     \*/
3232     Animation.prototype.delay = function (delay) {
3233         var a = new Animation(this.anim, this.ms);
3234         a.times = this.times;
3235         a.del = +delay || 0;
3236         return a;
3237     };
3238     /*\
3239      * Animation.repeat
3240      [ method ]
3241      **
3242      * Creates a copy of existing animation object with given repetition.
3243      **
3244      > Parameters
3245      **
3246      - repeat (number) number iterations of animation. For infinite animation pass `Infinity`
3247      **
3248      = (object) new altered Animation object
3249     \*/
3250     Animation.prototype.repeat = function (times) { 
3251         var a = new Animation(this.anim, this.ms);
3252         a.del = this.del;
3253         a.times = math.floor(mmax(times, 0)) || 1;
3254         return a;
3255     };
3256     function runAnimation(anim, element, percent, status, totalOrigin, times) {
3257         percent = toFloat(percent);
3258         var params,
3259             isInAnim,
3260             isInAnimSet,
3261             percents = [],
3262             next,
3263             prev,
3264             timestamp,
3265             ms = anim.ms,
3266             from = {},
3267             to = {},
3268             diff = {};
3269         if (status) {
3270             for (i = 0, ii = animationElements.length; i < ii; i++) {
3271                 var e = animationElements[i];
3272                 if (e.el.id == element.id && e.anim == anim) {
3273                     if (e.percent != percent) {
3274                         animationElements.splice(i, 1);
3275                         isInAnimSet = 1;
3276                     } else {
3277                         isInAnim = e;
3278                     }
3279                     element.attr(e.totalOrigin);
3280                     break;
3281                 }
3282             }
3283         } else {
3284             status = +to; // NaN
3285         }
3286         for (var i = 0, ii = anim.percents.length; i < ii; i++) {
3287             if (anim.percents[i] == percent || anim.percents[i] > status * anim.top) {
3288                 percent = anim.percents[i];
3289                 prev = anim.percents[i - 1] || 0;
3290                 ms = ms / anim.top * (percent - prev);
3291                 next = anim.percents[i + 1];
3292                 params = anim.anim[percent];
3293                 break;
3294             } else if (status) {
3295                 element.attr(anim.anim[anim.percents[i]]);
3296             }
3297         }
3298         if (!params) {
3299             return;
3300         }
3301         if (!isInAnim) {
3302             for (attr in params) if (params[has](attr)) {
3303                 if (availableAnimAttrs[has](attr) || element.paper.customAttributes[has](attr)) {
3304                     from[attr] = element.attr(attr);
3305                     (from[attr] == null) && (from[attr] = availableAttrs[attr]);
3306                     to[attr] = params[attr];
3307                     switch (availableAnimAttrs[attr]) {
3308                         case nu:
3309                             diff[attr] = (to[attr] - from[attr]) / ms;
3310                             break;
3311                         case "colour":
3312                             from[attr] = R.getRGB(from[attr]);
3313                             var toColour = R.getRGB(to[attr]);
3314                             diff[attr] = {
3315                                 r: (toColour.r - from[attr].r) / ms,
3316                                 g: (toColour.g - from[attr].g) / ms,
3317                                 b: (toColour.b - from[attr].b) / ms
3318                             };
3319                             break;
3320                         case "path":
3321                             var pathes = path2curve(from[attr], to[attr]),
3322                                 toPath = pathes[1];
3323                             from[attr] = pathes[0];
3324                             diff[attr] = [];
3325                             for (i = 0, ii = from[attr].length; i < ii; i++) {
3326                                 diff[attr][i] = [0];
3327                                 for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
3328                                     diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
3329                                 }
3330                             }
3331                             break;
3332                         case "transform":
3333                             var _ = element._,
3334                                 eq = equaliseTransform(_[attr], to[attr]);
3335                             if (eq) {
3336                                 from[attr] = eq.from;
3337                                 to[attr] = eq.to;
3338                                 diff[attr] = [];
3339                                 diff[attr].real = true;
3340                                 for (i = 0, ii = from[attr].length; i < ii; i++) {
3341                                     diff[attr][i] = [from[attr][i][0]];
3342                                     for (j = 1, jj = from[attr][i].length; j < jj; j++) {
3343                                         diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
3344                                     }
3345                                 }
3346                             } else {
3347                                 var m = (element.matrix || new Matrix),
3348                                     to2 = {
3349                                         _: {transform: _.transform},
3350                                         getBBox: function () {
3351                                             return element.getBBox(1);
3352                                         }
3353                                     };
3354                                 from[attr] = [
3355                                     m.a,
3356                                     m.b,
3357                                     m.c,
3358                                     m.d,
3359                                     m.e,
3360                                     m.f
3361                                 ];
3362                                 extractTransform(to2, to[attr]);
3363                                 to[attr] = to2._.transform;
3364                                 diff[attr] = [
3365                                     (to2.matrix.a - m.a) / ms,
3366                                     (to2.matrix.b - m.b) / ms,
3367                                     (to2.matrix.c - m.c) / ms,
3368                                     (to2.matrix.d - m.d) / ms,
3369                                     (to2.matrix.e - m.e) / ms,
3370                                     (to2.matrix.e - m.f) / ms
3371                                 ];
3372                                 // from[attr] = [_.sx, _.sy, _.deg, _.dx, _.dy];
3373                                 // var to2 = {_:{}, getBBox: function () { return element.getBBox(); }};
3374                                 // extractTransform(to2, to[attr]);
3375                                 // diff[attr] = [
3376                                 //     (to2._.sx - _.sx) / ms,
3377                                 //     (to2._.sy - _.sy) / ms,
3378                                 //     (to2._.deg - _.deg) / ms,
3379                                 //     (to2._.dx - _.dx) / ms,
3380                                 //     (to2._.dy - _.dy) / ms
3381                                 // ];
3382                             }
3383                             break;
3384                         case "csv":
3385                             var values = Str(params[attr]).split(separator),
3386                                 from2 = Str(from[attr]).split(separator);
3387                             if (attr == "clip-rect") {
3388                                 from[attr] = from2;
3389                                 diff[attr] = [];
3390                                 i = from2.length;
3391                                 while (i--) {
3392                                     diff[attr][i] = (values[i] - from[attr][i]) / ms;
3393                                 }
3394                             }
3395                             to[attr] = values;
3396                             break;
3397                         default:
3398                             values = [].concat(params[attr]);
3399                             from2 = [].concat(from[attr]);
3400                             diff[attr] = [];
3401                             i = element.paper.customAttributes[attr].length;
3402                             while (i--) {
3403                                 diff[attr][i] = ((values[i] || 0) - (from2[i] || 0)) / ms;
3404                             }
3405                             break;
3406                     }
3407                 }
3408             }
3409             var easing = params.easing,
3410                 easyeasy = R.easing_formulas[easing];
3411             if (!easyeasy) {
3412                 easyeasy = Str(easing).match(bezierrg);
3413                 if (easyeasy && easyeasy.length == 5) {
3414                     var curve = easyeasy;
3415                     easyeasy = function (t) {
3416                         return CubicBezierAtTime(t, +curve[1], +curve[2], +curve[3], +curve[4], ms);
3417                     };
3418                 } else {
3419                     easyeasy = pipe;
3420                 }
3421             }
3422             timestamp = params.start || anim.start || +new Date;
3423             e = {
3424                 anim: anim,
3425                 percent: percent,
3426                 timestamp: timestamp,
3427                 start: timestamp + (anim.del || 0),
3428                 status: 0,
3429                 initstatus: status || 0,
3430                 stop: false,
3431                 ms: ms,
3432                 easing: easyeasy,
3433                 from: from,
3434                 diff: diff,
3435                 to: to,
3436                 el: element,
3437                 callback: params.callback,
3438                 prev: prev,
3439                 next: next,
3440                 repeat: times || anim.times,
3441                 origin: element.attr(),
3442                 totalOrigin: totalOrigin
3443             };
3444             animationElements.push(e);
3445             if (status && !isInAnim) {
3446                 e.stop = true;
3447                 e.start = new Date - ms * status;
3448                 if (animationElements.length == 1) {
3449                     return animation();
3450                 }
3451             }
3452             animationElements.length == 1 && requestAnimFrame(animation);
3453         } else {
3454             isInAnim.initstatus = status;
3455             isInAnim.start = new Date - isInAnim.ms * status;
3456         }
3457         eve("anim.start." + element.id, element, anim);
3458     }
3459     /*\
3460      * Raphael.animation
3461      [ method ]
3462      **
3463      * Creates an animation object that can be passed to the @Element.animate or @Element.animateWith methods.
3464      * See also @Animation.delay and @Animation.repeat methods.
3465      **
3466      > Parameters
3467      **
3468      - params (object) final attributes for the element, see also @Element.attr
3469      - ms (number) number of milliseconds for animation to run
3470      - easing (string) #optional easing type. Accept one of @Raphael.easing_formulas or CSS format: `cubic&#x2010;bezier(XX,&#160;XX,&#160;XX,&#160;XX)`
3471      - callback (function) #optional callback function. Will be called at the end of animation.
3472      **
3473      = (object) @Animation
3474     \*/
3475     R.animation = function (params, ms, easing, callback) {
3476         if (R.is(easing, "function") || !easing) {
3477             callback = callback || easing || null;
3478             easing = null;
3479         }
3480         params = Object(params);
3481         ms = +ms || 0;
3482         var p = {},
3483             json,
3484             attr;
3485         for (attr in params) if (params[has](attr) && toFloat(attr) != attr) {
3486             json = true;
3487             p[attr] = params[attr];
3488         }
3489         if (!json) {
3490             return new Animation(params, ms);
3491         } else {
3492             easing && (p.easing = easing);
3493             callback && (p.callback = callback);
3494             return new Animation({100: p}, ms);
3495         }
3496     };
3497     /*\
3498      * Element.animate
3499      [ method ]
3500      **
3501      * Creates and starts animation for given element.
3502      **
3503      > Parameters
3504      **
3505      - params (object) final attributes for the element, see also @Element.attr
3506      - ms (number) number of milliseconds for animation to run
3507      - easing (string) #optional easing type. Accept one of @Raphael.easing_formulas or CSS format: `cubic&#x2010;bezier(XX,&#160;XX,&#160;XX,&#160;XX)`
3508      - callback (function) #optional callback function. Will be called at the end of animation.
3509      * or
3510      - animation (object) animation object, see @Raphael.animation
3511      **
3512      = (object) original element
3513     \*/
3514     elproto.animate = function (params, ms, easing, callback) {
3515         var element = this;
3516         if (element.removed) {
3517             callback && callback.call(element);
3518             return element;
3519         }
3520         var anim = params instanceof Animation ? params : R.animation(params, ms, easing, callback);
3521         runAnimation(anim, element, anim.percents[0], null, element.attr());
3522         return element;
3523     };
3524     /*\
3525      * Element.setTime
3526      [ method ]
3527      **
3528      * Sets the status of animation of the element in milliseconds. Similar to @Element.status method.
3529      **
3530      > Parameters
3531      **
3532      - anim (object) animation object
3533      - value (number) number of milliseconds from the beginning of the animation
3534      **
3535      = (object) original element if `value` is specified
3536      * Note, that during animation following events are triggered:
3537      *
3538      * On each animation frame event `anim.frame.<id>`, on start `anim.start.<id>` and on end `anim.finish.<id>`.
3539     \*/
3540     elproto.setTime = function (anim, value) {
3541         if (anim && value != null) {
3542             this.status(anim, mmin(value, anim.ms) / anim.ms);
3543         }
3544         return this;
3545     };
3546     /*\
3547      * Element.status
3548      [ method ]
3549      **
3550      * Gets or sets the status of animation of the element.
3551      **
3552      > Parameters
3553      **
3554      - anim (object) #optional animation object
3555      - value (number) #optional 0 – 1. If specified, method works like a setter and sets the status of a given animation to the value. This will cause animation to jump to the given position.
3556      **
3557      = (number) status
3558      * or
3559      = (array) status if `anim` is not specified. Array of objects in format:
3560      o {
3561      o     anim: (object) animation object
3562      o     status: (number) status
3563      o }
3564      * or
3565      = (object) original element if `value` is specified
3566     \*/
3567     elproto.status = function (anim, value) {
3568         var out = [],
3569             i = 0,
3570             len,
3571             e;
3572         if (value != null) {
3573             runAnimation(anim, this, -1, mmin(value, 1));
3574             return this;
3575         } else {
3576             len = animationElements.length;
3577             for (; i < len; i++) {
3578                 e = animationElements[i];
3579                 if (e.el.id == this.id && (!anim || e.anim == anim)) {
3580                     if (anim) {
3581                         return e.status;
3582                     }
3583                     out.push({anim: e.anim, status: e.status});
3584                 }
3585             }
3586             if (anim) {
3587                 return 0;
3588             }
3589             return out;
3590         }
3591     };
3592     /*\
3593      * Element.pause
3594      [ method ]
3595      **
3596      * Stops animation of the element with ability to resume it later on.
3597      **
3598      > Parameters
3599      **
3600      - anim (object) #optional animation object
3601      **
3602      = (object) original element
3603     \*/
3604     elproto.pause = function (anim) {
3605         for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
3606             if (eve("anim.pause." + this.id, this, animationElements[i].anim) !== false) {
3607                 animationElements[i].paused = true;
3608             }
3609         }
3610         return this;
3611     };
3612     /*\
3613      * Element.resume
3614      [ method ]
3615      **
3616      * Resumes animation if it was paused with @Element.pause method.
3617      **
3618      > Parameters
3619      **
3620      - anim (object) #optional animation object
3621      **
3622      = (object) original element
3623     \*/
3624     elproto.resume = function (anim) {
3625         for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
3626             var e = animationElements[i];
3627             if (eve("anim.resume." + this.id, this, e.anim) !== false) {
3628                 delete e.paused;
3629                 this.status(e.anim, e.status);
3630             }
3631         }
3632         return this;
3633     };
3634     /*\
3635      * Element.stop
3636      [ method ]
3637      **
3638      * Stops animation of the element.
3639      **
3640      > Parameters
3641      **
3642      - anim (object) #optional animation object
3643      **
3644      = (object) original element
3645     \*/
3646     elproto.stop = function (anim) {
3647         for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
3648             if (eve("anim.stop." + this.id, this, animationElements[i].anim) !== false) {
3649                 animationElements.splice(i--, 1);
3650             }
3651         }
3652         return this;
3653     };
3654     elproto.toString = function () {
3655         return "Rapha\xebl\u2019s object";
3656     };
3657
3658     // Set
3659     var Set = function (items) {
3660         this.items = [];
3661         this.length = 0;
3662         this.type = "set";
3663         if (items) {
3664             for (var i = 0, ii = items.length; i < ii; i++) {
3665                 if (items[i] && (items[i].constructor == elproto.constructor || items[i].constructor == Set)) {
3666                     this[this.items.length] = this.items[this.items.length] = items[i];
3667                     this.length++;
3668                 }
3669             }
3670         }
3671     },
3672     setproto = Set.prototype;
3673     /*\
3674      * Set.push
3675      [ method ]
3676      **
3677      * Adds each argument to the current set.
3678      = (object) original element
3679     \*/
3680     setproto.push = function () {
3681         var item,
3682             len;
3683         for (var i = 0, ii = arguments.length; i < ii; i++) {
3684             item = arguments[i];
3685             if (item && (item.constructor == elproto.constructor || item.constructor == Set)) {
3686                 len = this.items.length;
3687                 this[len] = this.items[len] = item;
3688                 this.length++;
3689             }
3690         }
3691         return this;
3692     };
3693     /*\
3694      * Set.pop
3695      [ method ]
3696      **
3697      * Removes last element and returns it.
3698      = (object) element
3699     \*/
3700     setproto.pop = function () {
3701         this.length && delete this[this.length--];
3702         return this.items.pop();
3703     };
3704     /*\
3705      * Set.forEach
3706      [ method ]
3707      **
3708      * Executes given function for each element in the set.
3709      *
3710      * If function returns `false` it will stop loop running.
3711      **
3712      > Parameters
3713      **
3714      - callback (function) function to run
3715      - thisArg (object) context object for the callback
3716      = (object) Set object
3717     \*/
3718     setproto.forEach = function (callback, thisArg) {
3719         for (var i = 0, ii = this.items.length; i < ii; i++) {
3720             if (callback.call(thisArg, this.items[i]) === false) {
3721                 return this;
3722             }
3723         }
3724         return this;
3725     };
3726     for (var method in elproto) if (elproto[has](method)) {
3727         setproto[method] = (function (methodname) {
3728             return function () {
3729                 var arg = arguments;
3730                 return this.forEach(function (el) {
3731                     el[methodname][apply](el, arg);
3732                 });
3733             };
3734         })(method);
3735     }
3736     setproto.attr = function (name, value) {
3737         if (name && R.is(name, array) && R.is(name[0], "object")) {
3738             for (var j = 0, jj = name.length; j < jj; j++) {
3739                 this.items[j].attr(name[j]);
3740             }
3741         } else {
3742             for (var i = 0, ii = this.items.length; i < ii; i++) {
3743                 this.items[i].attr(name, value);
3744             }
3745         }
3746         return this;
3747     };
3748     setproto.clear = function () {
3749         while (this.length) {
3750             this.pop();
3751         }
3752     };
3753     setproto.animate = function (params, ms, easing, callback) {
3754         (R.is(easing, "function") || !easing) && (callback = easing || null);
3755         var len = this.items.length,
3756             i = len,
3757             item,
3758             set = this,
3759             collector;
3760         if (!len) {
3761             return this;
3762         }
3763         callback && (collector = function () {
3764             !--len && callback.call(set);
3765         });
3766         easing = R.is(easing, string) ? easing : collector;
3767         var anim = params instanceof Animation ? params : R.animation(params, ms, easing, collector);
3768         item = this.items[--i].animate(anim);
3769         while (i--) {
3770             this.items[i] && !this.items[i].removed && this.items[i].animateWith(item, anim);
3771         }
3772         return this;
3773     };
3774     setproto.insertAfter = function (el) {
3775         var i = this.items.length;
3776         while (i--) {
3777             this.items[i].insertAfter(el);
3778         }
3779         return this;
3780     };
3781     setproto.getBBox = function () {
3782         var x = [],
3783             y = [],
3784             w = [],
3785             h = [];
3786         for (var i = this.items.length; i--;) if (!this.items[i].removed) {
3787             var box = this.items[i].getBBox();
3788             x.push(box.x);
3789             y.push(box.y);
3790             w.push(box.x + box.width);
3791             h.push(box.y + box.height);
3792         }
3793         x = mmin[apply](0, x);
3794         y = mmin[apply](0, y);
3795         return {
3796             x: x,
3797             y: y,
3798             width: mmax[apply](0, w) - x,
3799             height: mmax[apply](0, h) - y
3800         };
3801     };
3802     setproto.clone = function (s) {
3803         s = new Set;
3804         for (var i = 0, ii = this.items.length; i < ii; i++) {
3805             s.push(this.items[i].clone());
3806         }
3807         return s;
3808     };
3809     setproto.toString = function () {
3810         return "Rapha\xebl\u2018s set";
3811     };
3812
3813     R.registerFont = function (font) {
3814         if (!font.face) {
3815             return font;
3816         }
3817         this.fonts = this.fonts || {};
3818         var fontcopy = {
3819                 w: font.w,
3820                 face: {},
3821                 glyphs: {}
3822             },
3823             family = font.face["font-family"];
3824         for (var prop in font.face) if (font.face[has](prop)) {
3825             fontcopy.face[prop] = font.face[prop];
3826         }
3827         if (this.fonts[family]) {
3828             this.fonts[family].push(fontcopy);
3829         } else {
3830             this.fonts[family] = [fontcopy];
3831         }
3832         if (!font.svg) {
3833             fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
3834             for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
3835                 var path = font.glyphs[glyph];
3836                 fontcopy.glyphs[glyph] = {
3837                     w: path.w,
3838                     k: {},
3839                     d: path.d && "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
3840                             return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
3841                         }) + "z"
3842                 };
3843                 if (path.k) {
3844                     for (var k in path.k) if (path[has](k)) {
3845                         fontcopy.glyphs[glyph].k[k] = path.k[k];
3846                     }
3847                 }
3848             }
3849         }
3850         return font;
3851     };
3852     paperproto.getFont = function (family, weight, style, stretch) {
3853         stretch = stretch || "normal";
3854         style = style || "normal";
3855         weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
3856         if (!R.fonts) {
3857             return;
3858         }
3859         var font = R.fonts[family];
3860         if (!font) {
3861             var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
3862             for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
3863                 if (name.test(fontName)) {
3864                     font = R.fonts[fontName];
3865                     break;
3866                 }
3867             }
3868         }
3869         var thefont;
3870         if (font) {
3871             for (var i = 0, ii = font.length; i < ii; i++) {
3872                 thefont = font[i];
3873                 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
3874                     break;
3875                 }
3876             }
3877         }
3878         return thefont;
3879     };
3880     paperproto.print = function (x, y, string, font, size, origin, letter_spacing) {
3881         origin = origin || "middle"; // baseline|middle
3882         letter_spacing = mmax(mmin(letter_spacing || 0, 1), -1);
3883         var out = this.set(),
3884             letters = Str(string).split(E),
3885             shift = 0,
3886             path = E,
3887             scale;
3888         R.is(font, string) && (font = this.getFont(font));
3889         if (font) {
3890             scale = (size || 16) / font.face["units-per-em"];
3891             var bb = font.face.bbox.split(separator),
3892                 top = +bb[0],
3893                 height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
3894             for (var i = 0, ii = letters.length; i < ii; i++) {
3895                 var prev = i && font.glyphs[letters[i - 1]] || {},
3896                     curr = font.glyphs[letters[i]];
3897                 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) + (font.w * letter_spacing) : 0;
3898                 curr && curr.d && out.push(this.path(curr.d).attr({
3899                     fill: "#000",
3900                     stroke: "none",
3901                     transform: [["t", shift * scale, 0]]
3902                 }));
3903             }
3904             out.transform(["...s", scale, scale, top, height, "t", (x - top) / scale, (y - height) / scale]);
3905             // out.scale(scale, scale, top, height).translate(x - top, y - height);
3906         }
3907         return out;
3908     };
3909
3910     R.format = function (token, params) {
3911         var args = R.is(params, array) ? [0][concat](params) : arguments;
3912         token && R.is(token, string) && args.length - 1 && (token = token.replace(formatrg, function (str, i) {
3913             return args[++i] == null ? E : args[i];
3914         }));
3915         return token || E;
3916     };
3917     R.ninja = function () {
3918         oldRaphael.was ? (g.win.Raphael = oldRaphael.is) : delete Raphael;
3919         return R;
3920     };
3921     /*\
3922      * Raphael.st
3923      [ property (object) ]
3924      **
3925      * You can add your own method to elements. This is usefull when you want to hack default functionality or
3926      * want to wrap some common transformation or attributes in one method. In difference to canvas methods,
3927      * you can redefine element method at any time. Expending element methods wouldn’t affect set.
3928      > Usage
3929      | Raphael.el.red = function () {
3930      |     this.attr({fill: "#f00"});
3931      | };
3932      | // then use it
3933      | paper.circle(100, 100, 20).red();
3934     \*/
3935     R.st = setproto;
3936     // Firefox <3.6 fix: http://webreflection.blogspot.com/2009/11/195-chars-to-help-lazy-loading.html
3937     (function (doc, loaded, f) {
3938         if (doc.readyState == null && doc.addEventListener){
3939             doc.addEventListener(loaded, f = function () {
3940                 doc.removeEventListener(loaded, f, false);
3941                 doc.readyState = "complete";
3942             }, false);
3943             doc.readyState = "loading";
3944         }
3945         function isLoaded() {
3946             (/in/).test(doc.readyState) ? setTimeout(isLoaded, 9) : R.eve("DOMload");
3947         }
3948         isLoaded();
3949     })(document, "DOMContentLoaded");
3950
3951     oldRaphael.was ? (g.win.Raphael = R) : (Raphael = R);
3952
3953     /*
3954      * Eve 0.2.3 - JavaScript Events Library
3955      *
3956      * Copyright (c) 2010 Dmitry Baranovskiy (http://dmitry.baranovskiy.com/)
3957      * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
3958      */
3959
3960     var eve = R.eve = (function () {
3961         var version = "0.2.3",
3962             has = "hasOwnProperty",
3963             separator = /[\.\/]/,
3964             wildcard = "*",
3965             fun = function () {},
3966             numsort = function (a, b) {
3967                 return a - b;
3968             },
3969             current_event,
3970             events = {n: {}},
3971         /*\
3972          * eve
3973          [ method ]
3974          **
3975          * Fires event with given `name`, given scope and other parameters.
3976          **
3977          > Arguments
3978          **
3979          - name (string) name of the event, dot (`.`) or slash (`/`) separated
3980          - scope (object) context for the event handlers
3981          - varargs (...) the rest of arguments will be sent to event handlers
3982          **
3983          = (array) array of errors, if any. Each element of the array is in format:
3984          o {
3985          o     error (string) error message
3986          o     func (function) handler that caused error
3987          o }
3988         \*/
3989             eve = function (name, scope) {
3990                 var e = events,
3991                     args = Array.prototype.slice.call(arguments, 2),
3992                     listeners = eve.listeners(name),
3993                     z = 0,
3994                     f = false,
3995                     l,
3996                     indexed = [],
3997                     queue = {},
3998                     errors = [];
3999                 current_event = name;
4000                 for (var i = 0, ii = listeners.length; i < ii; i++) if ("zIndex" in listeners[i]) {
4001                     indexed.push(listeners[i].zIndex);
4002                     if (listeners[i].zIndex < 0) {
4003                         queue[listeners[i].zIndex] = listeners[i];
4004                     }
4005                 }
4006                 indexed.sort(numsort);
4007                 while (indexed[z] < 0) {
4008                     l = queue[indexed[z++]];
4009                     if (l.apply(scope, args) === f) {
4010                         return f;
4011                     }
4012                 }
4013                 for (i = 0; i < ii; i++) {
4014                     l = listeners[i];
4015                     if ("zIndex" in l) {
4016                         if (l.zIndex == indexed[z]) {
4017                             if (l.apply(scope, args) === f) {
4018                                 return f;
4019                             }
4020                             do {
4021                                 z++;
4022                                 l = queue[indexed[z]];
4023                                 if (l) {
4024                                     if (l.apply(scope, args) === f) {
4025                                         return f;
4026                                     }
4027                                 }
4028                             } while (l)
4029                         } else {
4030                             queue[l.zIndex] = l;
4031                         }
4032                     } else {
4033                         if (l.apply(scope, args) === f) {
4034                             return f;
4035                         }
4036                     }
4037                 }
4038             };
4039         /*\
4040          * eve.listeners
4041          [ method ]
4042          **
4043          * Internal method which gives you array of all event handlers that will be triggered by the given `name`.
4044          **
4045          > Arguments
4046          **
4047          - name (string) name of the event, dot (`.`) or slash (`/`) separated
4048          **
4049          = (array) array of event handlers
4050         \*/
4051         eve.listeners = function (name) {
4052             var names = name.split(separator),
4053                 e = events,
4054                 item,
4055                 items,
4056                 k,
4057                 i,
4058                 ii,
4059                 j,
4060                 jj,
4061                 nes,
4062                 es = [e],
4063                 out = [];
4064             for (i = 0, ii = names.length; i < ii; i++) {
4065                 nes = [];
4066                 for (j = 0, jj = es.length; j < jj; j++) {
4067                     e = es[j].n;
4068                     items = [e[names[i]], e[wildcard]];
4069                     k = 2;
4070                     while (k--) {
4071                         item = items[k];
4072                         if (item) {
4073                             nes.push(item);
4074                             out = out.concat(item.f || []);
4075                         }
4076                     }
4077                 }
4078                 es = nes;
4079             }
4080             return out;
4081         };
4082     
4083         /*\
4084          * eve.on
4085          [ method ]
4086          **
4087          * Binds given event handler with a given name. You can use wildcards “`*`” for the names:
4088          | eve.on("*.under.*", f);
4089          | eve("mouse.under.floor"); // triggers f
4090          * Use @eve to trigger the listener.
4091          **
4092          > Arguments
4093          **
4094          - name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards
4095          - f (function) event handler function
4096          **
4097          = (function) returned function accept one number parameter that represents z-index of the handler. It is optional feature and only used when you need to ensure that some subset of handlers will be invoked in a given order, despite of the order of assignment. 
4098          > Example:
4099          | eve.on("mouse", eat)(2);
4100          | eve.on("mouse", scream);
4101          | eve.on("mouse", catch)(1);
4102          * This will ensure that `catch` function will be called before `eat`.
4103          * If you want to put you hadler before not indexed handlers specify negative value.
4104          * Note: I assume most of the time you don’t need to worry about z-index, but it’s nice to have this feature “just in case”.
4105         \*/
4106         eve.on = function (name, f) {
4107             var names = name.split(separator),
4108                 e = events;
4109             for (var i = 0, ii = names.length; i < ii; i++) {
4110                 e = e.n;
4111                 !e[names[i]] && (e[names[i]] = {n: {}});
4112                 e = e[names[i]];
4113             }
4114             e.f = e.f || [];
4115             for (i = 0, ii = e.f.length; i < ii; i++) if (e.f[i] == f) {
4116                 return fun;
4117             }
4118             e.f.push(f);
4119             return function (zIndex) {
4120                 if (+zIndex == +zIndex) {
4121                     f.zIndex = +zIndex;
4122                 }
4123             };
4124         };
4125         /*\
4126          * eve.nt
4127          [ method ]
4128          **
4129          * Could be used inside event handler to figure out actual name of the event.
4130          **
4131          > Arguments
4132          **
4133          - subname (string) #optional subname of the event
4134          **
4135          = (string) name of the event, if `subname` is not specified
4136          * or
4137          = (boolean) `true`, if current event’s name contains `subname`
4138         \*/
4139         eve.nt = function (subname) {
4140             if (subname) {
4141                 return new RegExp("(?:\\.|\\/|^)" + subname + "(?:\\.|\\/|$)").test(current_event);
4142             }
4143             return current_event;
4144         };
4145         /*\
4146          * eve.unbind
4147          [ method ]
4148          **
4149          * Removes given function from the list of event listeners assigned to given name.
4150          **
4151          > Arguments
4152          **
4153          - name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards
4154          - f (function) event handler function
4155         \*/
4156         eve.unbind = function (name, f) {
4157             var names = name.split(separator),
4158                 e,
4159                 key,
4160                 splice,
4161                 cur = [events];
4162             for (var i = 0, ii = names.length; i < ii; i++) {
4163                 for (var j = 0; j < cur.length; j += splice.length - 2) {
4164                     splice = [j, 1];
4165                     e = cur[j].n;
4166                     if (names[i] != wildcard) {
4167                         if (e[names[i]]) {
4168                             splice.push(e[names[i]]);
4169                         }
4170                     } else {
4171                         for (key in e) if (e[has](key)) {
4172                             splice.push(e[key]);
4173                         }
4174                     }
4175                     cur.splice.apply(cur, splice);
4176                 }
4177             }
4178             for (i = 0, ii = cur.length; i < ii; i++) {
4179                 e = cur[i];
4180                 while (e.n) {
4181                     if (f) {
4182                         if (e.f) {
4183                             for (i = 0, ii = e.f.length; i < ii; i++) if (e.f[i] == f) {
4184                                 e.f.splice(i, 1);
4185                                 break;
4186                             }
4187                             !e.f.length && delete e.f;
4188                         }
4189                         for (key in e.n) if (e.n[has](key) && e.n[key].f) {
4190                             var funcs = e.n[key].f;
4191                             for (i = 0, ii = funcs.length; i < ii; i++) if (funcs[i] == f) {
4192                                 funcs.splice(i, 1);
4193                                 break;
4194                             }
4195                             !funcs.length && delete e.n[key].f;
4196                         }
4197                     } else {
4198                         delete e.f;
4199                         for (key in e.n) if (e.n[has](key) && e.n[key].f) {
4200                             delete e.n[key].f;
4201                         }
4202                     }
4203                     e = e.n;
4204                 }
4205             }
4206         };
4207         /*\
4208          * eve.version
4209          [ property (string) ]
4210          **
4211          * Current version of the library.
4212         \*/
4213         eve.version = version;
4214         eve.toString = function () {
4215             return "You are running Eve " + version;
4216         };
4217         return eve;
4218     })();
4219     
4220     // Eve finished
4221     
4222     eve.on("DOMload", function () {
4223         loaded = true;
4224     });
4225 })();
4226
4227 // ┌─────────────────────────────────────────────────────────────────────┐ \\
4228 // │ Raphaël 2 - JavaScript Vector Library                               │ \\
4229 // ├─────────────────────────────────────────────────────────────────────┤ \\
4230 // │ SVG Module                                                          │ \\
4231 // ├─────────────────────────────────────────────────────────────────────┤ \\
4232 // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com)   │ \\
4233 // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com)             │ \\
4234 // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
4235 // └─────────────────────────────────────────────────────────────────────┘ \\
4236 window.Raphael.svg && function (R) {
4237     var has = "hasOwnProperty",
4238         Str = String,
4239         toFloat = parseFloat,
4240         toInt = parseInt,
4241         math = Math,
4242         mmax = math.max,
4243         abs = math.abs,
4244         pow = math.pow,
4245         separator = /[, ]+/,
4246         eve = R.eve,
4247         E = "";
4248     // SVG
4249     var xlink = "http://www.w3.org/1999/xlink",
4250         markers = {
4251             block: "M5,0 0,2.5 5,5z",
4252             classic: "M5,0 0,2.5 5,5 3.5,3 3.5,2z",
4253             diamond: "M2.5,0 5,2.5 2.5,5 0,2.5z",
4254             open: "M6,1 1,3.5 6,6",
4255             oval: "M2.5,0A2.5,2.5,0,0,1,2.5,5 2.5,2.5,0,0,1,2.5,0z"
4256         },
4257         markerCounter = {};
4258     R.toString = function () {
4259         return  "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
4260     };
4261     var $ = function (el, attr) {
4262         if (attr) {
4263             if (typeof el == "string") {
4264                 el = $(el);
4265             }
4266             for (var key in attr) if (attr[has](key)) {
4267                 if (key.substring(0, 6) == "xlink:") {
4268                     el.setAttributeNS(xlink, key.substring(6), Str(attr[key]));
4269                 } else {
4270                     el.setAttribute(key, Str(attr[key]));
4271                 }
4272             }
4273         } else {
4274             el = R._g.doc.createElementNS("http://www.w3.org/2000/svg", el);
4275             el.style && (el.style.webkitTapHighlightColor = "rgba(0,0,0,0)");
4276         }
4277         return el;
4278     },
4279     gradients = {},
4280     rgGrad = /^url\(#(.*)\)$/,
4281     removeGradientFill = function (node, paper) {
4282         var oid = node.getAttribute("fill");
4283         oid = oid && oid.match(rgGrad);
4284         if (oid && !--gradients[oid[1]]) {
4285             delete gradients[oid[1]];
4286             paper.defs.removeChild(R._g.doc.getElementById(oid[1]));
4287         }
4288     },
4289     addGradientFill = function (element, gradient) {
4290         var type = "linear",
4291             id = element.id + gradient,
4292             fx = .5, fy = .5,
4293             o = element.node,
4294             SVG = element.paper,
4295             s = o.style,
4296             el = R._g.doc.getElementById(id);
4297         if (!el) {
4298             gradient = Str(gradient).replace(R._radial_gradient, function (all, _fx, _fy) {
4299                 type = "radial";
4300                 if (_fx && _fy) {
4301                     fx = toFloat(_fx);
4302                     fy = toFloat(_fy);
4303                     var dir = ((fy > .5) * 2 - 1);
4304                     pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
4305                         (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
4306                         fy != .5 &&
4307                         (fy = fy.toFixed(5) - 1e-5 * dir);
4308                 }
4309                 return E;
4310             });
4311             gradient = gradient.split(/\s*\-\s*/);
4312             if (type == "linear") {
4313                 var angle = gradient.shift();
4314                 angle = -toFloat(angle);
4315                 if (isNaN(angle)) {
4316                     return null;
4317                 }
4318                 var vector = [0, 0, math.cos(R.rad(angle)), math.sin(R.rad(angle))],
4319                     max = 1 / (mmax(abs(vector[2]), abs(vector[3])) || 1);
4320                 vector[2] *= max;
4321                 vector[3] *= max;
4322                 if (vector[2] < 0) {
4323                     vector[0] = -vector[2];
4324                     vector[2] = 0;
4325                 }
4326                 if (vector[3] < 0) {
4327                     vector[1] = -vector[3];
4328                     vector[3] = 0;
4329                 }
4330             }
4331             var dots = R._parseDots(gradient);
4332             if (!dots) {
4333                 return null;
4334             }
4335             if (element.gradient) {
4336                 SVG.defs.removeChild(element.gradient);
4337                 delete element.gradient;
4338             }
4339
4340             id = id.replace(/[\(\)\s,\xb0#]/g, "-");
4341             el = $(type + "Gradient", {id: id});
4342             element.gradient = el;
4343             $(el, type == "radial" ? {
4344                 fx: fx,
4345                 fy: fy
4346             } : {
4347                 x1: vector[0],
4348                 y1: vector[1],
4349                 x2: vector[2],
4350                 y2: vector[3],
4351                 gradientTransform: element.matrix.invert()
4352             });
4353             SVG.defs.appendChild(el);
4354             for (var i = 0, ii = dots.length; i < ii; i++) {
4355                 el.appendChild($("stop", {
4356                     offset: dots[i].offset ? dots[i].offset : i ? "100%" : "0%",
4357                     "stop-color": dots[i].color || "#fff"
4358                 }));
4359             }
4360         }
4361         $(o, {
4362             fill: "url(#" + id + ")",
4363             opacity: 1,
4364             "fill-opacity": 1
4365         });
4366         s.fill = E;
4367         s.opacity = 1;
4368         s.fillOpacity = 1;
4369         return 1;
4370     },
4371     updatePosition = function (o) {
4372         var bbox = o.getBBox(1);
4373         $(o.pattern, {patternTransform: o.matrix.invert() + " translate(" + bbox.x + "," + bbox.y + ")"});
4374     },
4375     addArrow = function (o, value, isEnd) {
4376         if (o.type == "path") {
4377             var values = Str(value).toLowerCase().split("-"),
4378                 p = o.paper,
4379                 se = isEnd ? "end" : "start",
4380                 node = o.node,
4381                 attrs = o.attrs,
4382                 stroke = attrs["stroke-width"],
4383                 i = values.length,
4384                 type = "classic",
4385                 from,
4386                 to,
4387                 dx,
4388                 refX,
4389                 attr,
4390                 w = 3,
4391                 h = 3,
4392                 t = 5;
4393             while (i--) {
4394                 switch (values[i]) {
4395                     case "block":
4396                     case "classic":
4397                     case "oval":
4398                     case "diamond":
4399                     case "open":
4400                     case "none":
4401                         type = values[i];
4402                         break;
4403                     case "wide": h = 5; break;
4404                     case "narrow": h = 2; break;
4405                     case "long": w = 5; break;
4406                     case "short": w = 2; break;
4407                 }
4408             }
4409             if (type == "open") {
4410                 w += 2;
4411                 h += 2;
4412                 t += 2;
4413                 dx = 1;
4414                 refX = isEnd ? 4 : 1;
4415                 attr = {
4416                     fill: "none",
4417                     stroke: attrs.stroke
4418                 };
4419             } else {
4420                 refX = dx = w / 2;
4421                 attr = {
4422                     fill: attrs.stroke,
4423                     stroke: "none"
4424                 };
4425             }
4426             if (o._.arrows) {
4427                 if (isEnd) {
4428                     o._.arrows.endPath && markerCounter[o._.arrows.endPath]--;
4429                     o._.arrows.endMarker && markerCounter[o._.arrows.endMarker]--;
4430                 } else {
4431                     o._.arrows.startPath && markerCounter[o._.arrows.startPath]--;
4432                     o._.arrows.startMarker && markerCounter[o._.arrows.startMarker]--;
4433                 }
4434             } else {
4435                 o._.arrows = {};
4436             }
4437             if (type != "none") {
4438                 var pathId = "raphael-marker-" + type,
4439                     markerId = "raphael-marker-" + se + type + w + h;
4440                 if (!R._g.doc.getElementById(pathId)) {
4441                     p.defs.appendChild($($("path"), {
4442                         "stroke-linecap": "round",
4443                         d: markers[type],
4444                         id: pathId
4445                     }));
4446                     markerCounter[pathId] = 1;
4447                 } else {
4448                     markerCounter[pathId]++;
4449                 }
4450                 var marker = R._g.doc.getElementById(markerId),
4451                     use;
4452                 if (!marker) {
4453                     marker = $($("marker"), {
4454                         id: markerId,
4455                         markerHeight: h,
4456                         markerWidth: w,
4457                         orient: "auto",
4458                         refX: refX,
4459                         refY: h / 2
4460                     });
4461                     use = $($("use"), {
4462                         "xlink:href": "#" + pathId,
4463                         transform: (isEnd ? " rotate(180 " + w / 2 + " " + h / 2 + ") " : S) + "scale(" + w / t + "," + h / t + ")",
4464                         "stroke-width": 1 / ((w / t + h / t) / 2)
4465                     });
4466                     marker.appendChild(use);
4467                     p.defs.appendChild(marker);
4468                     markerCounter[markerId] = 1;
4469                 } else {
4470                     markerCounter[markerId]++;
4471                     use = marker.getElementsByTagName("use")[0];
4472                 }
4473                 $(use, attr);
4474                 var delta = dx * (type != "diamond" && type != "oval");
4475                 if (isEnd) {
4476                     from = o._.arrows.startdx * stroke || 0;
4477                     to = R.getTotalLength(attrs.path) - delta * stroke;
4478                 } else {
4479                     from = delta * stroke;
4480                     to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
4481                 }
4482                 attr = {};
4483                 attr["marker-" + se] = "url(#" + markerId + ")";
4484                 if (to || from) {
4485                     attr.d = Raphael.getSubpath(attrs.path, from, to);
4486                 }
4487                 $(node, attr);
4488                 o._.arrows[se + "Path"] = pathId;
4489                 o._.arrows[se + "Marker"] = markerId;
4490                 o._.arrows[se + "dx"] = delta;
4491                 o._.arrows[se + "Type"] = type;
4492                 o._.arrows[se + "String"] = value;
4493             } else {
4494                 if (isEnd) {
4495                     from = o._.arrows.startdx * stroke || 0;
4496                     to = R.getTotalLength(attrs.path) - from;
4497                 } else {
4498                     from = 0;
4499                     to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
4500                 }
4501                 o._.arrows[se + "Path"] && $(node, {d: Raphael.getSubpath(attrs.path, from, to)});
4502                 delete o._.arrows[se + "Path"];
4503                 delete o._.arrows[se + "Marker"];
4504                 delete o._.arrows[se + "dx"];
4505                 delete o._.arrows[se + "Type"];
4506                 delete o._.arrows[se + "String"];
4507             }
4508             for (attr in markerCounter) if (markerCounter[has](attr) && !markerCounter[attr]) {
4509                 var item = R._g.doc.getElementById(attr);
4510                 item && item.parentNode.removeChild(item);
4511             }
4512         }
4513     },
4514     setFillAndStroke = function (o, params) {
4515         var dasharray = {
4516                 "": [0],
4517                 "none": [0],
4518                 "-": [3, 1],
4519                 ".": [1, 1],
4520                 "-.": [3, 1, 1, 1],
4521                 "-..": [3, 1, 1, 1, 1, 1],
4522                 ". ": [1, 3],
4523                 "- ": [4, 3],
4524                 "--": [8, 3],
4525                 "- .": [4, 3, 1, 3],
4526                 "--.": [8, 3, 1, 3],
4527                 "--..": [8, 3, 1, 3, 1, 3]
4528             },
4529             node = o.node,
4530             attrs = o.attrs,
4531             addDashes = function (o, value) {
4532                 value = dasharray[Str(value).toLowerCase()];
4533                 if (value) {
4534                     var width = o.attrs["stroke-width"] || "1",
4535                         butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
4536                         dashes = [],
4537                         i = value.length;
4538                     while (i--) {
4539                         dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
4540                     }
4541                     $(node, {"stroke-dasharray": dashes.join(",")});
4542                 }
4543             };
4544         for (var att in params) {
4545             if (params[has](att)) {
4546                 if (!R._availableAttrs[has](att)) {
4547                     continue;
4548                 }
4549                 var value = params[att];
4550                 attrs[att] = value;
4551                 switch (att) {
4552                     case "blur":
4553                         o.blur(value);
4554                         break;
4555                     case "href":
4556                     case "title":
4557                     case "target":
4558                         var pn = node.parentNode;
4559                         if (pn.tagName.toLowerCase() != "a") {
4560                             var hl = $("a");
4561                             pn.insertBefore(hl, node);
4562                             hl.appendChild(node);
4563                             pn = hl;
4564                         }
4565                         if (att == "target" && value == "blank") {
4566                             pn.setAttributeNS(xlink, "show", "new");
4567                         } else {
4568                             pn.setAttributeNS(xlink, att, value);
4569                         }
4570                         break;
4571                     case "cursor":
4572                         node.style.cursor = value;
4573                         break;
4574                     case "transform":
4575                         o.transform(value);
4576                         break;
4577                     case "arrow-start":
4578                         addArrow(o, value);
4579                         break;
4580                     case "arrow-end":
4581                         addArrow(o, value, 1);
4582                         break;
4583                     case "clip-rect":
4584                         var rect = Str(value).split(separator);
4585                         if (rect.length == 4) {
4586                             o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
4587                             var el = $("clipPath"),
4588                                 rc = $("rect");
4589                             el.id = R._createUUID();
4590                             $(rc, {
4591                                 x: rect[0],
4592                                 y: rect[1],
4593                                 width: rect[2],
4594                                 height: rect[3]
4595                             });
4596                             el.appendChild(rc);
4597                             o.paper.defs.appendChild(el);
4598                             $(node, {"clip-path": "url(#" + el.id + ")"});
4599                             o.clip = rc;
4600                         }
4601                         if (!value) {
4602                             var clip = R._g.doc.getElementById(node.getAttribute("clip-path").replace(/(^url\(#|\)$)/g, E));
4603                             clip && clip.parentNode.removeChild(clip);
4604                             $(node, {"clip-path": E});
4605                             delete o.clip;
4606                         }
4607                     break;
4608                     case "path":
4609                         if (o.type == "path") {
4610                             $(node, {d: value ? attrs.path = R._pathToAbsolute(value) : "M0,0"});
4611                             o._.dirty = 1;
4612                             if (o._.arrows) {
4613                                 "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
4614                                 "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
4615                             }
4616                         }
4617                         break;
4618                     case "width":
4619                         node.setAttribute(att, value);
4620                         o._.dirty = 1;
4621                         if (attrs.fx) {
4622                             att = "x";
4623                             value = attrs.x;
4624                         } else {
4625                             break;
4626                         }
4627                     case "x":
4628                         if (attrs.fx) {
4629                             value = -attrs.x - (attrs.width || 0);
4630                         }
4631                     case "rx":
4632                         if (att == "rx" && o.type == "rect") {
4633                             break;
4634                         }
4635                     case "cx":
4636                         node.setAttribute(att, value);
4637                         o.pattern && updatePosition(o);
4638                         o._.dirty = 1;
4639                         break;
4640                     case "height":
4641                         node.setAttribute(att, value);
4642                         o._.dirty = 1;
4643                         if (attrs.fy) {
4644                             att = "y";
4645                             value = attrs.y;
4646                         } else {
4647                             break;
4648                         }
4649                     case "y":
4650                         if (attrs.fy) {
4651                             value = -attrs.y - (attrs.height || 0);
4652                         }
4653                     case "ry":
4654                         if (att == "ry" && o.type == "rect") {
4655                             break;
4656                         }
4657                     case "cy":
4658                         node.setAttribute(att, value);
4659                         o.pattern && updatePosition(o);
4660                         o._.dirty = 1;
4661                         break;
4662                     case "r":
4663                         if (o.type == "rect") {
4664                             $(node, {rx: value, ry: value});
4665                         } else {
4666                             node.setAttribute(att, value);
4667                         }
4668                         o._.dirty = 1;
4669                         break;
4670                     case "src":
4671                         if (o.type == "image") {
4672                             node.setAttributeNS(xlink, "href", value);
4673                         }
4674                         break;
4675                     case "stroke-width":
4676                         if (o._.sx != 1 || o._.sy != 1) {
4677                             value /= mmax(abs(o._.sx), abs(o._.sy)) || 1;
4678                         }
4679                         if (o.paper._vbSize) {
4680                             value *= o.paper._vbSize;
4681                         }
4682                         node.setAttribute(att, value);
4683                         if (attrs["stroke-dasharray"]) {
4684                             addDashes(o, attrs["stroke-dasharray"]);
4685                         }
4686                         if (o._.arrows) {
4687                             "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
4688                             "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
4689                         }
4690                         break;
4691                     case "stroke-dasharray":
4692                         addDashes(o, value);
4693                         break;
4694                     case "fill":
4695                         var isURL = Str(value).match(R._ISURL);
4696                         if (isURL) {
4697                             el = $("pattern");
4698                             var ig = $("image");
4699                             el.id = R._createUUID();
4700                             $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
4701                             $(ig, {x: 0, y: 0, "xlink:href": isURL[1]});
4702                             el.appendChild(ig);
4703
4704                             (function (el) {
4705                                 R._preload(isURL[1], function () {
4706                                     var w = this.offsetWidth,
4707                                         h = this.offsetHeight;
4708                                     $(el, {width: w, height: h});
4709                                     $(ig, {width: w, height: h});
4710                                     o.paper.safari();
4711                                 });
4712                             })(el);
4713                             o.paper.defs.appendChild(el);
4714                             node.style.fill = "url(#" + el.id + ")";
4715                             $(node, {fill: "url(#" + el.id + ")"});
4716                             o.pattern = el;
4717                             o.pattern && updatePosition(o);
4718                             break;
4719                         }
4720                         var clr = R.getRGB(value);
4721                         if (!clr.error) {
4722                             delete params.gradient;
4723                             delete attrs.gradient;
4724                             !R.is(attrs.opacity, "undefined") &&
4725                                 R.is(params.opacity, "undefined") &&
4726                                 $(node, {opacity: attrs.opacity});
4727                             !R.is(attrs["fill-opacity"], "undefined") &&
4728                                 R.is(params["fill-opacity"], "undefined") &&
4729                                 $(node, {"fill-opacity": attrs["fill-opacity"]});
4730                         } else if ((o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value)) {
4731                             if ("opacity" in attrs || "fill-opacity" in attrs) {
4732                                 var gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
4733                                 if (gradient) {
4734                                     var stops = gradient.getElementsByTagName("stop");
4735                                     $(stops[stops.length - 1], {"stop-opacity": ("opacity" in attrs ? attrs.opacity : 1) * ("fill-opacity" in attrs ? attrs["fill-opacity"] : 1)});
4736                                 }
4737                             }
4738                             attrs.gradient = value;
4739                             attrs.fill = "none";
4740                             break;
4741                         }
4742                         clr[has]("opacity") && $(node, {"fill-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
4743                     case "stroke":
4744                         clr = R.getRGB(value);
4745                         node.setAttribute(att, clr.hex);
4746                         att == "stroke" && clr[has]("opacity") && $(node, {"stroke-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
4747                         if (att == "stroke" && o._.arrows) {
4748                             "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
4749                             "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
4750                         }
4751                         break;
4752                     case "gradient":
4753                         (o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value);
4754                         break;
4755                     case "opacity":
4756                         if (attrs.gradient && !attrs[has]("stroke-opacity")) {
4757                             $(node, {"stroke-opacity": value > 1 ? value / 100 : value});
4758                         }
4759                         // fall
4760                     case "fill-opacity":
4761                         if (attrs.gradient) {
4762                             gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
4763                             if (gradient) {
4764                                 stops = gradient.getElementsByTagName("stop");
4765                                 $(stops[stops.length - 1], {"stop-opacity": value});
4766                             }
4767                             break;
4768                         }
4769                     default:
4770                         att == "font-size" && (value = toInt(value, 10) + "px");
4771                         var cssrule = att.replace(/(\-.)/g, function (w) {
4772                             return w.substring(1).toUpperCase();
4773                         });
4774                         node.style[cssrule] = value;
4775                         o._.dirty = 1;
4776                         node.setAttribute(att, value);
4777                         break;
4778                 }
4779             }
4780         }
4781
4782         tuneText(o, params);
4783     },
4784     leading = 1.2,
4785     tuneText = function (el, params) {
4786         if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
4787             return;
4788         }
4789         var a = el.attrs,
4790             node = el.node,
4791             fontSize = node.firstChild ? toInt(R._g.doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
4792
4793         if (params[has]("text")) {
4794             a.text = params.text;
4795             while (node.firstChild) {
4796                 node.removeChild(node.firstChild);
4797             }
4798             var texts = Str(params.text).split("\n"),
4799                 tspans = [],
4800                 tspan;
4801             for (var i = 0, ii = texts.length; i < ii; i++) {
4802                 tspan = $("tspan");
4803                 i && $(tspan, {dy: fontSize * leading, x: a.x});
4804                 tspan.appendChild(R._g.doc.createTextNode(texts[i]));
4805                 node.appendChild(tspan);
4806                 tspans[i] = tspan;
4807             }
4808         } else {
4809             tspans = node.getElementsByTagName("tspan");
4810             for (i = 0, ii = tspans.length; i < ii; i++) if (i) {
4811                 $(tspans[i], {dy: fontSize * leading, x: a.x});
4812             } else {
4813                 $(tspans[0], {dy: 0});
4814             }
4815         }
4816         $(node, {x: a.x, y: a.y});
4817         el._.dirty = 1;
4818         var bb = el._getBBox(),
4819             dif = a.y - (bb.y + bb.height / 2);
4820         dif && R.is(dif, "finite") && $(tspans[0], {dy: dif});
4821     },
4822     Element = function (node, svg) {
4823         var X = 0,
4824             Y = 0;
4825         /*\
4826          * Element.node
4827          [ property (object) ]
4828          **
4829          * Gives you a reference to the DOM object, so you can assign event handlers or just mess around.
4830          > Usage
4831          | // draw a circle at coordinate 10,10 with radius of 10
4832          | var c = paper.circle(10, 10, 10);
4833          | c.node.onclick = function () {
4834          |     c.attr("fill", "red");
4835          | };
4836         \*/
4837         this[0] = this.node = node;
4838         /*\
4839          * Element.raphael
4840          [ property (object) ]
4841          **
4842          * Internal reference to @Raphael object. In case it is not available.
4843          > Usage
4844          | Raphael.el.red = function () {
4845          |     var hsb = this.paper.raphael.rgb2hsb(this.attr("fill"));
4846          |     hsb.h = 1;
4847          |     this.attr({fill: this.paper.raphael.hsb2rgb(hsb).hex});
4848          | }
4849         \*/
4850         node.raphael = true;
4851         /*\
4852          * Element.id
4853          [ property (number) ]
4854          **
4855          * Unique id of the element. Especially usesful when you want to listen to events of the element, 
4856          * because all events are fired in format `<module>.<action>.<id>`. Also useful for @Paper.getById method.
4857         \*/
4858         this.id = R._oid++;
4859         node.raphaelid = this.id;
4860         this.matrix = R.matrix();
4861         this.realPath = null;
4862         /*\
4863          * Element.paper
4864          [ property (object) ]
4865          **
4866          * Internal reference to “paper” where object drawn. Mainly for use in plugins and element extensions.
4867          > Usage
4868          | Raphael.el.cross = function () {
4869          |     this.attr({fill: "red"});
4870          |     this.paper.path("M10,10L50,50M50,10L10,50")
4871          |         .attr({stroke: "red"});
4872          | }
4873         \*/
4874         this.paper = svg;
4875         this.attrs = this.attrs || {};
4876         this._ = {
4877             transform: [],
4878             sx: 1,
4879             sy: 1,
4880             deg: 0,
4881             dx: 0,
4882             dy: 0,
4883             dirty: 1
4884         };
4885         !svg.bottom && (svg.bottom = this);
4886         /*\
4887          * Element.prev
4888          [ property (object) ]
4889          **
4890          * Reference to the previous element in the hierarchy.
4891         \*/
4892         this.prev = svg.top;
4893         svg.top && (svg.top.next = this);
4894         svg.top = this;
4895         /*\
4896          * Element.next
4897          [ property (object) ]
4898          **
4899          * Reference to the next element in the hierarchy.
4900         \*/
4901         this.next = null;
4902     },
4903     elproto = R.el;
4904
4905     Element.prototype = elproto;
4906     elproto.constructor = Element;
4907
4908     R._engine.path = function (pathString, SVG) {
4909         var el = $("path");
4910         SVG.canvas && SVG.canvas.appendChild(el);
4911         var p = new Element(el, SVG);
4912         p.type = "path";
4913         setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString});
4914         return p;
4915     };
4916     /*\
4917      * Element.rotate
4918      [ method ]
4919      **
4920      * Adds rotation by given angle around given point to the list of
4921      * transformations of the element.
4922      > Parameters
4923      - deg (number) angle in degrees
4924      - cx (number) #optional x coordinate of the centre of rotation
4925      - cy (number) #optional y coordinate of the centre of rotation
4926      * If cx & cy aren’t specified centre of the shape is used as a point of rotation.
4927      = (object) @Element
4928     \*/
4929     elproto.rotate = function (deg, cx, cy) {
4930         if (this.removed) {
4931             return this;
4932         }
4933         deg = Str(deg).split(separator);
4934         if (deg.length - 1) {
4935             cx = toFloat(deg[1]);
4936             cy = toFloat(deg[2]);
4937         }
4938         deg = toFloat(deg[0]);
4939         (cy == null) && (cx = cy);
4940         if (cx == null || cy == null) {
4941             var bbox = this.getBBox(1);
4942             cx = bbox.x + bbox.width / 2;
4943             cy = bbox.y + bbox.height / 2;
4944         }
4945         this.transform(this._.transform.concat([["r", deg, cx, cy]]));
4946         return this;
4947     };
4948     /*\
4949      * Element.scale
4950      [ method ]
4951      **
4952      * Adds scale by given amount relative to given point to the list of
4953      * transformations of the element.
4954      > Parameters
4955      - sx (number) horisontal scale amount
4956      - sy (number) vertical scale amount
4957      - cx (number) #optional x coordinate of the centre of scale
4958      - cy (number) #optional y coordinate of the centre of scale
4959      * If cx & cy aren’t specified centre of the shape is used instead.
4960      = (object) @Element
4961     \*/
4962     elproto.scale = function (sx, sy, cx, cy) {
4963         if (this.removed) {
4964             return this;
4965         }
4966         sx = Str(sx).split(separator);
4967         if (sx.length - 1) {
4968             sy = toFloat(sx[1]);
4969             cx = toFloat(sx[2]);
4970             cy = toFloat(sx[3]);
4971         }
4972         sx = toFloat(sx[0]);
4973         (sy == null) && (sy = sx);
4974         (cy == null) && (cx = cy);
4975         if (cx == null || cy == null) {
4976             var bbox = this.getBBox(1);
4977         }
4978         cx = cx == null ? bbox.x + bbox.width / 2 : cx;
4979         cy = cy == null ? bbox.y + bbox.height / 2 : cy;
4980         this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
4981         return this;
4982     };
4983     /*\
4984      * Element.translate
4985      [ method ]
4986      **
4987      * Adds translation by given amount to the list of transformations of the element.
4988      > Parameters
4989      - dx (number) horisontal shift
4990      - dy (number) vertical shift
4991      = (object) @Element
4992     \*/
4993     elproto.translate = function (dx, dy) {
4994         if (this.removed) {
4995             return this;
4996         }
4997         dx = Str(dx).split(separator);
4998         if (dx.length - 1) {
4999             dy = toFloat(dx[1]);
5000         }
5001         dx = toFloat(dx[0]) || 0;
5002         dy = +dy || 0;
5003         this.transform(this._.transform.concat([["t", dx, dy]]));
5004         return this;
5005     };
5006     /*\
5007      * Element.transform
5008      [ method ]
5009      **
5010      * Adds transformation to the element which is separate to other attributes,
5011      * i.e. translation doesn’t change `x` or `y` of the rectange. The format
5012      * of transformation string is similar to the path string syntax:
5013      | "t100,100r30,100,100s2,2,100,100r45s1.5"
5014      * Each letter is a command. There are four commands: `t` is for translate, `r` is for rotate, `s` is for
5015      * scale and `m` is for matrix.
5016      *
5017      * So, the example line above could be read like “translate by 100, 100; rotate 30° around 100, 100; scale twice around 100, 100;
5018      * rotate 45° around centre; scale 1.5 times relative to centre”. As you can see rotate and scale commands have origin
5019      * coordinates as optional parameters, the default is the centre point of the element.
5020      * Matrix accepts six parameters.
5021      > Usage
5022      | var el = paper.rect(10, 20, 300, 200);
5023      | // translate 100, 100, rotate 45°, translate -100, 0
5024      | el.transform("t100,100r45t-100,0");
5025      | // if you want you can append or prepend transformations
5026      | el.transform("...t50,50");
5027      | el.transform("s2...");
5028      | // or even wrap
5029      | el.transform("t50,50...t-50-50");
5030      | // to reset transformation call method with empty string
5031      | el.transform("");
5032      | // to get current value call it without parameters
5033      | console.log(el.transform());
5034      > Parameters
5035      - tstr (string) #optional transformation string
5036      * If tstr isn’t specified
5037      = (string) current transformation string
5038      * else
5039      = (object) @Element
5040     \*/
5041     elproto.transform = function (tstr) {
5042         var _ = this._;
5043         if (tstr == null) {
5044             return _.transform;
5045         }
5046         R._extractTransform(this, tstr);
5047
5048         this.clip && $(this.clip, {transform: this.matrix.invert()});
5049         this.pattern && updatePosition(this);
5050         this.node && $(this.node, {transform: this.matrix});
5051     
5052         if (_.sx != 1 || _.sy != 1) {
5053             var sw = this.attrs[has]("stroke-width") ? this.attrs["stroke-width"] : 1;
5054             this.attr({"stroke-width": sw});
5055         }
5056
5057         return this;
5058     };
5059     /*\
5060      * Element.hide
5061      [ method ]
5062      **
5063      * Makes element invisible. See @Element.show.
5064      = (object) @Element
5065     \*/
5066     elproto.hide = function () {
5067         !this.removed && this.paper.safari(this.node.style.display = "none");
5068         return this;
5069     };
5070     /*\
5071      * Element.show
5072      [ method ]
5073      **
5074      * Makes element visible. See @Element.hide.
5075      = (object) @Element
5076     \*/
5077     elproto.show = function () {
5078         !this.removed && this.paper.safari(this.node.style.display = "");
5079         return this;
5080     };
5081     /*\
5082      * Element.remove
5083      [ method ]
5084      **
5085      * Removes element form the paper.
5086     \*/
5087     elproto.remove = function () {
5088         if (this.removed) {
5089             return;
5090         }
5091         eve.unbind("*.*." + this.id);
5092         R._tear(this, this.paper);
5093         this.node.parentNode.removeChild(this.node);
5094         for (var i in this) {
5095             delete this[i];
5096         }
5097         this.removed = true;
5098     };
5099     elproto._getBBox = function () {
5100         if (this.node.style.display == "none") {
5101             this.show();
5102             var hide = true;
5103         }
5104         var bbox = {};
5105         try {
5106             bbox = this.node.getBBox();
5107         } catch(e) {
5108             // Firefox 3.0.x plays badly here
5109         } finally {
5110             bbox = bbox || {};
5111         }
5112         hide && this.hide();
5113         return bbox;
5114     };
5115     /*\
5116      * Element.attr
5117      [ method ]
5118      **
5119      * Sets the attributes of the element.
5120      > Parameters
5121      - attrName (string) attribute’s name
5122      - value (string) value
5123      * or
5124      - params (object) object of name/value pairs
5125      * or
5126      - attrName (string) attribute’s name
5127      * or
5128      - attrNames (array) in this case method returns array of current values for given attribute names
5129      = (object) @Element if attrsName & value or params are passed in.
5130      = (...) value of the attribute if only attrsName is passed in.
5131      = (array) array of values of the attribute if attrsNames is passed in.
5132      = (object) object of attributes if nothing is passed in.
5133      > Possible parameters
5134      # <p>Please refer to the <a href="http://www.w3.org/TR/SVG/" title="The W3C Recommendation for the SVG language describes these properties in detail.">SVG specification</a> for an explanation of these parameters.</p>
5135      o arrow-end (string) arrowhead on the end of the path. The format for string is `<type>[-<width>[-<length>]]`. Possible types: `classic`, `block`, `open`, `oval`, `diamond`, `none`, width: `wide`, `narrow`, `midium`, length: `long`, `short`, `midium`.
5136      o clip-rect (string) comma or space separated values: x, y, width and height
5137      o cursor (string) CSS type of the cursor
5138      o cx (number)
5139      o cy (number)
5140      o fill (string) colour, gradient or image
5141      o fill-opacity (number)
5142      o font (string)
5143      o font-family (string)
5144      o font-size (number) font size in pixels
5145      o font-weight (string)
5146      o height (number)
5147      o href (string) URL, if specified element behaves as hyperlink
5148      o opacity (number)
5149      o path (string) SVG path string format
5150      o r (number)
5151      o rx (number)
5152      o ry (number)
5153      o src (string) image URL, only works for @Element.image element
5154      o stroke (string) stroke colour
5155      o stroke-dasharray (string) [“”, “`-`”, “`.`”, “`-.`”, “`-..`”, “`. `”, “`- `”, “`--`”, “`- .`”, “`--.`”, “`--..`”]
5156      o stroke-linecap (string) [“`butt`”, “`square`”, “`round`”]
5157      o stroke-linejoin (string) [“`bevel`”, “`round`”, “`miter`”]
5158      o stroke-miterlimit (number)
5159      o stroke-opacity (number)
5160      o stroke-width (number) stroke width in pixels, default is '1'
5161      o target (string) used with href
5162      o text (string) contents of the text element. Use `\n` for multiline text
5163      o text-anchor (string) [“`start`”, “`middle`”, “`end`”], default is “`middle`”
5164      o title (string) will create tooltip with a given text
5165      o transform (string) see @Element.transform
5166      o width (number)
5167      o x (number)
5168      o y (number)
5169      > Gradients
5170      * Linear gradient format: “`‹angle›-‹colour›[-‹colour›[:‹offset›]]*-‹colour›`”, example: “`90-#fff-#000`” – 90°
5171      * gradient from white to black or “`0-#fff-#f00:20-#000`” – 0° gradient from white via red (at 20%) to black.
5172      *
5173      * radial gradient: “`r[(‹fx›, ‹fy›)]‹colour›[-‹colour›[:‹offset›]]*-‹colour›`”, example: “`r#fff-#000`” –
5174      * gradient from white to black or “`r(0.25, 0.75)#fff-#000`” – gradient from white to black with focus point
5175      * at 0.25, 0.75. Focus point coordinates are in 0..1 range. Radial gradients can only be applied to circles and ellipses.
5176      > Path String
5177      # <p>Please refer to <a href="http://www.w3.org/TR/SVG/paths.html#PathData" title="Details of a path’s data attribute’s format are described in the SVG specification.">SVG documentation regarding path string</a>. Raphaël fully supports it.</p>
5178      > Colour Parsing
5179      # <ul>
5180      #     <li>Colour name (“<code>red</code>”, “<code>green</code>”, “<code>cornflowerblue</code>”, etc)</li>
5181      #     <li>#••• — shortened HTML colour: (“<code>#000</code>”, “<code>#fc0</code>”, etc)</li>
5182      #     <li>#•••••• — full length HTML colour: (“<code>#000000</code>”, “<code>#bd2300</code>”)</li>
5183      #     <li>rgb(•••, •••, •••) — red, green and blue channels’ values: (“<code>rgb(200,&nbsp;100,&nbsp;0)</code>”)</li>
5184      #     <li>rgb(•••%, •••%, •••%) — same as above, but in %: (“<code>rgb(100%,&nbsp;175%,&nbsp;0%)</code>”)</li>
5185      #     <li>rgba(•••, •••, •••, •••) — red, green and blue channels’ values: (“<code>rgba(200,&nbsp;100,&nbsp;0, .5)</code>”)</li>
5186      #     <li>rgba(•••%, •••%, •••%, •••%) — same as above, but in %: (“<code>rgba(100%,&nbsp;175%,&nbsp;0%, 50%)</code>”)</li>
5187      #     <li>hsb(•••, •••, •••) — hue, saturation and brightness values: (“<code>hsb(0.5,&nbsp;0.25,&nbsp;1)</code>”)</li>
5188      #     <li>hsb(•••%, •••%, •••%) — same as above, but in %</li>
5189      #     <li>hsba(•••, •••, •••, •••) — same as above, but with opacity</li>
5190      #     <li>hsl(•••, •••, •••) — almost the same as hsb, see <a href="http://en.wikipedia.org/wiki/HSL_and_HSV" title="HSL and HSV - Wikipedia, the free encyclopedia">Wikipedia page</a></li>
5191      #     <li>hsl(•••%, •••%, •••%) — same as above, but in %</li>
5192      #     <li>hsla(•••, •••, •••) — same as above, but with opacity</li>
5193      #     <li>Optionally for hsb and hsl you could specify hue as a degree: “<code>hsl(240deg,&nbsp;1,&nbsp;.5)</code>” or, if you want to go fancy, “<code>hsl(240°,&nbsp;1,&nbsp;.5)</code>”</li>
5194      # </ul>
5195     \*/
5196     elproto.attr = function (name, value) {
5197         if (this.removed) {
5198             return this;
5199         }
5200         if (name == null) {
5201             var res = {};
5202             for (var a in this.attrs) if (this.attrs[has](a)) {
5203                 res[a] = this.attrs[a];
5204             }
5205             res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
5206             res.transform = this._.transform;
5207             return res;
5208         }
5209         if (value == null && R.is(name, "string")) {
5210             if (name == "fill" && this.attrs.fill == "none" && this.attrs.gradient) {
5211                 return this.attrs.gradient;
5212             }
5213             if (name == "transform") {
5214                 return this._.transform;
5215             }
5216             var names = name.split(separator),
5217                 out = {};
5218             for (var i = 0, ii = names.length; i < ii; i++) {
5219                 name = names[i];
5220                 if (name in this.attrs) {
5221                     out[name] = this.attrs[name];
5222                 } else if (R.is(this.paper.customAttributes[name], "function")) {
5223                     out[name] = this.paper.customAttributes[name].def;
5224                 } else {
5225                     out[name] = R._availableAttrs[name];
5226                 }
5227             }
5228             return ii - 1 ? out : out[names[0]];
5229         }
5230         if (value == null && R.is(name, "array")) {
5231             out = {};
5232             for (i = 0, ii = name.length; i < ii; i++) {
5233                 out[name[i]] = this.attr(name[i]);
5234             }
5235             return out;
5236         }
5237         if (value != null) {
5238             var params = {};
5239             params[name] = value;
5240         } else if (name != null && R.is(name, "object")) {
5241             params = name;
5242         }
5243         for (var key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
5244             var par = this.paper.customAttributes[key].apply(this, [].concat(params[key]));
5245             this.attrs[key] = params[key];
5246             for (var subkey in par) if (par[has](subkey)) {
5247                 params[subkey] = par[subkey];
5248             }
5249         }
5250         setFillAndStroke(this, params);
5251         return this;
5252     };
5253     /*\
5254      * Element.toFront
5255      [ method ]
5256      **
5257      * Moves the element so it is the closest to the viewer’s eyes, on top of other elements.
5258      = (object) @Element
5259     \*/
5260     elproto.toFront = function () {
5261         if (this.removed) {
5262             return this;
5263         }
5264         this.node.parentNode.appendChild(this.node);
5265         var svg = this.paper;
5266         svg.top != this && R._tofront(this, svg);
5267         return this;
5268     };
5269     /*\
5270      * Element.toBack
5271      [ method ]
5272      **
5273      * Moves the element so it is the furthest from the viewer’s eyes, behind other elements.
5274      = (object) @Element
5275     \*/
5276     elproto.toBack = function () {
5277         if (this.removed) {
5278             return this;
5279         }
5280         if (this.node.parentNode.firstChild != this.node) {
5281             this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
5282             R._toback(this, this.paper);
5283             var svg = this.paper;
5284         }
5285         return this;
5286     };
5287     /*\
5288      * Element.insertAfter
5289      [ method ]
5290      **
5291      * Inserts current object after the given one.
5292      = (object) @Element
5293     \*/
5294     elproto.insertAfter = function (element) {
5295         if (this.removed) {
5296             return this;
5297         }
5298         var node = element.node || element[element.length - 1].node;
5299         if (node.nextSibling) {
5300             node.parentNode.insertBefore(this.node, node.nextSibling);
5301         } else {
5302             node.parentNode.appendChild(this.node);
5303         }
5304         R._insertafter(this, element, this.paper);
5305         return this;
5306     };
5307     /*\
5308      * Element.insertBefore
5309      [ method ]
5310      **
5311      * Inserts current object before the given one.
5312      = (object) @Element
5313     \*/
5314     elproto.insertBefore = function (element) {
5315         if (this.removed) {
5316             return this;
5317         }
5318         var node = element.node || element[0].node;
5319         node.parentNode.insertBefore(this.node, node);
5320         R._insertbefore(this, element, this.paper);
5321         return this;
5322     };
5323     elproto.blur = function (size) {
5324         // Experimental. No Safari support. Use it on your own risk.
5325         var t = this;
5326         if (+size !== 0) {
5327             var fltr = $("filter"),
5328                 blur = $("feGaussianBlur");
5329             t.attrs.blur = size;
5330             fltr.id = R._createUUID();
5331             $(blur, {stdDeviation: +size || 1.5});
5332             fltr.appendChild(blur);
5333             t.paper.defs.appendChild(fltr);
5334             t._blur = fltr;
5335             $(t.node, {filter: "url(#" + fltr.id + ")"});
5336         } else {
5337             if (t._blur) {
5338                 t._blur.parentNode.removeChild(t._blur);
5339                 delete t._blur;
5340                 delete t.attrs.blur;
5341             }
5342             t.node.removeAttribute("filter");
5343         }
5344     };
5345     R._engine.circle = function (svg, x, y, r) {
5346         var el = $("circle");
5347         svg.canvas && svg.canvas.appendChild(el);
5348         var res = new Element(el, svg);
5349         res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
5350         res.type = "circle";
5351         $(el, res.attrs);
5352         return res;
5353     };
5354     R._engine.rect = function (svg, x, y, w, h, r) {
5355         var el = $("rect");
5356         svg.canvas && svg.canvas.appendChild(el);
5357         var res = new Element(el, svg);
5358         res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
5359         res.type = "rect";
5360         $(el, res.attrs);
5361         return res;
5362     };
5363     R._engine.ellipse = function (svg, x, y, rx, ry) {
5364         var el = $("ellipse");
5365         svg.canvas && svg.canvas.appendChild(el);
5366         var res = new Element(el, svg);
5367         res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
5368         res.type = "ellipse";
5369         $(el, res.attrs);
5370         return res;
5371     };
5372     R._engine.image = function (svg, src, x, y, w, h) {
5373         var el = $("image");
5374         $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
5375         el.setAttributeNS(xlink, "href", src);
5376         svg.canvas && svg.canvas.appendChild(el);
5377         var res = new Element(el, svg);
5378         res.attrs = {x: x, y: y, width: w, height: h, src: src};
5379         res.type = "image";
5380         return res;
5381     };
5382     R._engine.text = function (svg, x, y, text) {
5383         var el = $("text");
5384         // $(el, {x: x, y: y, "text-anchor": "middle"});
5385         svg.canvas && svg.canvas.appendChild(el);
5386         var res = new Element(el, svg);
5387         res.attrs = {
5388             x: x,
5389             y: y,
5390             "text-anchor": "middle",
5391             text: text,
5392             font: R._availableAttrs.font,
5393             stroke: "none",
5394             fill: "#000"
5395         };
5396         res.type = "text";
5397         setFillAndStroke(res, res.attrs);
5398         return res;
5399     };
5400     R._engine.setSize = function (width, height) {
5401         this.width = width || this.width;
5402         this.height = height || this.height;
5403         this.canvas.setAttribute("width", this.width);
5404         this.canvas.setAttribute("height", this.height);
5405         if (this._viewBox) {
5406             this.setViewBox.apply(this, this._viewBox);
5407         }
5408         return this;
5409     };
5410     R._engine.create = function () {
5411         var con = R._getContainer.apply(0, arguments),
5412             container = con && con.container,
5413             x = con.x,
5414             y = con.y,
5415             width = con.width,
5416             height = con.height;
5417         if (!container) {
5418             throw new Error("SVG container not found.");
5419         }
5420         var cnvs = $("svg"),
5421             css = "overflow:hidden;",
5422             isFloating;
5423         x = x || 0;
5424         y = y || 0;
5425         width = width || 512;
5426         height = height || 342;
5427         $(cnvs, {
5428             height: height,
5429             version: 1.1,
5430             width: width,
5431             xmlns: "http://www.w3.org/2000/svg"
5432         });
5433         if (container == 1) {
5434             cnvs.style.cssText = css + "position:absolute;left:" + x + "px;top:" + y + "px";
5435             R._g.doc.body.appendChild(cnvs);
5436             isFloating = 1;
5437         } else {
5438             cnvs.style.cssText = css + "position:relative";
5439             if (container.firstChild) {
5440                 container.insertBefore(cnvs, container.firstChild);
5441             } else {
5442                 container.appendChild(cnvs);
5443             }
5444         }
5445         container = new R._Paper;
5446         container.width = width;
5447         container.height = height;
5448         container.canvas = cnvs;
5449         // plugins.call(container, container, R.fn);
5450         container.clear();
5451         container._left = container._top = 0;
5452         isFloating && (container.renderfix = function () {});
5453         container.renderfix();
5454         return container;
5455     };
5456     R._engine.setViewBox = function (x, y, w, h, fit) {
5457         eve("setViewBox", this, this._viewBox, [x, y, w, h, fit]);
5458         var size = mmax(w / this.width, h / this.height),
5459             top = this.top,
5460             aspectRatio = fit ? "meet" : "xMinYMin",
5461             vb,
5462             sw;
5463         if (x == null) {
5464             if (this._vbSize) {
5465                 size = 1;
5466             }
5467             delete this._vbSize;
5468             vb = "0 0 " + this.width + S + this.height;
5469         } else {
5470             this._vbSize = size;
5471             vb = x + S + y + S + w + S + h;
5472         }
5473         $(this.canvas, {
5474             viewBox: vb,
5475             preserveAspectRatio: aspectRatio
5476         });
5477         while (size && top) {
5478             sw = "stroke-width" in top.attrs ? top.attrs["stroke-width"] : 1;
5479             top.attr({"stroke-width": sw});
5480             top._.dirty = 1;
5481             top._.dirtyT = 1;
5482             top = top.prev;
5483         }
5484         this._viewBox = [x, y, w, h, !!fit];
5485         return this;
5486     };
5487     /*\
5488      * Paper.renderfix
5489      [ method ]
5490      **
5491      * Fixes the issue of Firefox and IE9 regarding subpixel rendering. If paper is dependant
5492      * on other elements after reflow it could shift half pixel which cause for lines to lost their crispness.
5493      * This method fixes the issue.
5494      **
5495        Special thanks to Mariusz Nowak (http://www.medikoo.com/) for this method.
5496     \*/
5497     R.prototype.renderfix = function () {
5498         var cnvs = this.canvas,
5499             s = cnvs.style,
5500             pos = cnvs.getScreenCTM(),
5501             left = -pos.e % 1,
5502             top = -pos.f % 1;
5503         if (left || top) {
5504             if (left) {
5505                 this._left = (this._left + left) % 1;
5506                 s.left = this._left + "px";
5507             }
5508             if (top) {
5509                 this._top = (this._top + top) % 1;
5510                 s.top = this._top + "px";
5511             }
5512         }
5513     };
5514     /*\
5515      * Paper.clear
5516      [ method ]
5517      **
5518      * Clears the paper, i.e. removes all the elements.
5519     \*/
5520     R.prototype.clear = function () {
5521         R.eve("clear", this);
5522         var c = this.canvas;
5523         while (c.firstChild) {
5524             c.removeChild(c.firstChild);
5525         }
5526         this.bottom = this.top = null;
5527         (this.desc = $("desc")).appendChild(R._g.doc.createTextNode("Created with Rapha\xebl " + R.version));
5528         c.appendChild(this.desc);
5529         c.appendChild(this.defs = $("defs"));
5530     };
5531     /*\
5532      * Paper.remove
5533      [ method ]
5534      **
5535      * Removes the paper from the DOM.
5536     \*/
5537     R.prototype.remove = function () {
5538         eve("remove", this);
5539         this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
5540         for (var i in this) {
5541             this[i] = removed(i);
5542         }
5543     };
5544     var setproto = R.st;
5545     for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) {
5546         setproto[method] = (function (methodname) {
5547             return function () {
5548                 var arg = arguments;
5549                 return this.forEach(function (el) {
5550                     el[methodname].apply(el, arg);
5551                 });
5552             };
5553         })(method);
5554     }
5555 }(window.Raphael);
5556
5557 // ┌─────────────────────────────────────────────────────────────────────┐ \\
5558 // │ Raphaël 2 - JavaScript Vector Library                               │ \\
5559 // ├─────────────────────────────────────────────────────────────────────┤ \\
5560 // │ VML Module                                                          │ \\
5561 // ├─────────────────────────────────────────────────────────────────────┤ \\
5562 // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com)   │ \\
5563 // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com)             │ \\
5564 // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
5565 // └─────────────────────────────────────────────────────────────────────┘ \\
5566 window.Raphael.vml && function (R) {
5567     var has = "hasOwnProperty",
5568         Str = String,
5569         toFloat = parseFloat,
5570         math = Math,
5571         round = math.round,
5572         mmax = math.max,
5573         mmin = math.min,
5574         abs = math.abs,
5575         fillString = "fill",
5576         separator = /[, ]+/,
5577         eve = R.eve,
5578         S = " ",
5579         E = "";
5580     // VML
5581     var map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
5582         bites = /([clmz]),?([^clmz]*)/gi,
5583         blurregexp = / progid:\S+Blur\([^\)]+\)/g,
5584         val = /-?[^,\s-]+/g,
5585         cssDot = "position:absolute;left:0;top:0;width:1px;height:1px",
5586         zoom = 21600,
5587         pathTypes = {path: 1, rect: 1},
5588         ovalTypes = {circle: 1, ellipse: 1},
5589         path2vml = function (path) {
5590             var total =  /[ahqstv]/ig,
5591                 command = R._pathToAbsolute;
5592             Str(path).match(total) && (command = path2curve);
5593             total = /[clmz]/g;
5594             if (command == R._pathToAbsolute && !Str(path).match(total)) {
5595                 var res = Str(path).replace(bites, function (all, command, args) {
5596                     var vals = [],
5597                         isMove = command.toLowerCase() == "m",
5598                         res = map[command];
5599                     args.replace(val, function (value) {
5600                         if (isMove && vals.length == 2) {
5601                             res += vals + map[command == "m" ? "l" : "L"];
5602                             vals = [];
5603                         }
5604                         vals.push(round(value * zoom));
5605                     });
5606                     return res + vals;
5607                 });
5608                 return res;
5609             }
5610             var pa = command(path), p, r;
5611             res = [];
5612             for (var i = 0, ii = pa.length; i < ii; i++) {
5613                 p = pa[i];
5614                 r = pa[i][0].toLowerCase();
5615                 r == "z" && (r = "x");
5616                 for (var j = 1, jj = p.length; j < jj; j++) {
5617                     r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
5618                 }
5619                 res.push(r);
5620             }
5621             return res.join(S);
5622         },
5623         compensation = function (deg, dx, dy) {
5624             var m = R.matrix();
5625             m.rotate(-deg, .5, .5);
5626             return {
5627                 dx: m.x(dx, dy),
5628                 dy: m.y(dx, dy)
5629             };
5630         },
5631         setCoords = function (p, sx, sy, dx, dy, deg) {
5632             var _ = p._,
5633                 m = p.matrix,
5634                 fillpos = _.fillpos,
5635                 o = p.node,
5636                 s = o.style,
5637                 y = 1,
5638                 flip = "",
5639                 dxdy,
5640                 kx = zoom / sx,
5641                 ky = zoom / sy;
5642             s.visibility = "hidden";
5643             if (!sx || !sy) {
5644                 return;
5645             }
5646             o.coordsize = abs(kx) + S + abs(ky);
5647             s.rotation = deg * (sx * sy < 0 ? -1 : 1);
5648             if (deg) {
5649                 var c = compensation(deg, dx, dy);
5650                 dx = c.dx;
5651                 dy = c.dy;
5652             }
5653             sx < 0 && (flip += "x");
5654             sy < 0 && (flip += " y") && (y = -1);
5655             s.flip = flip;
5656             o.coordorigin = (dx * -kx) + S + (dy * -ky);
5657             if (fillpos || _.fillsize) {
5658                 var fill = o.getElementsByTagName(fillString);
5659                 fill = fill && fill[0];
5660                 o.removeChild(fill);
5661                 if (fillpos) {
5662                     c = compensation(deg, m.x(fillpos[0], fillpos[1]), m.y(fillpos[0], fillpos[1]));
5663                     fill.position = c.dx * y + S + c.dy * y;
5664                 }
5665                 if (_.fillsize) {
5666                     fill.size = _.fillsize[0] * abs(sx) + S + _.fillsize[1] * abs(sy);
5667                 }
5668                 o.appendChild(fill);
5669             }
5670             s.visibility = "visible";
5671         };
5672     R.toString = function () {
5673         return  "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
5674     };
5675     addArrow = function (o, value, isEnd) {
5676         var values = Str(value).toLowerCase().split("-"),
5677             se = isEnd ? "end" : "start",
5678             i = values.length,
5679             type = "classic",
5680             w = "medium",
5681             h = "medium";
5682         while (i--) {
5683             switch (values[i]) {
5684                 case "block":
5685                 case "classic":
5686                 case "oval":
5687                 case "diamond":
5688                 case "open":
5689                 case "none":
5690                     type = values[i];
5691                     break;
5692                 case "wide":
5693                 case "narrow": h = values[i]; break;
5694                 case "long":
5695                 case "short": w = values[i]; break;
5696             }
5697         }
5698         var stroke = o.node.getElementsByTagName("stroke")[0];
5699         stroke[se + "arrow"] = type;
5700         stroke[se + "arrowlength"] = w;
5701         stroke[se + "arrowwidth"] = h;
5702     };
5703     setFillAndStroke = function (o, params) {
5704         // o.paper.canvas.style.display = "none";
5705         o.attrs = o.attrs || {};
5706         var node = o.node,
5707             a = o.attrs,
5708             s = node.style,
5709             xy,
5710             newpath = pathTypes[o.type] && (params.x != a.x || params.y != a.y || params.width != a.width || params.height != a.height || params.cx != a.cx || params.cy != a.cy || params.rx != a.rx || params.ry != a.ry || params.r != a.r),
5711             isOval = ovalTypes[o.type] && (a.cx != params.cx || a.cy != params.cy || a.r != params.r || a.rx != params.rx || a.ry != params.ry),
5712             res = o;
5713
5714
5715         for (var par in params) if (params[has](par)) {
5716             a[par] = params[par];
5717         }
5718         if (newpath) {
5719             a.path = R._getPath[o.type](o);
5720             o._.dirty = 1;
5721         }
5722         params.href && (node.href = params.href);
5723         params.title && (node.title = params.title);
5724         params.target && (node.target = params.target);
5725         params.cursor && (s.cursor = params.cursor);
5726         "blur" in params && o.blur(params.blur);
5727         "transform" in params && o.transform(params.transform);
5728         if (params.path && o.type == "path" || newpath) {
5729             node.path = path2vml(a.path);
5730         }
5731         if (isOval) {
5732             var cx = a.cx,
5733                 cy = a.cy,
5734                 rx = a.rx || a.r || 0,
5735                 ry = a.ry || a.r || 0;
5736             node.path = R.format("ar{0},{1},{2},{3},{4},{1},{4},{1}x", round((cx - rx) * zoom), round((cy - ry) * zoom), round((cx + rx) * zoom), round((cy + ry) * zoom), round(cx * zoom));
5737         }
5738         if ("clip-rect" in params) {
5739             var rect = Str(params["clip-rect"]).split(separator);
5740             if (rect.length == 4) {
5741                 rect[2] = +rect[2] + (+rect[0]);
5742                 rect[3] = +rect[3] + (+rect[1]);
5743                 var div = node.clipRect || R._g.doc.createElement("div"),
5744                     dstyle = div.style,
5745                     group = node.parentNode;
5746                 dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
5747                 if (!node.clipRect) {
5748                     dstyle.position = "absolute";
5749                     dstyle.top = 0;
5750                     dstyle.left = 0;
5751                     dstyle.width = o.paper.width + "px";
5752                     dstyle.height = o.paper.height + "px";
5753                     group.parentNode.insertBefore(div, group);
5754                     div.appendChild(group);
5755                     node.clipRect = div;
5756                 }
5757             }
5758             if (!params["clip-rect"]) {
5759                 node.clipRect && (node.clipRect.style.clip = E);
5760             }
5761         }
5762         if (o.textpath) {
5763             var textpathStyle = o.textpath.style;
5764             params.font && (textpathStyle.font = params.font);
5765             params["font-family"] && (textpathStyle.fontFamily = '"' + params["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g, E) + '"');
5766             params["font-size"] && (textpathStyle.fontSize = params["font-size"]);
5767             params["font-weight"] && (textpathStyle.fontWeight = params["font-weight"]);
5768             params["font-style"] && (textpathStyle.fontStyle = params["font-style"]);
5769         }
5770         if ("arrow-start" in params) {
5771             addArrow(res, params["arrow-start"]);
5772         }
5773         if ("arrow-end" in params) {
5774             addArrow(res, params["arrow-end"], 1);
5775         }
5776         if (params.opacity != null || 
5777             params["stroke-width"] != null ||
5778             params.fill != null ||
5779             params.src != null ||
5780             params.stroke != null ||
5781             params["stroke-width"] != null ||
5782             params["stroke-opacity"] != null ||
5783             params["fill-opacity"] != null ||
5784             params["stroke-dasharray"] != null ||
5785             params["stroke-miterlimit"] != null ||
5786             params["stroke-linejoin"] != null ||
5787             params["stroke-linecap"] != null) {
5788             var fill = node.getElementsByTagName(fillString),
5789                 newfill = false;
5790             fill = fill && fill[0];
5791             !fill && (newfill = fill = createNode(fillString));
5792             if (o.type == "image" && params.src) {
5793                 fill.src = params.src;
5794             }
5795             params.fill && (fill.on = true);
5796             if (fill.on == null || params.fill == "none" || params.fill === null) {
5797                 fill.on = false;
5798             }
5799             if (fill.on && params.fill) {
5800                 var isURL = Str(params.fill).match(R._ISURL);
5801                 if (isURL) {
5802                     fill.parentNode == node && node.removeChild(fill);
5803                     fill.rotate = true;
5804                     fill.src = isURL[1];
5805                     fill.type = "tile";
5806                     var bbox = o.getBBox(1);
5807                     fill.position = bbox.x + S + bbox.y;
5808                     o._.fillpos = [bbox.x, bbox.y];
5809
5810                     R._preload(isURL[1], function () {
5811                         o._.fillsize = [this.offsetWidth, this.offsetHeight];
5812                     });
5813                 } else {
5814                     fill.color = R.getRGB(params.fill).hex;
5815                     fill.src = E;
5816                     fill.type = "solid";
5817                     if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || Str(params.fill).charAt() != "r") && addGradientFill(res, params.fill, fill)) {
5818                         a.fill = "none";
5819                         a.gradient = params.fill;
5820                         fill.rotate = false;
5821                     }
5822                 }
5823             }
5824             if ("fill-opacity" in params || "opacity" in params) {
5825                 var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
5826                 opacity = mmin(mmax(opacity, 0), 1);
5827                 fill.opacity = opacity;
5828                 if (fill.src) {
5829                     fill.color = "none";
5830                 }
5831             }
5832             node.appendChild(fill);
5833             var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
5834             newstroke = false;
5835             !stroke && (newstroke = stroke = createNode("stroke"));
5836             if ((params.stroke && params.stroke != "none") ||
5837                 params["stroke-width"] ||
5838                 params["stroke-opacity"] != null ||
5839                 params["stroke-dasharray"] ||
5840                 params["stroke-miterlimit"] ||
5841                 params["stroke-linejoin"] ||
5842                 params["stroke-linecap"]) {
5843                 stroke.on = true;
5844             }
5845             (params.stroke == "none" || params.stroke === null || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
5846             var strokeColor = R.getRGB(params.stroke);
5847             stroke.on && params.stroke && (stroke.color = strokeColor.hex);
5848             opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
5849             var width = (toFloat(params["stroke-width"]) || 1) * .75;
5850             opacity = mmin(mmax(opacity, 0), 1);
5851             params["stroke-width"] == null && (width = a["stroke-width"]);
5852             params["stroke-width"] && (stroke.weight = width);
5853             width && width < 1 && (opacity *= width) && (stroke.weight = 1);
5854             stroke.opacity = opacity;
5855         
5856             params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
5857             stroke.miterlimit = params["stroke-miterlimit"] || 8;
5858             params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
5859             if (params["stroke-dasharray"]) {
5860                 var dasharray = {
5861                     "-": "shortdash",
5862                     ".": "shortdot",
5863                     "-.": "shortdashdot",
5864                     "-..": "shortdashdotdot",
5865                     ". ": "dot",
5866                     "- ": "dash",
5867                     "--": "longdash",
5868                     "- .": "dashdot",
5869                     "--.": "longdashdot",
5870                     "--..": "longdashdotdot"
5871                 };
5872                 stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
5873             }
5874             newstroke && node.appendChild(stroke);
5875         }
5876         if (res.type == "text") {
5877             res.paper.canvas.style.display = E;
5878             var span = res.paper.span,
5879                 m = 100,
5880                 fontSize = a.font && a.font.match(/\d+(?:\.\d*)?(?=px)/);
5881             s = span.style;
5882             a.font && (s.font = a.font);
5883             a["font-family"] && (s.fontFamily = a["font-family"]);
5884             a["font-weight"] && (s.fontWeight = a["font-weight"]);
5885             a["font-style"] && (s.fontStyle = a["font-style"]);
5886             fontSize = toFloat(fontSize ? fontSize[0] : a["font-size"]);
5887             s.fontSize = fontSize * m + "px";
5888             res.textpath.string && (span.innerHTML = Str(res.textpath.string).replace(/</g, "&#60;").replace(/&/g, "&#38;").replace(/\n/g, "<br>"));
5889             var brect = span.getBoundingClientRect();
5890             res.W = a.w = (brect.right - brect.left) / m;
5891             res.H = a.h = (brect.bottom - brect.top) / m;
5892             res.paper.canvas.style.display = "none";
5893             res.X = a.x;
5894             res.Y = a.y + res.H / 2;
5895
5896             ("x" in params || "y" in params) && (res.path.v = R.format("m{0},{1}l{2},{1}", round(a.x * zoom), round(a.y * zoom), round(a.x * zoom) + 1));
5897             var dirtyattrs = ["x", "y", "text", "font", "font-family", "font-weight", "font-style", "font-size"];
5898             for (var d = 0, dd = dirtyattrs.length; d < dd; d++) if (dirtyattrs[d] in params) {
5899                 res._.dirty = 1;
5900                 break;
5901             }
5902         
5903             // text-anchor emulation
5904             switch (a["text-anchor"]) {
5905                 case "start":
5906                     res.textpath.style["v-text-align"] = "left";
5907                     res.bbx = res.W / 2;
5908                 break;
5909                 case "end":
5910                     res.textpath.style["v-text-align"] = "right";
5911                     res.bbx = -res.W / 2;
5912                 break;
5913                 default:
5914                     res.textpath.style["v-text-align"] = "center";
5915                     res.bbx = 0;
5916                 break;
5917             }
5918             res.textpath.style["v-text-kern"] = true;
5919         }
5920         // res.paper.canvas.style.display = E;
5921     };
5922     addGradientFill = function (o, gradient, fill) {
5923         o.attrs = o.attrs || {};
5924         var attrs = o.attrs,
5925             opacity,
5926             oindex,
5927             type = "linear",
5928             fxfy = ".5 .5";
5929         o.attrs.gradient = gradient;
5930         gradient = Str(gradient).replace(R._radial_gradient, function (all, fx, fy) {
5931             type = "radial";
5932             if (fx && fy) {
5933                 fx = toFloat(fx);
5934                 fy = toFloat(fy);
5935                 pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
5936                 fxfy = fx + S + fy;
5937             }
5938             return E;
5939         });
5940         gradient = gradient.split(/\s*\-\s*/);
5941         if (type == "linear") {
5942             var angle = gradient.shift();
5943             angle = -toFloat(angle);
5944             if (isNaN(angle)) {
5945                 return null;
5946             }
5947         }
5948         var dots = R._parseDots(gradient);
5949         if (!dots) {
5950             return null;
5951         }
5952         o = o.shape || o.node;
5953         if (dots.length) {
5954             o.removeChild(fill);
5955             fill.on = true;
5956             fill.method = "none";
5957             fill.color = dots[0].color;
5958             fill.color2 = dots[dots.length - 1].color;
5959             var clrs = [];
5960             for (var i = 0, ii = dots.length; i < ii; i++) {
5961                 dots[i].offset && clrs.push(dots[i].offset + S + dots[i].color);
5962             }
5963             fill.colors = clrs.length ? clrs.join() : "0% " + fill.color;
5964             if (type == "radial") {
5965                 fill.type = "gradientTitle";
5966                 fill.focus = "100%";
5967                 fill.focussize = "0 0";
5968                 fill.focusposition = fxfy;
5969                 fill.angle = 0;
5970             } else {
5971                 // fill.rotate= true;
5972                 fill.type = "gradient";
5973                 fill.angle = (270 - angle) % 360;
5974             }
5975             o.appendChild(fill);
5976         }
5977         return 1;
5978     };
5979     Element = function (node, vml) {
5980         this[0] = this.node = node;
5981         node.raphael = true;
5982         this.id = R._oid++;
5983         node.raphaelid = this.id;
5984         this.X = 0;
5985         this.Y = 0;
5986         this.attrs = {};
5987         this.paper = vml;
5988         this.matrix = R.matrix();
5989         this._ = {
5990             transform: [],
5991             sx: 1,
5992             sy: 1,
5993             dx: 0,
5994             dy: 0,
5995             deg: 0,
5996             dirty: 1,
5997             dirtyT: 1
5998         };
5999         !vml.bottom && (vml.bottom = this);
6000         this.prev = vml.top;
6001         vml.top && (vml.top.next = this);
6002         vml.top = this;
6003         this.next = null;
6004     };
6005     var elproto = R.el;
6006
6007     Element.prototype = elproto;
6008     elproto.constructor = Element;
6009     elproto.transform = function (tstr) {
6010         if (tstr == null) {
6011             return this._.transform;
6012         }
6013         R._extractTransform(this, tstr);
6014         var matrix = this.matrix.clone(),
6015             vbs = this.paper._viewBoxShift,
6016             skew = this.skew,
6017             o = this.node,
6018             split,
6019             isGrad = Str(this.attrs.fill).indexOf("-") + 1;
6020         matrix.translate(-.5, -.5);
6021         if (vbs) {
6022             matrix.scale(vbs.scale, vbs.scale, -1, -1);
6023             matrix.translate(vbs.dx, vbs.dy);
6024         }
6025         if (isGrad || this.type == "image") {
6026             skew.matrix = "1 0 0 1";
6027             skew.offset = "0 0";
6028             split = matrix.split();
6029             if ((isGrad && split.noRotation) || !split.isSimple) {
6030                 o.style.filter = matrix.toFilter();
6031                 var bb = this.getBBox(),
6032                     bbt = this.getBBox(1),
6033                     dx = bb.x - bbt.x,
6034                     dy = bb.y - bbt.y;
6035                 o.coordorigin = (dx * -zoom) + S + (dy * -zoom);
6036                 setCoords(this, 1, 1, dx, dy, 0);
6037             } else {
6038                 o.style.filter = E;
6039                 setCoords(this, split.scalex, split.scaley, split.dx, split.dy, split.rotate);
6040             }
6041         } else {
6042             o.style.filter = E;
6043             skew.matrix = Str(matrix);
6044             skew.offset = matrix.offset();
6045         }
6046         return this;
6047     };
6048     elproto.rotate = function (deg, cx, cy) {
6049         if (this.removed) {
6050             return this;
6051         }
6052         if (deg == null) {
6053             return;
6054         }
6055         deg = Str(deg).split(separator);
6056         if (deg.length - 1) {
6057             cx = toFloat(deg[1]);
6058             cy = toFloat(deg[2]);
6059         }
6060         deg = toFloat(deg[0]);
6061         (cy == null) && (cx = cy);
6062         if (cx == null || cy == null) {
6063             var bbox = this.getBBox(1);
6064             cx = bbox.x + bbox.width / 2;
6065             cy = bbox.y + bbox.height / 2;
6066         }
6067         this._.dirtyT = 1;
6068         this.transform(this._.transform.concat([["r", deg, cx, cy]]));
6069         return this;
6070     };
6071     elproto.translate = function (dx, dy) {
6072         if (this.removed) {
6073             return this;
6074         }
6075         dx = Str(dx).split(separator);
6076         if (dx.length - 1) {
6077             dy = toFloat(dx[1]);
6078         }
6079         dx = toFloat(dx[0]) || 0;
6080         dy = +dy || 0;
6081         if (this._.bbox) {
6082             this._.bbox.x += dx;
6083             this._.bbox.y += dy;
6084         }
6085         this.transform(this._.transform.concat([["t", dx, dy]]));
6086         return this;
6087     };
6088     elproto.scale = function (sx, sy, cx, cy) {
6089         if (this.removed) {
6090             return this;
6091         }
6092         sx = Str(sx).split(separator);
6093         if (sx.length - 1) {
6094             sy = toFloat(sx[1]);
6095             cx = toFloat(sx[2]);
6096             cy = toFloat(sx[3]);
6097             isNaN(cx) && (cx = null);
6098             isNaN(cy) && (cy = null);
6099         }
6100         sx = toFloat(sx[0]);
6101         (sy == null) && (sy = sx);
6102         (cy == null) && (cx = cy);
6103         if (cx == null || cy == null) {
6104             var bbox = this.getBBox(1);
6105         }
6106         cx = cx == null ? bbox.x + bbox.width / 2 : cx;
6107         cy = cy == null ? bbox.y + bbox.height / 2 : cy;
6108     
6109         this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
6110         this._.dirtyT = 1;
6111         return this;
6112     };
6113     elproto.hide = function () {
6114         !this.removed && (this.node.style.display = "none");
6115         return this;
6116     };
6117     elproto.show = function () {
6118         !this.removed && (this.node.style.display = E);
6119         return this;
6120     };
6121     elproto._getBBox = function () {
6122         if (this.removed) {
6123             return {};
6124         }
6125         if (this.type == "text") {
6126             return {
6127                 x: this.X + (this.bbx || 0) - this.W / 2,
6128                 y: this.Y - this.H,
6129                 width: this.W,
6130                 height: this.H
6131             };
6132         } else {
6133             return pathDimensions(this.attrs.path);
6134         }
6135     };
6136     elproto.remove = function () {
6137         if (this.removed) {
6138             return;
6139         }
6140         R.eve.unbind("*.*." + this.id);
6141         R._tear(this, this.paper);
6142         this.node.parentNode.removeChild(this.node);
6143         this.shape && this.shape.parentNode.removeChild(this.shape);
6144         for (var i in this) {
6145             delete this[i];
6146         }
6147         this.removed = true;
6148     };
6149     elproto.attr = function (name, value) {
6150         if (this.removed) {
6151             return this;
6152         }
6153         if (name == null) {
6154             var res = {};
6155             for (var a in this.attrs) if (this.attrs[has](a)) {
6156                 res[a] = this.attrs[a];
6157             }
6158             res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
6159             res.transform = this._.transform;
6160             return res;
6161         }
6162         if (value == null && R.is(name, "string")) {
6163             if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
6164                 return this.attrs.gradient;
6165             }
6166             var names = name.split(separator),
6167                 out = {};
6168             for (var i = 0, ii = names.length; i < ii; i++) {
6169                 name = names[i];
6170                 if (name in this.attrs) {
6171                     out[name] = this.attrs[name];
6172                 } else if (R.is(this.paper.customAttributes[name], "function")) {
6173                     out[name] = this.paper.customAttributes[name].def;
6174                 } else {
6175                     out[name] = R._availableAttrs[name];
6176                 }
6177             }
6178             return ii - 1 ? out : out[names[0]];
6179         }
6180         if (this.attrs && value == null && R.is(name, "array")) {
6181             out = {};
6182             for (i = 0, ii = name.length; i < ii; i++) {
6183                 out[name[i]] = this.attr(name[i]);
6184             }
6185             return out;
6186         }
6187         var params;
6188         if (value != null) {
6189             params = {};
6190             params[name] = value;
6191         }
6192         value == null && R.is(name, "object") && (params = name);
6193         for (var key in params) {
6194             R.eve("attr." + key + "." + this.id, this, params[key]);
6195         }
6196         if (params) {
6197             for (key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
6198                 var par = this.paper.customAttributes[key].apply(this, [][concat](params[key]));
6199                 this.attrs[key] = params[key];
6200                 for (var subkey in par) if (par[has](subkey)) {
6201                     params[subkey] = par[subkey];
6202                 }
6203             }
6204             // this.paper.canvas.style.display = "none";
6205             if (params.text && this.type == "text") {
6206                 this.textpath.string = params.text;
6207             }
6208             setFillAndStroke(this, params);
6209             // this.paper.canvas.style.display = E;
6210         }
6211         return this;
6212     };
6213     elproto.toFront = function () {
6214         !this.removed && this.node.parentNode.appendChild(this.node);
6215         this.paper && this.paper.top != this && tofront(this, this.paper);
6216         return this;
6217     };
6218     elproto.toBack = function () {
6219         if (this.removed) {
6220             return this;
6221         }
6222         if (this.node.parentNode.firstChild != this.node) {
6223             this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
6224             toback(this, this.paper);
6225         }
6226         return this;
6227     };
6228     elproto.insertAfter = function (element) {
6229         if (this.removed) {
6230             return this;
6231         }
6232         if (element.constructor == Set) {
6233             element = element[element.length - 1];
6234         }
6235         if (element.node.nextSibling) {
6236             element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
6237         } else {
6238             element.node.parentNode.appendChild(this.node);
6239         }
6240         R._insertafter(this, element, this.paper);
6241         return this;
6242     };
6243     elproto.insertBefore = function (element) {
6244         if (this.removed) {
6245             return this;
6246         }
6247         if (element.constructor == Set) {
6248             element = element[0];
6249         }
6250         element.node.parentNode.insertBefore(this.node, element.node);
6251         R._insertbefore(this, element, this.paper);
6252         return this;
6253     };
6254     elproto.blur = function (size) {
6255         var s = this.node.runtimeStyle,
6256             f = s.filter;
6257         f = f.replace(blurregexp, E);
6258         if (+size !== 0) {
6259             this.attrs.blur = size;
6260             s.filter = f + S + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
6261             s.margin = R.format("-{0}px 0 0 -{0}px", round(+size || 1.5));
6262         } else {
6263             s.filter = f;
6264             s.margin = 0;
6265             delete this.attrs.blur;
6266         }
6267     };
6268
6269     R._engine.path = function (pathString, vml) {
6270         var el = createNode("shape");
6271         el.style.cssText = cssDot;
6272         el.coordsize = zoom + S + zoom;
6273         el.coordorigin = vml.coordorigin;
6274         var p = new Element(el, vml),
6275             attr = {fill: "none", stroke: "#000"};
6276         pathString && (attr.path = pathString);
6277         p.type = "path";
6278         p.path = [];
6279         p.Path = E;
6280         setFillAndStroke(p, attr);
6281         vml.canvas.appendChild(el);
6282         var skew = createNode("skew");
6283         skew.on = true;
6284         el.appendChild(skew);
6285         p.skew = skew;
6286         p.transform(E);
6287         return p;
6288     };
6289     R._engine.rect = function (vml, x, y, w, h, r) {
6290         var path = R._rectPath(x, y, w, h, r),
6291             res = vml.path(path),
6292             a = res.attrs;
6293         res.X = a.x = x;
6294         res.Y = a.y = y;
6295         res.W = a.width = w;
6296         res.H = a.height = h;
6297         a.r = r;
6298         a.path = path;
6299         res.type = "rect";
6300         return res;
6301     };
6302     R._engine.ellipse = function (vml, x, y, rx, ry) {
6303         var res = vml.path(),
6304             a = res.attrs;
6305         res.X = x - rx;
6306         res.Y = y - ry;
6307         res.W = rx * 2;
6308         res.H = ry * 2;
6309         res.type = "ellipse";
6310         setFillAndStroke(res, {
6311             cx: x,
6312             cy: y,
6313             rx: rx,
6314             ry: ry
6315         });
6316         return res;
6317     };
6318     R._engine.circle = function (vml, x, y, r) {
6319         var res = vml.path(),
6320             a = res.attrs;
6321         res.X = x - r;
6322         res.Y = y - r;
6323         res.W = res.H = r * 2;
6324         res.type = "circle";
6325         setFillAndStroke(res, {
6326             cx: x,
6327             cy: y,
6328             r: r
6329         });
6330         return res;
6331     };
6332     R._engine.image = function (vml, src, x, y, w, h) {
6333         var path = R._rectPath(x, y, w, h),
6334             res = vml.path(path).attr({stroke: "none"}),
6335             a = res.attrs,
6336             node = res.node,
6337             fill = node.getElementsByTagName(fillString)[0];
6338         a.src = src;
6339         res.X = a.x = x;
6340         res.Y = a.y = y;
6341         res.W = a.width = w;
6342         res.H = a.height = h;
6343         a.path = path;
6344         res.type = "image";
6345         fill.parentNode == node && node.removeChild(fill);
6346         fill.rotate = true;
6347         fill.src = src;
6348         fill.type = "tile";
6349         res._.fillpos = [x, y];
6350         res._.fillsize = [w, h];
6351         node.appendChild(fill);
6352         setCoords(res, 1, 1, 0, 0, 0);
6353         return res;
6354     };
6355     R._engine.text = function (vml, x, y, text) {
6356         var el = createNode("shape"),
6357             path = createNode("path"),
6358             o = createNode("textpath");
6359         x = x || 0;
6360         y = y || 0;
6361         text = text || "";
6362         path.v = R.format("m{0},{1}l{2},{1}", round(x * zoom), round(y * zoom), round(x * zoom) + 1);
6363         path.textpathok = true;
6364         o.string = Str(text);
6365         o.on = true;
6366         el.style.cssText = "position:absolute;left:0;top:0;width:1px;height:1px";
6367         el.coordsize = zoom + S + zoom;
6368         el.coordorigin = "0 0";
6369         var p = new Element(el, vml),
6370             attr = {fill: "#000", stroke: "none", font: availableAttrs.font, text: text};
6371         p.shape = el;
6372         p.path = path;
6373         p.textpath = o;
6374         p.type = "text";
6375         p.attrs.text = Str(text);
6376         p.attrs.x = x;
6377         p.attrs.y = y;
6378         p.attrs.w = 1;
6379         p.attrs.h = 1;
6380         setFillAndStroke(p, attr);
6381         el.appendChild(o);
6382         el.appendChild(path);
6383         vml.canvas.appendChild(el);
6384         var skew = createNode("skew");
6385         skew.on = true;
6386         el.appendChild(skew);
6387         p.skew = skew;
6388         p.transform(E);
6389         return p;
6390     };
6391     R._engine.setSize = function (width, height) {
6392         var cs = this.canvas.style;
6393         this.width = width;
6394         this.height = height;
6395         width == +width && (width += "px");
6396         height == +height && (height += "px");
6397         cs.width = width;
6398         cs.height = height;
6399         cs.clip = "rect(0 " + width + " " + height + " 0)";
6400         if (this._viewBox) {
6401             setViewBox.apply(this, this._viewBox);
6402         }
6403         return this;
6404     };
6405     R._engine.setViewBox = function (x, y, w, h, fit) {
6406         R.eve("setViewBox", this, this._viewBox, [x, y, w, h, fit]);
6407         var width = this.width,
6408             height = this.height,
6409             size = 1 / mmax(w / width, h / height),
6410             H, W;
6411         if (fit) {
6412             H = height / h;
6413             W = width / w;
6414             if (w * H < width) {
6415                 x -= (width - w * H) / 2 / H;
6416             }
6417             if (h * W < height) {
6418                 y -= (height - h * W) / 2 / W;
6419             }
6420         }
6421         this._viewBox = [x, y, w, h, !!fit];
6422         this._viewBoxShift = {
6423             dx: -x,
6424             dy: -y,
6425             scale: size
6426         };
6427         this.forEach(function (el) {
6428             el.transform("...");
6429         });
6430         return this;
6431     };
6432     var createNode,
6433         initWin = function (win) {
6434             var doc = win.document;
6435             doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
6436             try {
6437                 !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
6438                 createNode = function (tagName) {
6439                     return doc.createElement('<rvml:' + tagName + ' class="rvml">');
6440                 };
6441             } catch (e) {
6442                 createNode = function (tagName) {
6443                     return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
6444                 };
6445             }
6446         };
6447     initWin(R._g.win);
6448     R._engine.create = function () {
6449         var con = R._getContainer.apply(0, arguments),
6450             container = con.container,
6451             height = con.height,
6452             s,
6453             width = con.width,
6454             x = con.x,
6455             y = con.y;
6456         if (!container) {
6457             throw new Error("VML container not found.");
6458         }
6459         var res = new R._Paper,
6460             c = res.canvas = R._g.doc.createElement("div"),
6461             cs = c.style;
6462         x = x || 0;
6463         y = y || 0;
6464         width = width || 512;
6465         height = height || 342;
6466         res.width = width;
6467         res.height = height;
6468         width == +width && (width += "px");
6469         height == +height && (height += "px");
6470         res.coordsize = zoom * 1e3 + S + zoom * 1e3;
6471         res.coordorigin = "0 0";
6472         res.span = R._g.doc.createElement("span");
6473         res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;";
6474         c.appendChild(res.span);
6475         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);
6476         if (container == 1) {
6477             R._g.doc.body.appendChild(c);
6478             cs.left = x + "px";
6479             cs.top = y + "px";
6480             cs.position = "absolute";
6481         } else {
6482             if (container.firstChild) {
6483                 container.insertBefore(c, container.firstChild);
6484             } else {
6485                 container.appendChild(c);
6486             }
6487         }
6488         // plugins.call(res, res, R.fn);
6489         res.renderfix = function () {};
6490         return res;
6491     };
6492     R.prototype.clear = function () {
6493         R.eve("clear", this);
6494         this.canvas.innerHTML = E;
6495         this.span = R._g.doc.createElement("span");
6496         this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
6497         this.canvas.appendChild(this.span);
6498         this.bottom = this.top = null;
6499     };
6500     R.prototype.remove = function () {
6501         R.eve("remove", this);
6502         this.canvas.parentNode.removeChild(this.canvas);
6503         for (var i in this) {
6504             this[i] = removed(i);
6505         }
6506         return true;
6507     };
6508 }(window.Raphael);