diff js-lib/raphael.js @ 83:e0dadfad3dc4 laserkard

going to try a pure raphael solution
author Robert McIntyre <rlm@mit.edu>
date Sun, 25 Jul 2010 21:46:00 -0400
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js-lib/raphael.js	Sun Jul 25 21:46:00 2010 -0400
     1.3 @@ -0,0 +1,3515 @@
     1.4 +/*!
     1.5 + * Raphael 1.4.7 - JavaScript Vector Library
     1.6 + *
     1.7 + * Copyright (c) 2010 Dmitry Baranovskiy (http://raphaeljs.com)
     1.8 + * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
     1.9 + */
    1.10 + 
    1.11 +Raphael = (function () {
    1.12 +    function R() {
    1.13 +        if (R.is(arguments[0], array)) {
    1.14 +            var a = arguments[0],
    1.15 +                cnv = create[apply](R, a.splice(0, 3 + R.is(a[0], nu))),
    1.16 +                res = cnv.set();
    1.17 +            for (var i = 0, ii = a[length]; i < ii; i++) {
    1.18 +                var j = a[i] || {};
    1.19 +                elements.test(j.type) && res[push](cnv[j.type]().attr(j));
    1.20 +            }
    1.21 +            return res;
    1.22 +        }
    1.23 +        return create[apply](R, arguments);
    1.24 +    }
    1.25 +    R.version = "1.4.7";
    1.26 +    var separator = /[, ]+/,
    1.27 +        elements = /^(circle|rect|path|ellipse|text|image)$/,
    1.28 +        proto = "prototype",
    1.29 +        has = "hasOwnProperty",
    1.30 +        doc = document,
    1.31 +        win = window,
    1.32 +        oldRaphael = {
    1.33 +            was: Object[proto][has].call(win, "Raphael"),
    1.34 +            is: win.Raphael
    1.35 +        },
    1.36 +        Paper = function () {},
    1.37 +        appendChild = "appendChild",
    1.38 +        apply = "apply",
    1.39 +        concat = "concat",
    1.40 +        supportsTouch = "createTouch" in doc,
    1.41 +        E = "",
    1.42 +        S = " ",
    1.43 +        Str = String,
    1.44 +        split = "split",
    1.45 +        events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend orientationchange touchcancel gesturestart gesturechange gestureend"[split](S),
    1.46 +        touchMap = {
    1.47 +            mousedown: "touchstart",
    1.48 +            mousemove: "touchmove",
    1.49 +            mouseup: "touchend"
    1.50 +        },
    1.51 +        join = "join",
    1.52 +        length = "length",
    1.53 +        lowerCase = String[proto].toLowerCase,
    1.54 +        math = Math,
    1.55 +        mmax = math.max,
    1.56 +        mmin = math.min,
    1.57 +        nu = "number",
    1.58 +        string = "string",
    1.59 +        array = "array",
    1.60 +        toString = "toString",
    1.61 +        fillString = "fill",
    1.62 +        objectToString = Object[proto][toString],
    1.63 +        paper = {},
    1.64 +        pow = math.pow,
    1.65 +        push = "push",
    1.66 +        rg = /^(?=[\da-f]$)/,
    1.67 +        ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
    1.68 +        colourRegExp = /^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+(?:\s*,\s*[\d\.]+)?)\s*\)|rgba?\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%(?:\s*,\s*[\d\.]+%)?)\s*\)|hsb\(\s*([\d\.]+(?:deg|\xb0)?\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hsb\(\s*([\d\.]+(?:deg|\xb0|%)\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\)|hsl\(\s*([\d\.]+(?:deg|\xb0)?\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hsl\(\s*([\d\.]+(?:deg|\xb0|%)\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i,
    1.69 +        round = math.round,
    1.70 +        setAttribute = "setAttribute",
    1.71 +        toFloat = parseFloat,
    1.72 +        toInt = parseInt,
    1.73 +        ms = " progid:DXImageTransform.Microsoft",
    1.74 +        upperCase = String[proto].toUpperCase,
    1.75 +        availableAttrs = {blur: 0, "clip-rect": "0 0 1e9 1e9", cursor: "default", cx: 0, cy: 0, fill: "#fff", "fill-opacity": 1, font: '10px "Arial"', "font-family": '"Arial"', "font-size": "10", "font-style": "normal", "font-weight": 400, gradient: 0, height: 0, href: "http://raphaeljs.com/", opacity: 1, path: "M0,0", r: 0, rotation: 0, rx: 0, ry: 0, scale: "1 1", src: "", stroke: "#000", "stroke-dasharray": "", "stroke-linecap": "butt", "stroke-linejoin": "butt", "stroke-miterlimit": 0, "stroke-opacity": 1, "stroke-width": 1, target: "_blank", "text-anchor": "middle", title: "Raphael", translation: "0 0", width: 0, x: 0, y: 0},
    1.76 +        availableAnimAttrs = {along: "along", blur: nu, "clip-rect": "csv", cx: nu, cy: nu, fill: "colour", "fill-opacity": nu, "font-size": nu, height: nu, opacity: nu, path: "path", r: nu, rotation: "csv", rx: nu, ry: nu, scale: "csv", stroke: "colour", "stroke-opacity": nu, "stroke-width": nu, translation: "csv", width: nu, x: nu, y: nu},
    1.77 +        rp = "replace";
    1.78 +    R.type = (win.SVGAngle || doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
    1.79 +    if (R.type == "VML") {
    1.80 +        var d = doc.createElement("div"),
    1.81 +            b;
    1.82 +        d.innerHTML = '<v:shape adj="1"/>';
    1.83 +        b = d.firstChild;
    1.84 +        b.style.behavior = "url(#default#VML)";
    1.85 +        if (!(b && typeof b.adj == "object")) {
    1.86 +            return R.type = null;
    1.87 +        }
    1.88 +        d = null;
    1.89 +    }
    1.90 +    R.svg = !(R.vml = R.type == "VML");
    1.91 +    Paper[proto] = R[proto];
    1.92 +    R._id = 0;
    1.93 +    R._oid = 0;
    1.94 +    R.fn = {};
    1.95 +    R.is = function (o, type) {
    1.96 +        type = lowerCase.call(type);
    1.97 +        return  (type == "object" && o === Object(o)) ||
    1.98 +                (type == "undefined" && typeof o == type) ||
    1.99 +                (type == "null" && o == null) ||
   1.100 +                (type == "array" && Array.isArray && Array.isArray(o)) ||
   1.101 +                lowerCase.call(objectToString.call(o).slice(8, -1)) == type;
   1.102 +    };
   1.103 +
   1.104 +    R.setWindow = function (newwin) {
   1.105 +        win = newwin;
   1.106 +        doc = win.document;
   1.107 +    };
   1.108 +    // colour utilities
   1.109 +    var toHex = function (color) {
   1.110 +        if (R.vml) {
   1.111 +            // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
   1.112 +            var trim = /^\s+|\s+$/g;
   1.113 +            toHex = cacher(function (color) {
   1.114 +                var bod;
   1.115 +                color = Str(color)[rp](trim, E);
   1.116 +                try {
   1.117 +                    var docum = new win.ActiveXObject("htmlfile");
   1.118 +                    docum.write("<body>");
   1.119 +                    docum.close();
   1.120 +                    bod = docum.body;
   1.121 +                } catch(e) {
   1.122 +                    bod = win.createPopup().document.body;
   1.123 +                }
   1.124 +                var range = bod.createTextRange();
   1.125 +                try {
   1.126 +                    bod.style.color = color;
   1.127 +                    var value = range.queryCommandValue("ForeColor");
   1.128 +                    value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
   1.129 +                    return "#" + ("000000" + value[toString](16)).slice(-6);
   1.130 +                } catch(e) {
   1.131 +                    return "none";
   1.132 +                }
   1.133 +            });
   1.134 +        } else {
   1.135 +            var i = doc.createElement("i");
   1.136 +            i.title = "Rapha\xebl Colour Picker";
   1.137 +            i.style.display = "none";
   1.138 +            doc.body[appendChild](i);
   1.139 +            toHex = cacher(function (color) {
   1.140 +                i.style.color = color;
   1.141 +                return doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
   1.142 +            });
   1.143 +        }
   1.144 +        return toHex(color);
   1.145 +    },
   1.146 +    hsbtoString = function () {
   1.147 +        return "hsb(" + [this.h, this.s, this.b] + ")";
   1.148 +    },
   1.149 +    hsltoString = function () {
   1.150 +        return "hsl(" + [this.h, this.s, this.l] + ")";
   1.151 +    },
   1.152 +    rgbtoString = function () {
   1.153 +        return this.hex;
   1.154 +    };
   1.155 +    R.hsb2rgb = function (h, s, b) {
   1.156 +        if (R.is(h, "object") && "h" in h && "s" in h && "b" in h) {
   1.157 +            b = h.b;
   1.158 +            s = h.s;
   1.159 +            h = h.h;
   1.160 +        }
   1.161 +        return R.hsl2rgb(h, s, b / 2);
   1.162 +    };
   1.163 +    R.hsl2rgb = function (h, s, l) {
   1.164 +        if (R.is(h, "object") && "h" in h && "s" in h && "l" in h) {
   1.165 +            l = h.l;
   1.166 +            s = h.s;
   1.167 +            h = h.h;
   1.168 +        }
   1.169 +        if (h > 1 || s > 1 || l > 1) {
   1.170 +            h /= 255;
   1.171 +            s /= 255;
   1.172 +            l /= 255;
   1.173 +        }
   1.174 +        var rgb = {},
   1.175 +            channels = ["r", "g", "b"],
   1.176 +            t2, t1, t3, r, g, b;
   1.177 +        if (!s) {
   1.178 +            rgb = {
   1.179 +                r: l,
   1.180 +                g: l,
   1.181 +                b: l
   1.182 +            };
   1.183 +        } else {
   1.184 +            if (l < .5) {
   1.185 +                t2 = l * (1 + s);
   1.186 +            } else {
   1.187 +                t2 = l + s - l * s;
   1.188 +            }
   1.189 +            t1 = 2 * l - t2;
   1.190 +            for (var i = 0, ii = channels.length; i < ii; i++) {
   1.191 +                t3 = h + 1 / 3 * -(i - 1);
   1.192 +                t3 < 0 && t3++;
   1.193 +                t3 > 1 && t3--;
   1.194 +                if (t3 * 6 < 1) {
   1.195 +                    rgb[channels[i]] = t1 + (t2 - t1) * 6 * t3;
   1.196 +                } else if (t3 * 2 < 1) {
   1.197 +                    rgb[channels[i]] = t2;
   1.198 +                } else if (t3 * 3 < 2) {
   1.199 +                    rgb[channels[i]] = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
   1.200 +                } else {
   1.201 +                    rgb[channels[i]] = t1;
   1.202 +                }
   1.203 +            }
   1.204 +        }
   1.205 +        rgb.r *= 255;
   1.206 +        rgb.g *= 255;
   1.207 +        rgb.b *= 255;
   1.208 +        r = (~~rgb.r)[toString](16);
   1.209 +        g = (~~rgb.g)[toString](16);
   1.210 +        b = (~~rgb.b)[toString](16);
   1.211 +        r = r[rp](rg, "0");
   1.212 +        g = g[rp](rg, "0");
   1.213 +        b = b[rp](rg, "0");
   1.214 +        rgb.hex = "#" + r + g + b;
   1.215 +        rgb.toString = rgbtoString;
   1.216 +        return rgb;
   1.217 +    };
   1.218 +    R.rgb2hsb = function (red, green, blue) {
   1.219 +        if (green == null && R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
   1.220 +            blue = red.b;
   1.221 +            green = red.g;
   1.222 +            red = red.r;
   1.223 +        }
   1.224 +        if (green == null && R.is(red, string)) {
   1.225 +            var clr = R.getRGB(red);
   1.226 +            red = clr.r;
   1.227 +            green = clr.g;
   1.228 +            blue = clr.b;
   1.229 +        }
   1.230 +        if (red > 1 || green > 1 || blue > 1) {
   1.231 +            red /= 255;
   1.232 +            green /= 255;
   1.233 +            blue /= 255;
   1.234 +        }
   1.235 +        var max = mmax(red, green, blue),
   1.236 +            min = mmin(red, green, blue),
   1.237 +            hue,
   1.238 +            saturation,
   1.239 +            brightness = max;
   1.240 +        if (min == max) {
   1.241 +            return {h: 0, s: 0, b: max, toString: hsbtoString};
   1.242 +        } else {
   1.243 +            var delta = (max - min);
   1.244 +            saturation = delta / max;
   1.245 +            if (red == max) {
   1.246 +                hue = (green - blue) / delta;
   1.247 +            } else if (green == max) {
   1.248 +                hue = 2 + ((blue - red) / delta);
   1.249 +            } else {
   1.250 +                hue = 4 + ((red - green) / delta);
   1.251 +            }
   1.252 +            hue /= 6;
   1.253 +            hue < 0 && hue++;
   1.254 +            hue > 1 && hue--;
   1.255 +        }
   1.256 +        return {h: hue, s: saturation, b: brightness, toString: hsbtoString};
   1.257 +    };
   1.258 +    R.rgb2hsl = function (red, green, blue) {
   1.259 +        if (green == null && R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
   1.260 +            blue = red.b;
   1.261 +            green = red.g;
   1.262 +            red = red.r;
   1.263 +        }
   1.264 +        if (green == null && R.is(red, string)) {
   1.265 +            var clr = R.getRGB(red);
   1.266 +            red = clr.r;
   1.267 +            green = clr.g;
   1.268 +            blue = clr.b;
   1.269 +        }
   1.270 +        if (red > 1 || green > 1 || blue > 1) {
   1.271 +            red /= 255;
   1.272 +            green /= 255;
   1.273 +            blue /= 255;
   1.274 +        }
   1.275 +        var max = mmax(red, green, blue),
   1.276 +            min = mmin(red, green, blue),
   1.277 +            h,
   1.278 +            s,
   1.279 +            l = (max + min) / 2,
   1.280 +            hsl;
   1.281 +        if (min == max) {
   1.282 +            hsl =  {h: 0, s: 0, l: l};
   1.283 +        } else {
   1.284 +            var delta = max - min;
   1.285 +            s = l < .5 ? delta / (max + min) : delta / (2 - max - min);
   1.286 +            if (red == max) {
   1.287 +                h = (green - blue) / delta;
   1.288 +            } else if (green == max) {
   1.289 +                h = 2 + (blue - red) / delta;
   1.290 +            } else {
   1.291 +                h = 4 + (red - green) / delta;
   1.292 +            }
   1.293 +            h /= 6;
   1.294 +            h < 0 && h++;
   1.295 +            h > 1 && h--;
   1.296 +            hsl = {h: h, s: s, l: l};
   1.297 +        }
   1.298 +        hsl.toString = hsltoString;
   1.299 +        return hsl;
   1.300 +    };
   1.301 +    var p2s = /,?([achlmqrstvxz]),?/gi,
   1.302 +        commaSpaces = /\s*,\s*/,
   1.303 +        hsrg = {hs: 1, rg: 1};
   1.304 +    R._path2string = function () {
   1.305 +        return this.join(",")[rp](p2s, "$1");
   1.306 +    };
   1.307 +    function cacher(f, scope, postprocessor) {
   1.308 +        function newf() {
   1.309 +            var arg = Array[proto].slice.call(arguments, 0),
   1.310 +                args = arg[join]("\u25ba"),
   1.311 +                cache = newf.cache = newf.cache || {},
   1.312 +                count = newf.count = newf.count || [];
   1.313 +            if (cache[has](args)) {
   1.314 +                return postprocessor ? postprocessor(cache[args]) : cache[args];
   1.315 +            }
   1.316 +            count[length] >= 1e3 && delete cache[count.shift()];
   1.317 +            count[push](args);
   1.318 +            cache[args] = f[apply](scope, arg);
   1.319 +            return postprocessor ? postprocessor(cache[args]) : cache[args];
   1.320 +        }
   1.321 +        return newf;
   1.322 +    }
   1.323 + 
   1.324 +    R.getRGB = cacher(function (colour) {
   1.325 +        if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) {
   1.326 +            return {r: -1, g: -1, b: -1, hex: "none", error: 1};
   1.327 +        }
   1.328 +        if (colour == "none") {
   1.329 +            return {r: -1, g: -1, b: -1, hex: "none"};
   1.330 +        }
   1.331 +        !(hsrg[has](colour.substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
   1.332 +        var res,
   1.333 +            red,
   1.334 +            green,
   1.335 +            blue,
   1.336 +            opacity,
   1.337 +            t,
   1.338 +            rgb = colour.match(colourRegExp);
   1.339 +        if (rgb) {
   1.340 +            if (rgb[2]) {
   1.341 +                blue = toInt(rgb[2].substring(5), 16);
   1.342 +                green = toInt(rgb[2].substring(3, 5), 16);
   1.343 +                red = toInt(rgb[2].substring(1, 3), 16);
   1.344 +            }
   1.345 +            if (rgb[3]) {
   1.346 +                blue = toInt((t = rgb[3].charAt(3)) + t, 16);
   1.347 +                green = toInt((t = rgb[3].charAt(2)) + t, 16);
   1.348 +                red = toInt((t = rgb[3].charAt(1)) + t, 16);
   1.349 +            }
   1.350 +            if (rgb[4]) {
   1.351 +                rgb = rgb[4][split](commaSpaces);
   1.352 +                red = toFloat(rgb[0]);
   1.353 +                green = toFloat(rgb[1]);
   1.354 +                blue = toFloat(rgb[2]);
   1.355 +                opacity = toFloat(rgb[3]);
   1.356 +            }
   1.357 +            if (rgb[5]) {
   1.358 +                rgb = rgb[5][split](commaSpaces);
   1.359 +                red = toFloat(rgb[0]) * 2.55;
   1.360 +                green = toFloat(rgb[1]) * 2.55;
   1.361 +                blue = toFloat(rgb[2]) * 2.55;
   1.362 +                opacity = toFloat(rgb[3]);
   1.363 +            }
   1.364 +            if (rgb[6]) {
   1.365 +                rgb = rgb[6][split](commaSpaces);
   1.366 +                red = toFloat(rgb[0]);
   1.367 +                green = toFloat(rgb[1]);
   1.368 +                blue = toFloat(rgb[2]);
   1.369 +                (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360);
   1.370 +                return R.hsb2rgb(red, green, blue);
   1.371 +            }
   1.372 +            if (rgb[7]) {
   1.373 +                rgb = rgb[7][split](commaSpaces);
   1.374 +                red = toFloat(rgb[0]) * 2.55;
   1.375 +                green = toFloat(rgb[1]) * 2.55;
   1.376 +                blue = toFloat(rgb[2]) * 2.55;
   1.377 +                (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360 * 2.55);
   1.378 +                return R.hsb2rgb(red, green, blue);
   1.379 +            }
   1.380 +            if (rgb[8]) {
   1.381 +                rgb = rgb[8][split](commaSpaces);
   1.382 +                red = toFloat(rgb[0]);
   1.383 +                green = toFloat(rgb[1]);
   1.384 +                blue = toFloat(rgb[2]);
   1.385 +                (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360);
   1.386 +                return R.hsl2rgb(red, green, blue);
   1.387 +            }
   1.388 +            if (rgb[9]) {
   1.389 +                rgb = rgb[9][split](commaSpaces);
   1.390 +                red = toFloat(rgb[0]) * 2.55;
   1.391 +                green = toFloat(rgb[1]) * 2.55;
   1.392 +                blue = toFloat(rgb[2]) * 2.55;
   1.393 +                (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360 * 2.55);
   1.394 +                return R.hsl2rgb(red, green, blue);
   1.395 +            }
   1.396 +            rgb = {r: red, g: green, b: blue};
   1.397 +            var r = (~~red)[toString](16),
   1.398 +                g = (~~green)[toString](16),
   1.399 +                b = (~~blue)[toString](16);
   1.400 +            r = r[rp](rg, "0");
   1.401 +            g = g[rp](rg, "0");
   1.402 +            b = b[rp](rg, "0");
   1.403 +            rgb.hex = "#" + r + g + b;
   1.404 +            isFinite(toFloat(opacity)) && (rgb.o = opacity);
   1.405 +            return rgb;
   1.406 +        }
   1.407 +        return {r: -1, g: -1, b: -1, hex: "none", error: 1};
   1.408 +    }, R);
   1.409 +    R.getColor = function (value) {
   1.410 +        var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
   1.411 +            rgb = this.hsb2rgb(start.h, start.s, start.b);
   1.412 +        start.h += .075;
   1.413 +        if (start.h > 1) {
   1.414 +            start.h = 0;
   1.415 +            start.s -= .2;
   1.416 +            start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
   1.417 +        }
   1.418 +        return rgb.hex;
   1.419 +    };
   1.420 +    R.getColor.reset = function () {
   1.421 +        delete this.start;
   1.422 +    };
   1.423 +    // path utilities
   1.424 +    var pathCommand = /([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig,
   1.425 +        pathValues = /(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig;
   1.426 +    R.parsePathString = cacher(function (pathString) {
   1.427 +        if (!pathString) {
   1.428 +            return null;
   1.429 +        }
   1.430 +        var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
   1.431 +            data = [];
   1.432 +        if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
   1.433 +            data = pathClone(pathString);
   1.434 +        }
   1.435 +        if (!data[length]) {
   1.436 +            Str(pathString)[rp](pathCommand, function (a, b, c) {
   1.437 +                var params = [],
   1.438 +                    name = lowerCase.call(b);
   1.439 +                c[rp](pathValues, function (a, b) {
   1.440 +                    b && params[push](+b);
   1.441 +                });
   1.442 +                if (name == "m" && params[length] > 2) {
   1.443 +                    data[push]([b][concat](params.splice(0, 2)));
   1.444 +                    name = "l";
   1.445 +                    b = b == "m" ? "l" : "L";
   1.446 +                }
   1.447 +                while (params[length] >= paramCounts[name]) {
   1.448 +                    data[push]([b][concat](params.splice(0, paramCounts[name])));
   1.449 +                    if (!paramCounts[name]) {
   1.450 +                        break;
   1.451 +                    }
   1.452 +                }
   1.453 +            });
   1.454 +        }
   1.455 +        data[toString] = R._path2string;
   1.456 +        return data;
   1.457 +    });
   1.458 +    R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
   1.459 +        var t1 = 1 - t,
   1.460 +            x = pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
   1.461 +            y = pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y,
   1.462 +            mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x),
   1.463 +            my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y),
   1.464 +            nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x),
   1.465 +            ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y),
   1.466 +            ax = (1 - t) * p1x + t * c1x,
   1.467 +            ay = (1 - t) * p1y + t * c1y,
   1.468 +            cx = (1 - t) * c2x + t * p2x,
   1.469 +            cy = (1 - t) * c2y + t * p2y,
   1.470 +            alpha = (90 - math.atan((mx - nx) / (my - ny)) * 180 / math.PI);
   1.471 +        (mx > nx || my < ny) && (alpha += 180);
   1.472 +        return {x: x, y: y, m: {x: mx, y: my}, n: {x: nx, y: ny}, start: {x: ax, y: ay}, end: {x: cx, y: cy}, alpha: alpha};
   1.473 +    };
   1.474 +    var pathDimensions = cacher(function (path) {
   1.475 +        if (!path) {
   1.476 +            return {x: 0, y: 0, width: 0, height: 0};
   1.477 +        }
   1.478 +        path = path2curve(path);
   1.479 +        var x = 0, 
   1.480 +            y = 0,
   1.481 +            X = [],
   1.482 +            Y = [],
   1.483 +            p;
   1.484 +        for (var i = 0, ii = path[length]; i < ii; i++) {
   1.485 +            p = path[i];
   1.486 +            if (p[0] == "M") {
   1.487 +                x = p[1];
   1.488 +                y = p[2];
   1.489 +                X[push](x);
   1.490 +                Y[push](y);
   1.491 +            } else {
   1.492 +                var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
   1.493 +                X = X[concat](dim.min.x, dim.max.x);
   1.494 +                Y = Y[concat](dim.min.y, dim.max.y);
   1.495 +                x = p[5];
   1.496 +                y = p[6];
   1.497 +            }
   1.498 +        }
   1.499 +        var xmin = mmin[apply](0, X),
   1.500 +            ymin = mmin[apply](0, Y);
   1.501 +        return {
   1.502 +            x: xmin,
   1.503 +            y: ymin,
   1.504 +            width: mmax[apply](0, X) - xmin,
   1.505 +            height: mmax[apply](0, Y) - ymin
   1.506 +        };
   1.507 +    }),
   1.508 +        pathClone = function (pathArray) {
   1.509 +            var res = [];
   1.510 +            if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
   1.511 +                pathArray = R.parsePathString(pathArray);
   1.512 +            }
   1.513 +            for (var i = 0, ii = pathArray[length]; i < ii; i++) {
   1.514 +                res[i] = [];
   1.515 +                for (var j = 0, jj = pathArray[i][length]; j < jj; j++) {
   1.516 +                    res[i][j] = pathArray[i][j];
   1.517 +                }
   1.518 +            }
   1.519 +            res[toString] = R._path2string;
   1.520 +            return res;
   1.521 +        },
   1.522 +        pathToRelative = cacher(function (pathArray) {
   1.523 +            if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
   1.524 +                pathArray = R.parsePathString(pathArray);
   1.525 +            }
   1.526 +            var res = [],
   1.527 +                x = 0,
   1.528 +                y = 0,
   1.529 +                mx = 0,
   1.530 +                my = 0,
   1.531 +                start = 0;
   1.532 +            if (pathArray[0][0] == "M") {
   1.533 +                x = pathArray[0][1];
   1.534 +                y = pathArray[0][2];
   1.535 +                mx = x;
   1.536 +                my = y;
   1.537 +                start++;
   1.538 +                res[push](["M", x, y]);
   1.539 +            }
   1.540 +            for (var i = start, ii = pathArray[length]; i < ii; i++) {
   1.541 +                var r = res[i] = [],
   1.542 +                    pa = pathArray[i];
   1.543 +                if (pa[0] != lowerCase.call(pa[0])) {
   1.544 +                    r[0] = lowerCase.call(pa[0]);
   1.545 +                    switch (r[0]) {
   1.546 +                        case "a":
   1.547 +                            r[1] = pa[1];
   1.548 +                            r[2] = pa[2];
   1.549 +                            r[3] = pa[3];
   1.550 +                            r[4] = pa[4];
   1.551 +                            r[5] = pa[5];
   1.552 +                            r[6] = +(pa[6] - x).toFixed(3);
   1.553 +                            r[7] = +(pa[7] - y).toFixed(3);
   1.554 +                            break;
   1.555 +                        case "v":
   1.556 +                            r[1] = +(pa[1] - y).toFixed(3);
   1.557 +                            break;
   1.558 +                        case "m":
   1.559 +                            mx = pa[1];
   1.560 +                            my = pa[2];
   1.561 +                        default:
   1.562 +                            for (var j = 1, jj = pa[length]; j < jj; j++) {
   1.563 +                                r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
   1.564 +                            }
   1.565 +                    }
   1.566 +                } else {
   1.567 +                    r = res[i] = [];
   1.568 +                    if (pa[0] == "m") {
   1.569 +                        mx = pa[1] + x;
   1.570 +                        my = pa[2] + y;
   1.571 +                    }
   1.572 +                    for (var k = 0, kk = pa[length]; k < kk; k++) {
   1.573 +                        res[i][k] = pa[k];
   1.574 +                    }
   1.575 +                }
   1.576 +                var len = res[i][length];
   1.577 +                switch (res[i][0]) {
   1.578 +                    case "z":
   1.579 +                        x = mx;
   1.580 +                        y = my;
   1.581 +                        break;
   1.582 +                    case "h":
   1.583 +                        x += +res[i][len - 1];
   1.584 +                        break;
   1.585 +                    case "v":
   1.586 +                        y += +res[i][len - 1];
   1.587 +                        break;
   1.588 +                    default:
   1.589 +                        x += +res[i][len - 2];
   1.590 +                        y += +res[i][len - 1];
   1.591 +                }
   1.592 +            }
   1.593 +            res[toString] = R._path2string;
   1.594 +            return res;
   1.595 +        }, 0, pathClone),
   1.596 +        pathToAbsolute = cacher(function (pathArray) {
   1.597 +            if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
   1.598 +                pathArray = R.parsePathString(pathArray);
   1.599 +            }
   1.600 +            var res = [],
   1.601 +                x = 0,
   1.602 +                y = 0,
   1.603 +                mx = 0,
   1.604 +                my = 0,
   1.605 +                start = 0;
   1.606 +            if (pathArray[0][0] == "M") {
   1.607 +                x = +pathArray[0][1];
   1.608 +                y = +pathArray[0][2];
   1.609 +                mx = x;
   1.610 +                my = y;
   1.611 +                start++;
   1.612 +                res[0] = ["M", x, y];
   1.613 +            }
   1.614 +            for (var i = start, ii = pathArray[length]; i < ii; i++) {
   1.615 +                var r = res[i] = [],
   1.616 +                    pa = pathArray[i];
   1.617 +                if (pa[0] != upperCase.call(pa[0])) {
   1.618 +                    r[0] = upperCase.call(pa[0]);
   1.619 +                    switch (r[0]) {
   1.620 +                        case "A":
   1.621 +                            r[1] = pa[1];
   1.622 +                            r[2] = pa[2];
   1.623 +                            r[3] = pa[3];
   1.624 +                            r[4] = pa[4];
   1.625 +                            r[5] = pa[5];
   1.626 +                            r[6] = +(pa[6] + x);
   1.627 +                            r[7] = +(pa[7] + y);
   1.628 +                            break;
   1.629 +                        case "V":
   1.630 +                            r[1] = +pa[1] + y;
   1.631 +                            break;
   1.632 +                        case "H":
   1.633 +                            r[1] = +pa[1] + x;
   1.634 +                            break;
   1.635 +                        case "M":
   1.636 +                            mx = +pa[1] + x;
   1.637 +                            my = +pa[2] + y;
   1.638 +                        default:
   1.639 +                            for (var j = 1, jj = pa[length]; j < jj; j++) {
   1.640 +                                r[j] = +pa[j] + ((j % 2) ? x : y);
   1.641 +                            }
   1.642 +                    }
   1.643 +                } else {
   1.644 +                    for (var k = 0, kk = pa[length]; k < kk; k++) {
   1.645 +                        res[i][k] = pa[k];
   1.646 +                    }
   1.647 +                }
   1.648 +                switch (r[0]) {
   1.649 +                    case "Z":
   1.650 +                        x = mx;
   1.651 +                        y = my;
   1.652 +                        break;
   1.653 +                    case "H":
   1.654 +                        x = r[1];
   1.655 +                        break;
   1.656 +                    case "V":
   1.657 +                        y = r[1];
   1.658 +                        break;
   1.659 +                    case "M":
   1.660 +                        mx = res[i][res[i][length] - 2];
   1.661 +                        my = res[i][res[i][length] - 1];
   1.662 +                    default:
   1.663 +                        x = res[i][res[i][length] - 2];
   1.664 +                        y = res[i][res[i][length] - 1];
   1.665 +                }
   1.666 +            }
   1.667 +            res[toString] = R._path2string;
   1.668 +            return res;
   1.669 +        }, null, pathClone),
   1.670 +        l2c = function (x1, y1, x2, y2) {
   1.671 +            return [x1, y1, x2, y2, x2, y2];
   1.672 +        },
   1.673 +        q2c = function (x1, y1, ax, ay, x2, y2) {
   1.674 +            var _13 = 1 / 3,
   1.675 +                _23 = 2 / 3;
   1.676 +            return [
   1.677 +                    _13 * x1 + _23 * ax,
   1.678 +                    _13 * y1 + _23 * ay,
   1.679 +                    _13 * x2 + _23 * ax,
   1.680 +                    _13 * y2 + _23 * ay,
   1.681 +                    x2,
   1.682 +                    y2
   1.683 +                ];
   1.684 +        },
   1.685 +        a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
   1.686 +            // for more information of where this math came from visit:
   1.687 +            // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
   1.688 +            var PI = math.PI,
   1.689 +                _120 = PI * 120 / 180,
   1.690 +                rad = PI / 180 * (+angle || 0),
   1.691 +                res = [],
   1.692 +                xy,
   1.693 +                rotate = cacher(function (x, y, rad) {
   1.694 +                    var X = x * math.cos(rad) - y * math.sin(rad),
   1.695 +                        Y = x * math.sin(rad) + y * math.cos(rad);
   1.696 +                    return {x: X, y: Y};
   1.697 +                });
   1.698 +            if (!recursive) {
   1.699 +                xy = rotate(x1, y1, -rad);
   1.700 +                x1 = xy.x;
   1.701 +                y1 = xy.y;
   1.702 +                xy = rotate(x2, y2, -rad);
   1.703 +                x2 = xy.x;
   1.704 +                y2 = xy.y;
   1.705 +                var cos = math.cos(PI / 180 * angle),
   1.706 +                    sin = math.sin(PI / 180 * angle),
   1.707 +                    x = (x1 - x2) / 2,
   1.708 +                    y = (y1 - y2) / 2;
   1.709 +                var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
   1.710 +                if (h > 1) {
   1.711 +                    h = math.sqrt(h);
   1.712 +                    rx = h * rx;
   1.713 +                    ry = h * ry;
   1.714 +                }
   1.715 +                var rx2 = rx * rx,
   1.716 +                    ry2 = ry * ry,
   1.717 +                    k = (large_arc_flag == sweep_flag ? -1 : 1) *
   1.718 +                        math.sqrt(math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
   1.719 +                    cx = k * rx * y / ry + (x1 + x2) / 2,
   1.720 +                    cy = k * -ry * x / rx + (y1 + y2) / 2,
   1.721 +                    f1 = math.asin(((y1 - cy) / ry).toFixed(7)),
   1.722 +                    f2 = math.asin(((y2 - cy) / ry).toFixed(7));
   1.723 +
   1.724 +                f1 = x1 < cx ? PI - f1 : f1;
   1.725 +                f2 = x2 < cx ? PI - f2 : f2;
   1.726 +                f1 < 0 && (f1 = PI * 2 + f1);
   1.727 +                f2 < 0 && (f2 = PI * 2 + f2);
   1.728 +                if (sweep_flag && f1 > f2) {
   1.729 +                    f1 = f1 - PI * 2;
   1.730 +                }
   1.731 +                if (!sweep_flag && f2 > f1) {
   1.732 +                    f2 = f2 - PI * 2;
   1.733 +                }
   1.734 +            } else {
   1.735 +                f1 = recursive[0];
   1.736 +                f2 = recursive[1];
   1.737 +                cx = recursive[2];
   1.738 +                cy = recursive[3];
   1.739 +            }
   1.740 +            var df = f2 - f1;
   1.741 +            if (math.abs(df) > _120) {
   1.742 +                var f2old = f2,
   1.743 +                    x2old = x2,
   1.744 +                    y2old = y2;
   1.745 +                f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
   1.746 +                x2 = cx + rx * math.cos(f2);
   1.747 +                y2 = cy + ry * math.sin(f2);
   1.748 +                res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
   1.749 +            }
   1.750 +            df = f2 - f1;
   1.751 +            var c1 = math.cos(f1),
   1.752 +                s1 = math.sin(f1),
   1.753 +                c2 = math.cos(f2),
   1.754 +                s2 = math.sin(f2),
   1.755 +                t = math.tan(df / 4),
   1.756 +                hx = 4 / 3 * rx * t,
   1.757 +                hy = 4 / 3 * ry * t,
   1.758 +                m1 = [x1, y1],
   1.759 +                m2 = [x1 + hx * s1, y1 - hy * c1],
   1.760 +                m3 = [x2 + hx * s2, y2 - hy * c2],
   1.761 +                m4 = [x2, y2];
   1.762 +            m2[0] = 2 * m1[0] - m2[0];
   1.763 +            m2[1] = 2 * m1[1] - m2[1];
   1.764 +            if (recursive) {
   1.765 +                return [m2, m3, m4][concat](res);
   1.766 +            } else {
   1.767 +                res = [m2, m3, m4][concat](res)[join]()[split](",");
   1.768 +                var newres = [];
   1.769 +                for (var i = 0, ii = res[length]; i < ii; i++) {
   1.770 +                    newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
   1.771 +                }
   1.772 +                return newres;
   1.773 +            }
   1.774 +        },
   1.775 +        findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
   1.776 +            var t1 = 1 - t;
   1.777 +            return {
   1.778 +                x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
   1.779 +                y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
   1.780 +            };
   1.781 +        },
   1.782 +        curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
   1.783 +            var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
   1.784 +                b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
   1.785 +                c = p1x - c1x,
   1.786 +                t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
   1.787 +                t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
   1.788 +                y = [p1y, p2y],
   1.789 +                x = [p1x, p2x],
   1.790 +                dot;
   1.791 +            math.abs(t1) > 1e12 && (t1 = .5);
   1.792 +            math.abs(t2) > 1e12 && (t2 = .5);
   1.793 +            if (t1 > 0 && t1 < 1) {
   1.794 +                dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
   1.795 +                x[push](dot.x);
   1.796 +                y[push](dot.y);
   1.797 +            }
   1.798 +            if (t2 > 0 && t2 < 1) {
   1.799 +                dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
   1.800 +                x[push](dot.x);
   1.801 +                y[push](dot.y);
   1.802 +            }
   1.803 +            a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
   1.804 +            b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
   1.805 +            c = p1y - c1y;
   1.806 +            t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
   1.807 +            t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
   1.808 +            math.abs(t1) > 1e12 && (t1 = .5);
   1.809 +            math.abs(t2) > 1e12 && (t2 = .5);
   1.810 +            if (t1 > 0 && t1 < 1) {
   1.811 +                dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
   1.812 +                x[push](dot.x);
   1.813 +                y[push](dot.y);
   1.814 +            }
   1.815 +            if (t2 > 0 && t2 < 1) {
   1.816 +                dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
   1.817 +                x[push](dot.x);
   1.818 +                y[push](dot.y);
   1.819 +            }
   1.820 +            return {
   1.821 +                min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
   1.822 +                max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
   1.823 +            };
   1.824 +        }),
   1.825 +        path2curve = cacher(function (path, path2) {
   1.826 +            var p = pathToAbsolute(path),
   1.827 +                p2 = path2 && pathToAbsolute(path2),
   1.828 +                attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
   1.829 +                attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
   1.830 +                processPath = function (path, d) {
   1.831 +                    var nx, ny;
   1.832 +                    if (!path) {
   1.833 +                        return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
   1.834 +                    }
   1.835 +                    !(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null);
   1.836 +                    switch (path[0]) {
   1.837 +                        case "M":
   1.838 +                            d.X = path[1];
   1.839 +                            d.Y = path[2];
   1.840 +                            break;
   1.841 +                        case "A":
   1.842 +                            path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
   1.843 +                            break;
   1.844 +                        case "S":
   1.845 +                            nx = d.x + (d.x - (d.bx || d.x));
   1.846 +                            ny = d.y + (d.y - (d.by || d.y));
   1.847 +                            path = ["C", nx, ny][concat](path.slice(1));
   1.848 +                            break;
   1.849 +                        case "T":
   1.850 +                            d.qx = d.x + (d.x - (d.qx || d.x));
   1.851 +                            d.qy = d.y + (d.y - (d.qy || d.y));
   1.852 +                            path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
   1.853 +                            break;
   1.854 +                        case "Q":
   1.855 +                            d.qx = path[1];
   1.856 +                            d.qy = path[2];
   1.857 +                            path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
   1.858 +                            break;
   1.859 +                        case "L":
   1.860 +                            path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
   1.861 +                            break;
   1.862 +                        case "H":
   1.863 +                            path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
   1.864 +                            break;
   1.865 +                        case "V":
   1.866 +                            path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
   1.867 +                            break;
   1.868 +                        case "Z":
   1.869 +                            path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
   1.870 +                            break;
   1.871 +                    }
   1.872 +                    return path;
   1.873 +                },
   1.874 +                fixArc = function (pp, i) {
   1.875 +                    if (pp[i][length] > 7) {
   1.876 +                        pp[i].shift();
   1.877 +                        var pi = pp[i];
   1.878 +                        while (pi[length]) {
   1.879 +                            pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
   1.880 +                        }
   1.881 +                        pp.splice(i, 1);
   1.882 +                        ii = mmax(p[length], p2 && p2[length] || 0);
   1.883 +                    }
   1.884 +                },
   1.885 +                fixM = function (path1, path2, a1, a2, i) {
   1.886 +                    if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
   1.887 +                        path2.splice(i, 0, ["M", a2.x, a2.y]);
   1.888 +                        a1.bx = 0;
   1.889 +                        a1.by = 0;
   1.890 +                        a1.x = path1[i][1];
   1.891 +                        a1.y = path1[i][2];
   1.892 +                        ii = mmax(p[length], p2 && p2[length] || 0);
   1.893 +                    }
   1.894 +                };
   1.895 +            for (var i = 0, ii = mmax(p[length], p2 && p2[length] || 0); i < ii; i++) {
   1.896 +                p[i] = processPath(p[i], attrs);
   1.897 +                fixArc(p, i);
   1.898 +                p2 && (p2[i] = processPath(p2[i], attrs2));
   1.899 +                p2 && fixArc(p2, i);
   1.900 +                fixM(p, p2, attrs, attrs2, i);
   1.901 +                fixM(p2, p, attrs2, attrs, i);
   1.902 +                var seg = p[i],
   1.903 +                    seg2 = p2 && p2[i],
   1.904 +                    seglen = seg[length],
   1.905 +                    seg2len = p2 && seg2[length];
   1.906 +                attrs.x = seg[seglen - 2];
   1.907 +                attrs.y = seg[seglen - 1];
   1.908 +                attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
   1.909 +                attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
   1.910 +                attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
   1.911 +                attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
   1.912 +                attrs2.x = p2 && seg2[seg2len - 2];
   1.913 +                attrs2.y = p2 && seg2[seg2len - 1];
   1.914 +            }
   1.915 +            return p2 ? [p, p2] : p;
   1.916 +        }, null, pathClone),
   1.917 +        parseDots = cacher(function (gradient) {
   1.918 +            var dots = [];
   1.919 +            for (var i = 0, ii = gradient[length]; i < ii; i++) {
   1.920 +                var dot = {},
   1.921 +                    par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
   1.922 +                dot.color = R.getRGB(par[1]);
   1.923 +                if (dot.color.error) {
   1.924 +                    return null;
   1.925 +                }
   1.926 +                dot.color = dot.color.hex;
   1.927 +                par[2] && (dot.offset = par[2] + "%");
   1.928 +                dots[push](dot);
   1.929 +            }
   1.930 +            for (i = 1, ii = dots[length] - 1; i < ii; i++) {
   1.931 +                if (!dots[i].offset) {
   1.932 +                    var start = toFloat(dots[i - 1].offset || 0),
   1.933 +                        end = 0;
   1.934 +                    for (var j = i + 1; j < ii; j++) {
   1.935 +                        if (dots[j].offset) {
   1.936 +                            end = dots[j].offset;
   1.937 +                            break;
   1.938 +                        }
   1.939 +                    }
   1.940 +                    if (!end) {
   1.941 +                        end = 100;
   1.942 +                        j = ii;
   1.943 +                    }
   1.944 +                    end = toFloat(end);
   1.945 +                    var d = (end - start) / (j - i + 1);
   1.946 +                    for (; i < j; i++) {
   1.947 +                        start += d;
   1.948 +                        dots[i].offset = start + "%";
   1.949 +                    }
   1.950 +                }
   1.951 +            }
   1.952 +            return dots;
   1.953 +        }),
   1.954 +        getContainer = function (x, y, w, h) {
   1.955 +            var container;
   1.956 +            if (R.is(x, string) || R.is(x, "object")) {
   1.957 +                container = R.is(x, string) ? doc.getElementById(x) : x;
   1.958 +                if (container.tagName) {
   1.959 +                    if (y == null) {
   1.960 +                        return {
   1.961 +                            container: container,
   1.962 +                            width: container.style.pixelWidth || container.offsetWidth,
   1.963 +                            height: container.style.pixelHeight || container.offsetHeight
   1.964 +                        };
   1.965 +                    } else {
   1.966 +                        return {container: container, width: y, height: w};
   1.967 +                    }
   1.968 +                }
   1.969 +            } else {
   1.970 +                return {container: 1, x: x, y: y, width: w, height: h};
   1.971 +            }
   1.972 +        },
   1.973 +        plugins = function (con, add) {
   1.974 +            var that = this;
   1.975 +            for (var prop in add) {
   1.976 +                if (add[has](prop) && !(prop in con)) {
   1.977 +                    switch (typeof add[prop]) {
   1.978 +                        case "function":
   1.979 +                            (function (f) {
   1.980 +                                con[prop] = con === that ? f : function () { return f[apply](that, arguments); };
   1.981 +                            })(add[prop]);
   1.982 +                        break;
   1.983 +                        case "object":
   1.984 +                            con[prop] = con[prop] || {};
   1.985 +                            plugins.call(this, con[prop], add[prop]);
   1.986 +                        break;
   1.987 +                        default:
   1.988 +                            con[prop] = add[prop];
   1.989 +                        break;
   1.990 +                    }
   1.991 +                }
   1.992 +            }
   1.993 +        },
   1.994 +        tear = function (el, paper) {
   1.995 +            el == paper.top && (paper.top = el.prev);
   1.996 +            el == paper.bottom && (paper.bottom = el.next);
   1.997 +            el.next && (el.next.prev = el.prev);
   1.998 +            el.prev && (el.prev.next = el.next);
   1.999 +        },
  1.1000 +        tofront = function (el, paper) {
  1.1001 +            if (paper.top === el) {
  1.1002 +                return;
  1.1003 +            }
  1.1004 +            tear(el, paper);
  1.1005 +            el.next = null;
  1.1006 +            el.prev = paper.top;
  1.1007 +            paper.top.next = el;
  1.1008 +            paper.top = el;
  1.1009 +        },
  1.1010 +        toback = function (el, paper) {
  1.1011 +            if (paper.bottom === el) {
  1.1012 +                return;
  1.1013 +            }
  1.1014 +            tear(el, paper);
  1.1015 +            el.next = paper.bottom;
  1.1016 +            el.prev = null;
  1.1017 +            paper.bottom.prev = el;
  1.1018 +            paper.bottom = el;
  1.1019 +        },
  1.1020 +        insertafter = function (el, el2, paper) {
  1.1021 +            tear(el, paper);
  1.1022 +            el2 == paper.top && (paper.top = el);
  1.1023 +            el2.next && (el2.next.prev = el);
  1.1024 +            el.next = el2.next;
  1.1025 +            el.prev = el2;
  1.1026 +            el2.next = el;
  1.1027 +        },
  1.1028 +        insertbefore = function (el, el2, paper) {
  1.1029 +            tear(el, paper);
  1.1030 +            el2 == paper.bottom && (paper.bottom = el);
  1.1031 +            el2.prev && (el2.prev.next = el);
  1.1032 +            el.prev = el2.prev;
  1.1033 +            el2.prev = el;
  1.1034 +            el.next = el2;
  1.1035 +        },
  1.1036 +        removed = function (methodname) {
  1.1037 +            return function () {
  1.1038 +                throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object");
  1.1039 +            };
  1.1040 +        },
  1.1041 +        radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/;
  1.1042 +    R.pathToRelative = pathToRelative;
  1.1043 +    // SVG
  1.1044 +    if (R.svg) {
  1.1045 +        Paper[proto].svgns = "http://www.w3.org/2000/svg";
  1.1046 +        Paper[proto].xlink = "http://www.w3.org/1999/xlink";
  1.1047 +        round = function (num) {
  1.1048 +            return +num + (~~num === num) * .5;
  1.1049 +        };
  1.1050 +        var $ = function (el, attr) {
  1.1051 +            if (attr) {
  1.1052 +                for (var key in attr) {
  1.1053 +                    if (attr[has](key)) {
  1.1054 +                        el[setAttribute](key, Str(attr[key]));
  1.1055 +                    }
  1.1056 +                }
  1.1057 +            } else {
  1.1058 +                el = doc.createElementNS(Paper[proto].svgns, el);
  1.1059 +                el.style.webkitTapHighlightColor = "rgba(0,0,0,0)";
  1.1060 +                return el;
  1.1061 +            }
  1.1062 +        };
  1.1063 +        R[toString] = function () {
  1.1064 +            return  "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
  1.1065 +        };
  1.1066 +        var thePath = function (pathString, SVG) {
  1.1067 +            var el = $("path");
  1.1068 +            SVG.canvas && SVG.canvas[appendChild](el);
  1.1069 +            var p = new Element(el, SVG);
  1.1070 +            p.type = "path";
  1.1071 +            setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString});
  1.1072 +            return p;
  1.1073 +        };
  1.1074 +        var addGradientFill = function (o, gradient, SVG) {
  1.1075 +            var type = "linear",
  1.1076 +                fx = .5, fy = .5,
  1.1077 +                s = o.style;
  1.1078 +            gradient = Str(gradient)[rp](radial_gradient, function (all, _fx, _fy) {
  1.1079 +                type = "radial";
  1.1080 +                if (_fx && _fy) {
  1.1081 +                    fx = toFloat(_fx);
  1.1082 +                    fy = toFloat(_fy);
  1.1083 +                    var dir = ((fy > .5) * 2 - 1);
  1.1084 +                    pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
  1.1085 +                        (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
  1.1086 +                        fy != .5 &&
  1.1087 +                        (fy = fy.toFixed(5) - 1e-5 * dir);
  1.1088 +                }
  1.1089 +                return E;
  1.1090 +            });
  1.1091 +            gradient = gradient[split](/\s*\-\s*/);
  1.1092 +            if (type == "linear") {
  1.1093 +                var angle = gradient.shift();
  1.1094 +                angle = -toFloat(angle);
  1.1095 +                if (isNaN(angle)) {
  1.1096 +                    return null;
  1.1097 +                }
  1.1098 +                var vector = [0, 0, math.cos(angle * math.PI / 180), math.sin(angle * math.PI / 180)],
  1.1099 +                    max = 1 / (mmax(math.abs(vector[2]), math.abs(vector[3])) || 1);
  1.1100 +                vector[2] *= max;
  1.1101 +                vector[3] *= max;
  1.1102 +                if (vector[2] < 0) {
  1.1103 +                    vector[0] = -vector[2];
  1.1104 +                    vector[2] = 0;
  1.1105 +                }
  1.1106 +                if (vector[3] < 0) {
  1.1107 +                    vector[1] = -vector[3];
  1.1108 +                    vector[3] = 0;
  1.1109 +                }
  1.1110 +            }
  1.1111 +            var dots = parseDots(gradient);
  1.1112 +            if (!dots) {
  1.1113 +                return null;
  1.1114 +            }
  1.1115 +            var id = o.getAttribute(fillString);
  1.1116 +            id = id.match(/^url\(#(.*)\)$/);
  1.1117 +            id && SVG.defs.removeChild(doc.getElementById(id[1]));
  1.1118 +            
  1.1119 +            var el = $(type + "Gradient");
  1.1120 +            el.id = "r" + (R._id++)[toString](36);
  1.1121 +            $(el, type == "radial" ? {fx: fx, fy: fy} : {x1: vector[0], y1: vector[1], x2: vector[2], y2: vector[3]});
  1.1122 +            SVG.defs[appendChild](el);
  1.1123 +            for (var i = 0, ii = dots[length]; i < ii; i++) {
  1.1124 +                var stop = $("stop");
  1.1125 +                $(stop, {
  1.1126 +                    offset: dots[i].offset ? dots[i].offset : !i ? "0%" : "100%",
  1.1127 +                    "stop-color": dots[i].color || "#fff"
  1.1128 +                });
  1.1129 +                el[appendChild](stop);
  1.1130 +            }
  1.1131 +            $(o, {
  1.1132 +                fill: "url(#" + el.id + ")",
  1.1133 +                opacity: 1,
  1.1134 +                "fill-opacity": 1
  1.1135 +            });
  1.1136 +            s.fill = E;
  1.1137 +            s.opacity = 1;
  1.1138 +            s.fillOpacity = 1;
  1.1139 +            return 1;
  1.1140 +        };
  1.1141 +        var updatePosition = function (o) {
  1.1142 +            var bbox = o.getBBox();
  1.1143 +            $(o.pattern, {patternTransform: R.format("translate({0},{1})", bbox.x, bbox.y)});
  1.1144 +        };
  1.1145 +        var setFillAndStroke = function (o, params) {
  1.1146 +            var dasharray = {
  1.1147 +                    "": [0],
  1.1148 +                    "none": [0],
  1.1149 +                    "-": [3, 1],
  1.1150 +                    ".": [1, 1],
  1.1151 +                    "-.": [3, 1, 1, 1],
  1.1152 +                    "-..": [3, 1, 1, 1, 1, 1],
  1.1153 +                    ". ": [1, 3],
  1.1154 +                    "- ": [4, 3],
  1.1155 +                    "--": [8, 3],
  1.1156 +                    "- .": [4, 3, 1, 3],
  1.1157 +                    "--.": [8, 3, 1, 3],
  1.1158 +                    "--..": [8, 3, 1, 3, 1, 3]
  1.1159 +                },
  1.1160 +                node = o.node,
  1.1161 +                attrs = o.attrs,
  1.1162 +                rot = o.rotate(),
  1.1163 +                addDashes = function (o, value) {
  1.1164 +                    value = dasharray[lowerCase.call(value)];
  1.1165 +                    if (value) {
  1.1166 +                        var width = o.attrs["stroke-width"] || "1",
  1.1167 +                            butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
  1.1168 +                            dashes = [];
  1.1169 +                        var i = value[length];
  1.1170 +                        while (i--) {
  1.1171 +                            dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
  1.1172 +                        }
  1.1173 +                        $(node, {"stroke-dasharray": dashes[join](",")});
  1.1174 +                    }
  1.1175 +                };
  1.1176 +            params[has]("rotation") && (rot = params.rotation);
  1.1177 +            var rotxy = Str(rot)[split](separator);
  1.1178 +            if (!(rotxy.length - 1)) {
  1.1179 +                rotxy = null;
  1.1180 +            } else {
  1.1181 +                rotxy[1] = +rotxy[1];
  1.1182 +                rotxy[2] = +rotxy[2];
  1.1183 +            }
  1.1184 +            toFloat(rot) && o.rotate(0, true);
  1.1185 +            for (var att in params) {
  1.1186 +                if (params[has](att)) {
  1.1187 +                    if (!availableAttrs[has](att)) {
  1.1188 +                        continue;
  1.1189 +                    }
  1.1190 +                    var value = params[att];
  1.1191 +                    attrs[att] = value;
  1.1192 +                    switch (att) {
  1.1193 +                        case "blur":
  1.1194 +                            o.blur(value);
  1.1195 +                            break;
  1.1196 +                        case "rotation":
  1.1197 +                            o.rotate(value, true);
  1.1198 +                            break;
  1.1199 +                        case "href":
  1.1200 +                        case "title":
  1.1201 +                        case "target":
  1.1202 +                            var pn = node.parentNode;
  1.1203 +                            if (lowerCase.call(pn.tagName) != "a") {
  1.1204 +                                var hl = $("a");
  1.1205 +                                pn.insertBefore(hl, node);
  1.1206 +                                hl[appendChild](node);
  1.1207 +                                pn = hl;
  1.1208 +                            }
  1.1209 +                            pn.setAttributeNS(o.paper.xlink, att, value);
  1.1210 +                            break;
  1.1211 +                        case "cursor":
  1.1212 +                            node.style.cursor = value;
  1.1213 +                            break;
  1.1214 +                        case "clip-rect":
  1.1215 +                            var rect = Str(value)[split](separator);
  1.1216 +                            if (rect[length] == 4) {
  1.1217 +                                o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
  1.1218 +                                var el = $("clipPath"),
  1.1219 +                                    rc = $("rect");
  1.1220 +                                el.id = "r" + (R._id++)[toString](36);
  1.1221 +                                $(rc, {
  1.1222 +                                    x: rect[0],
  1.1223 +                                    y: rect[1],
  1.1224 +                                    width: rect[2],
  1.1225 +                                    height: rect[3]
  1.1226 +                                });
  1.1227 +                                el[appendChild](rc);
  1.1228 +                                o.paper.defs[appendChild](el);
  1.1229 +                                $(node, {"clip-path": "url(#" + el.id + ")"});
  1.1230 +                                o.clip = rc;
  1.1231 +                            }
  1.1232 +                            if (!value) {
  1.1233 +                                var clip = doc.getElementById(node.getAttribute("clip-path")[rp](/(^url\(#|\)$)/g, E));
  1.1234 +                                clip && clip.parentNode.removeChild(clip);
  1.1235 +                                $(node, {"clip-path": E});
  1.1236 +                                delete o.clip;
  1.1237 +                            }
  1.1238 +                        break;
  1.1239 +                        case "path":
  1.1240 +                            if (o.type == "path") {
  1.1241 +                                $(node, {d: value ? attrs.path = pathToAbsolute(value) : "M0,0"});
  1.1242 +                            }
  1.1243 +                            break;
  1.1244 +                        case "width":
  1.1245 +                            node[setAttribute](att, value);
  1.1246 +                            if (attrs.fx) {
  1.1247 +                                att = "x";
  1.1248 +                                value = attrs.x;
  1.1249 +                            } else {
  1.1250 +                                break;
  1.1251 +                            }
  1.1252 +                        case "x":
  1.1253 +                            if (attrs.fx) {
  1.1254 +                                value = -attrs.x - (attrs.width || 0);
  1.1255 +                            }
  1.1256 +                        case "rx":
  1.1257 +                            if (att == "rx" && o.type == "rect") {
  1.1258 +                                break;
  1.1259 +                            }
  1.1260 +                        case "cx":
  1.1261 +                            rotxy && (att == "x" || att == "cx") && (rotxy[1] += value - attrs[att]);
  1.1262 +                            node[setAttribute](att, value);
  1.1263 +                            o.pattern && updatePosition(o);
  1.1264 +                            break;
  1.1265 +                        case "height":
  1.1266 +                            node[setAttribute](att, value);
  1.1267 +                            if (attrs.fy) {
  1.1268 +                                att = "y";
  1.1269 +                                value = attrs.y;
  1.1270 +                            } else {
  1.1271 +                                break;
  1.1272 +                            }
  1.1273 +                        case "y":
  1.1274 +                            if (attrs.fy) {
  1.1275 +                                value = -attrs.y - (attrs.height || 0);
  1.1276 +                            }
  1.1277 +                        case "ry":
  1.1278 +                            if (att == "ry" && o.type == "rect") {
  1.1279 +                                break;
  1.1280 +                            }
  1.1281 +                        case "cy":
  1.1282 +                            rotxy && (att == "y" || att == "cy") && (rotxy[2] += value - attrs[att]);
  1.1283 +                            node[setAttribute](att, value);
  1.1284 +                            o.pattern && updatePosition(o);
  1.1285 +                            break;
  1.1286 +                        case "r":
  1.1287 +                            if (o.type == "rect") {
  1.1288 +                                $(node, {rx: value, ry: value});
  1.1289 +                            } else {
  1.1290 +                                node[setAttribute](att, value);
  1.1291 +                            }
  1.1292 +                            break;
  1.1293 +                        case "src":
  1.1294 +                            if (o.type == "image") {
  1.1295 +                                node.setAttributeNS(o.paper.xlink, "href", value);
  1.1296 +                            }
  1.1297 +                            break;
  1.1298 +                        case "stroke-width":
  1.1299 +                            node.style.strokeWidth = value;
  1.1300 +                            // Need following line for Firefox
  1.1301 +                            node[setAttribute](att, value);
  1.1302 +                            if (attrs["stroke-dasharray"]) {
  1.1303 +                                addDashes(o, attrs["stroke-dasharray"]);
  1.1304 +                            }
  1.1305 +                            break;
  1.1306 +                        case "stroke-dasharray":
  1.1307 +                            addDashes(o, value);
  1.1308 +                            break;
  1.1309 +                        case "translation":
  1.1310 +                            var xy = Str(value)[split](separator);
  1.1311 +                            xy[0] = +xy[0] || 0;
  1.1312 +                            xy[1] = +xy[1] || 0;
  1.1313 +                            if (rotxy) {
  1.1314 +                                rotxy[1] += xy[0];
  1.1315 +                                rotxy[2] += xy[1];
  1.1316 +                            }
  1.1317 +                            translate.call(o, xy[0], xy[1]);
  1.1318 +                            break;
  1.1319 +                        case "scale":
  1.1320 +                            xy = Str(value)[split](separator);
  1.1321 +                            o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, isNaN(toFloat(xy[2])) ? null : +xy[2], isNaN(toFloat(xy[3])) ? null : +xy[3]);
  1.1322 +                            break;
  1.1323 +                        case fillString:
  1.1324 +                            var isURL = Str(value).match(ISURL);
  1.1325 +                            if (isURL) {
  1.1326 +                                el = $("pattern");
  1.1327 +                                var ig = $("image");
  1.1328 +                                el.id = "r" + (R._id++)[toString](36);
  1.1329 +                                $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
  1.1330 +                                $(ig, {x: 0, y: 0});
  1.1331 +                                ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
  1.1332 +                                el[appendChild](ig);
  1.1333 + 
  1.1334 +                                var img = doc.createElement("img");
  1.1335 +                                img.style.cssText = "position:absolute;left:-9999em;top-9999em";
  1.1336 +                                img.onload = function () {
  1.1337 +                                    $(el, {width: this.offsetWidth, height: this.offsetHeight});
  1.1338 +                                    $(ig, {width: this.offsetWidth, height: this.offsetHeight});
  1.1339 +                                    doc.body.removeChild(this);
  1.1340 +                                    o.paper.safari();
  1.1341 +                                };
  1.1342 +                                doc.body[appendChild](img);
  1.1343 +                                img.src = isURL[1];
  1.1344 +                                o.paper.defs[appendChild](el);
  1.1345 +                                node.style.fill = "url(#" + el.id + ")";
  1.1346 +                                $(node, {fill: "url(#" + el.id + ")"});
  1.1347 +                                o.pattern = el;
  1.1348 +                                o.pattern && updatePosition(o);
  1.1349 +                                break;
  1.1350 +                            }
  1.1351 +                            var clr = R.getRGB(value);
  1.1352 +                            if (!clr.error) {
  1.1353 +                                delete params.gradient;
  1.1354 +                                delete attrs.gradient;
  1.1355 +                                !R.is(attrs.opacity, "undefined") &&
  1.1356 +                                    R.is(params.opacity, "undefined") &&
  1.1357 +                                    $(node, {opacity: attrs.opacity});
  1.1358 +                                !R.is(attrs["fill-opacity"], "undefined") &&
  1.1359 +                                    R.is(params["fill-opacity"], "undefined") &&
  1.1360 +                                    $(node, {"fill-opacity": attrs["fill-opacity"]});
  1.1361 +                            } else if ((({circle: 1, ellipse: 1})[has](o.type) || Str(value).charAt() != "r") && addGradientFill(node, value, o.paper)) {
  1.1362 +                                attrs.gradient = value;
  1.1363 +                                attrs.fill = "none";
  1.1364 +                                break;
  1.1365 +                            }
  1.1366 +                            clr[has]("o") && $(node, {"fill-opacity": clr.o > 1 ? clr.o / 100 : clr.o});
  1.1367 +                        case "stroke":
  1.1368 +                            clr = R.getRGB(value);
  1.1369 +                            node[setAttribute](att, clr.hex);
  1.1370 +                            att == "stroke" && clr[has]("o") && $(node, {"stroke-opacity": clr.o > 1 ? clr.o / 100 : clr.o});
  1.1371 +                            break;
  1.1372 +                        case "gradient":
  1.1373 +                            (({circle: 1, ellipse: 1})[has](o.type) || Str(value).charAt() != "r") && addGradientFill(node, value, o.paper);
  1.1374 +                            break;
  1.1375 +                        case "opacity":
  1.1376 +                        case "fill-opacity":
  1.1377 +                            if (attrs.gradient) {
  1.1378 +                                var gradient = doc.getElementById(node.getAttribute(fillString)[rp](/^url\(#|\)$/g, E));
  1.1379 +                                if (gradient) {
  1.1380 +                                    var stops = gradient.getElementsByTagName("stop");
  1.1381 +                                    stops[stops[length] - 1][setAttribute]("stop-opacity", value);
  1.1382 +                                }
  1.1383 +                                break;
  1.1384 +                            }
  1.1385 +                        default:
  1.1386 +                            att == "font-size" && (value = toInt(value, 10) + "px");
  1.1387 +                            var cssrule = att[rp](/(\-.)/g, function (w) {
  1.1388 +                                return upperCase.call(w.substring(1));
  1.1389 +                            });
  1.1390 +                            node.style[cssrule] = value;
  1.1391 +                            // Need following line for Firefox
  1.1392 +                            node[setAttribute](att, value);
  1.1393 +                            break;
  1.1394 +                    }
  1.1395 +                }
  1.1396 +            }
  1.1397 +            
  1.1398 +            tuneText(o, params);
  1.1399 +            if (rotxy) {
  1.1400 +                o.rotate(rotxy.join(S));
  1.1401 +            } else {
  1.1402 +                toFloat(rot) && o.rotate(rot, true);
  1.1403 +            }
  1.1404 +        };
  1.1405 +        var leading = 1.2,
  1.1406 +        tuneText = function (el, params) {
  1.1407 +            if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
  1.1408 +                return;
  1.1409 +            }
  1.1410 +            var a = el.attrs,
  1.1411 +                node = el.node,
  1.1412 +                fontSize = node.firstChild ? toInt(doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
  1.1413 + 
  1.1414 +            if (params[has]("text")) {
  1.1415 +                a.text = params.text;
  1.1416 +                while (node.firstChild) {
  1.1417 +                    node.removeChild(node.firstChild);
  1.1418 +                }
  1.1419 +                var texts = Str(params.text)[split]("\n");
  1.1420 +                for (var i = 0, ii = texts[length]; i < ii; i++) if (texts[i]) {
  1.1421 +                    var tspan = $("tspan");
  1.1422 +                    i && $(tspan, {dy: fontSize * leading, x: a.x});
  1.1423 +                    tspan[appendChild](doc.createTextNode(texts[i]));
  1.1424 +                    node[appendChild](tspan);
  1.1425 +                }
  1.1426 +            } else {
  1.1427 +                texts = node.getElementsByTagName("tspan");
  1.1428 +                for (i = 0, ii = texts[length]; i < ii; i++) {
  1.1429 +                    i && $(texts[i], {dy: fontSize * leading, x: a.x});
  1.1430 +                }
  1.1431 +            }
  1.1432 +            $(node, {y: a.y});
  1.1433 +            var bb = el.getBBox(),
  1.1434 +                dif = a.y - (bb.y + bb.height / 2);
  1.1435 +            dif && isFinite(dif) && $(node, {y: a.y + dif});
  1.1436 +        },
  1.1437 +        Element = function (node, svg) {
  1.1438 +            var X = 0,
  1.1439 +                Y = 0;
  1.1440 +            this[0] = node;
  1.1441 +            this.id = R._oid++;
  1.1442 +            this.node = node;
  1.1443 +            node.raphael = this;
  1.1444 +            this.paper = svg;
  1.1445 +            this.attrs = this.attrs || {};
  1.1446 +            this.transformations = []; // rotate, translate, scale
  1.1447 +            this._ = {
  1.1448 +                tx: 0,
  1.1449 +                ty: 0,
  1.1450 +                rt: {deg: 0, cx: 0, cy: 0},
  1.1451 +                sx: 1,
  1.1452 +                sy: 1
  1.1453 +            };
  1.1454 +            !svg.bottom && (svg.bottom = this);
  1.1455 +            this.prev = svg.top;
  1.1456 +            svg.top && (svg.top.next = this);
  1.1457 +            svg.top = this;
  1.1458 +            this.next = null;
  1.1459 +        };
  1.1460 +        Element[proto].rotate = function (deg, cx, cy) {
  1.1461 +            if (this.removed) {
  1.1462 +                return this;
  1.1463 +            }
  1.1464 +            if (deg == null) {
  1.1465 +                if (this._.rt.cx) {
  1.1466 +                    return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
  1.1467 +                }
  1.1468 +                return this._.rt.deg;
  1.1469 +            }
  1.1470 +            var bbox = this.getBBox();
  1.1471 +            deg = Str(deg)[split](separator);
  1.1472 +            if (deg[length] - 1) {
  1.1473 +                cx = toFloat(deg[1]);
  1.1474 +                cy = toFloat(deg[2]);
  1.1475 +            }
  1.1476 +            deg = toFloat(deg[0]);
  1.1477 +            if (cx != null) {
  1.1478 +                this._.rt.deg = deg;
  1.1479 +            } else {
  1.1480 +                this._.rt.deg += deg;
  1.1481 +            }
  1.1482 +            (cy == null) && (cx = null);
  1.1483 +            this._.rt.cx = cx;
  1.1484 +            this._.rt.cy = cy;
  1.1485 +            cx = cx == null ? bbox.x + bbox.width / 2 : cx;
  1.1486 +            cy = cy == null ? bbox.y + bbox.height / 2 : cy;
  1.1487 +            if (this._.rt.deg) {
  1.1488 +                this.transformations[0] = R.format("rotate({0} {1} {2})", this._.rt.deg, cx, cy);
  1.1489 +                this.clip && $(this.clip, {transform: R.format("rotate({0} {1} {2})", -this._.rt.deg, cx, cy)});
  1.1490 +            } else {
  1.1491 +                this.transformations[0] = E;
  1.1492 +                this.clip && $(this.clip, {transform: E});
  1.1493 +            }
  1.1494 +            $(this.node, {transform: this.transformations[join](S)});
  1.1495 +            return this;
  1.1496 +        };
  1.1497 +        Element[proto].hide = function () {
  1.1498 +            !this.removed && (this.node.style.display = "none");
  1.1499 +            return this;
  1.1500 +        };
  1.1501 +        Element[proto].show = function () {
  1.1502 +            !this.removed && (this.node.style.display = "");
  1.1503 +            return this;
  1.1504 +        };
  1.1505 +        Element[proto].remove = function () {
  1.1506 +            if (this.removed) {
  1.1507 +                return;
  1.1508 +            }
  1.1509 +            tear(this, this.paper);
  1.1510 +            this.node.parentNode.removeChild(this.node);
  1.1511 +            for (var i in this) {
  1.1512 +                delete this[i];
  1.1513 +            }
  1.1514 +            this.removed = true;
  1.1515 +        };
  1.1516 +        Element[proto].getBBox = function () {
  1.1517 +            if (this.removed) {
  1.1518 +                return this;
  1.1519 +            }
  1.1520 +            if (this.type == "path") {
  1.1521 +                return pathDimensions(this.attrs.path);
  1.1522 +            }
  1.1523 +            if (this.node.style.display == "none") {
  1.1524 +                this.show();
  1.1525 +                var hide = true;
  1.1526 +            }
  1.1527 +            var bbox = {};
  1.1528 +            try {
  1.1529 +                bbox = this.node.getBBox();
  1.1530 +            } catch(e) {
  1.1531 +                // Firefox 3.0.x plays badly here
  1.1532 +            } finally {
  1.1533 +                bbox = bbox || {};
  1.1534 +            }
  1.1535 +            if (this.type == "text") {
  1.1536 +                bbox = {x: bbox.x, y: Infinity, width: 0, height: 0};
  1.1537 +                for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
  1.1538 +                    var bb = this.node.getExtentOfChar(i);
  1.1539 +                    (bb.y < bbox.y) && (bbox.y = bb.y);
  1.1540 +                    (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
  1.1541 +                    (bb.x + bb.width - bbox.x > bbox.width) && (bbox.width = bb.x + bb.width - bbox.x);
  1.1542 +                }
  1.1543 +            }
  1.1544 +            hide && this.hide();
  1.1545 +            return bbox;
  1.1546 +        };
  1.1547 +        Element[proto].attr = function (name, value) {
  1.1548 +            if (this.removed) {
  1.1549 +                return this;
  1.1550 +            }
  1.1551 +            if (name == null) {
  1.1552 +                var res = {};
  1.1553 +                for (var i in this.attrs) if (this.attrs[has](i)) {
  1.1554 +                    res[i] = this.attrs[i];
  1.1555 +                }
  1.1556 +                this._.rt.deg && (res.rotation = this.rotate());
  1.1557 +                (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
  1.1558 +                res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
  1.1559 +                return res;
  1.1560 +            }
  1.1561 +            if (value == null && R.is(name, string)) {
  1.1562 +                if (name == "translation") {
  1.1563 +                    return translate.call(this);
  1.1564 +                }
  1.1565 +                if (name == "rotation") {
  1.1566 +                    return this.rotate();
  1.1567 +                }
  1.1568 +                if (name == "scale") {
  1.1569 +                    return this.scale();
  1.1570 +                }
  1.1571 +                if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
  1.1572 +                    return this.attrs.gradient;
  1.1573 +                }
  1.1574 +                return this.attrs[name];
  1.1575 +            }
  1.1576 +            if (value == null && R.is(name, array)) {
  1.1577 +                var values = {};
  1.1578 +                for (var j = 0, jj = name.length; j < jj; j++) {
  1.1579 +                    values[name[j]] = this.attr(name[j]);
  1.1580 +                }
  1.1581 +                return values;
  1.1582 +            }
  1.1583 +            if (value != null) {
  1.1584 +                var params = {};
  1.1585 +                params[name] = value;
  1.1586 +                setFillAndStroke(this, params);
  1.1587 +            } else if (name != null && R.is(name, "object")) {
  1.1588 +                setFillAndStroke(this, name);
  1.1589 +            }
  1.1590 +            return this;
  1.1591 +        };
  1.1592 +        Element[proto].toFront = function () {
  1.1593 +            if (this.removed) {
  1.1594 +                return this;
  1.1595 +            }
  1.1596 +            this.node.parentNode[appendChild](this.node);
  1.1597 +            var svg = this.paper;
  1.1598 +            svg.top != this && tofront(this, svg);
  1.1599 +            return this;
  1.1600 +        };
  1.1601 +        Element[proto].toBack = function () {
  1.1602 +            if (this.removed) {
  1.1603 +                return this;
  1.1604 +            }
  1.1605 +            if (this.node.parentNode.firstChild != this.node) {
  1.1606 +                this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
  1.1607 +                toback(this, this.paper);
  1.1608 +                var svg = this.paper;
  1.1609 +            }
  1.1610 +            return this;
  1.1611 +        };
  1.1612 +        Element[proto].insertAfter = function (element) {
  1.1613 +            if (this.removed) {
  1.1614 +                return this;
  1.1615 +            }
  1.1616 +            var node = element.node || element[element.length].node;
  1.1617 +            if (node.nextSibling) {
  1.1618 +                node.parentNode.insertBefore(this.node, node.nextSibling);
  1.1619 +            } else {
  1.1620 +                node.parentNode[appendChild](this.node);
  1.1621 +            }
  1.1622 +            insertafter(this, element, this.paper);
  1.1623 +            return this;
  1.1624 +        };
  1.1625 +        Element[proto].insertBefore = function (element) {
  1.1626 +            if (this.removed) {
  1.1627 +                return this;
  1.1628 +            }
  1.1629 +            var node = element.node || element[0].node;
  1.1630 +            node.parentNode.insertBefore(this.node, node);
  1.1631 +            insertbefore(this, element, this.paper);
  1.1632 +            return this;
  1.1633 +        };
  1.1634 +        Element[proto].blur = function (size) {
  1.1635 +            // Experimental. No Safari support. Use it on your own risk.
  1.1636 +            var t = this;
  1.1637 +            if (+size !== 0) {
  1.1638 +                var fltr = $("filter"),
  1.1639 +                    blur = $("feGaussianBlur");
  1.1640 +                t.attrs.blur = size;
  1.1641 +                fltr.id = "r" + (R._id++)[toString](36);
  1.1642 +                $(blur, {stdDeviation: +size || 1.5});
  1.1643 +                fltr.appendChild(blur);
  1.1644 +                t.paper.defs.appendChild(fltr);
  1.1645 +                t._blur = fltr;
  1.1646 +                $(t.node, {filter: "url(#" + fltr.id + ")"});
  1.1647 +            } else {
  1.1648 +                if (t._blur) {
  1.1649 +                    t._blur.parentNode.removeChild(t._blur);
  1.1650 +                    delete t._blur;
  1.1651 +                    delete t.attrs.blur;
  1.1652 +                }
  1.1653 +                t.node.removeAttribute("filter");
  1.1654 +            }
  1.1655 +        };
  1.1656 +        var theCircle = function (svg, x, y, r) {
  1.1657 +            var el = $("circle");
  1.1658 +            svg.canvas && svg.canvas[appendChild](el);
  1.1659 +            var res = new Element(el, svg);
  1.1660 +            res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
  1.1661 +            res.type = "circle";
  1.1662 +            $(el, res.attrs);
  1.1663 +            return res;
  1.1664 +        };
  1.1665 +        var theRect = function (svg, x, y, w, h, r) {
  1.1666 +            var el = $("rect");
  1.1667 +            svg.canvas && svg.canvas[appendChild](el);
  1.1668 +            var res = new Element(el, svg);
  1.1669 +            res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
  1.1670 +            res.type = "rect";
  1.1671 +            $(el, res.attrs);
  1.1672 +            return res;
  1.1673 +        };
  1.1674 +        var theEllipse = function (svg, x, y, rx, ry) {
  1.1675 +            var el = $("ellipse");
  1.1676 +            svg.canvas && svg.canvas[appendChild](el);
  1.1677 +            var res = new Element(el, svg);
  1.1678 +            res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
  1.1679 +            res.type = "ellipse";
  1.1680 +            $(el, res.attrs);
  1.1681 +            return res;
  1.1682 +        };
  1.1683 +        var theImage = function (svg, src, x, y, w, h) {
  1.1684 +            var el = $("image");
  1.1685 +            $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
  1.1686 +            el.setAttributeNS(svg.xlink, "href", src);
  1.1687 +            svg.canvas && svg.canvas[appendChild](el);
  1.1688 +            var res = new Element(el, svg);
  1.1689 +            res.attrs = {x: x, y: y, width: w, height: h, src: src};
  1.1690 +            res.type = "image";
  1.1691 +            return res;
  1.1692 +        };
  1.1693 +        var theText = function (svg, x, y, text) {
  1.1694 +            var el = $("text");
  1.1695 +            $(el, {x: x, y: y, "text-anchor": "middle"});
  1.1696 +            svg.canvas && svg.canvas[appendChild](el);
  1.1697 +            var res = new Element(el, svg);
  1.1698 +            res.attrs = {x: x, y: y, "text-anchor": "middle", text: text, font: availableAttrs.font, stroke: "none", fill: "#000"};
  1.1699 +            res.type = "text";
  1.1700 +            setFillAndStroke(res, res.attrs);
  1.1701 +            return res;
  1.1702 +        };
  1.1703 +        var setSize = function (width, height) {
  1.1704 +            this.width = width || this.width;
  1.1705 +            this.height = height || this.height;
  1.1706 +            this.canvas[setAttribute]("width", this.width);
  1.1707 +            this.canvas[setAttribute]("height", this.height);
  1.1708 +            return this;
  1.1709 +        };
  1.1710 +        var create = function () {
  1.1711 +            var con = getContainer[apply](0, arguments),
  1.1712 +                container = con && con.container,
  1.1713 +                x = con.x,
  1.1714 +                y = con.y,
  1.1715 +                width = con.width,
  1.1716 +                height = con.height;
  1.1717 +            if (!container) {
  1.1718 +                throw new Error("SVG container not found.");
  1.1719 +            }
  1.1720 +            var cnvs = $("svg");
  1.1721 +            x = x || 0;
  1.1722 +            y = y || 0;
  1.1723 +            width = width || 512;
  1.1724 +            height = height || 342;
  1.1725 +            $(cnvs, {
  1.1726 +                xmlns: "http://www.w3.org/2000/svg",
  1.1727 +                version: 1.1,
  1.1728 +                width: width,
  1.1729 +                height: height
  1.1730 +            });
  1.1731 +            if (container == 1) {
  1.1732 +                cnvs.style.cssText = "position:absolute;left:" + x + "px;top:" + y + "px";
  1.1733 +                doc.body[appendChild](cnvs);
  1.1734 +            } else {
  1.1735 +                if (container.firstChild) {
  1.1736 +                    container.insertBefore(cnvs, container.firstChild);
  1.1737 +                } else {
  1.1738 +                    container[appendChild](cnvs);
  1.1739 +                }
  1.1740 +            }
  1.1741 +            container = new Paper;
  1.1742 +            container.width = width;
  1.1743 +            container.height = height;
  1.1744 +            container.canvas = cnvs;
  1.1745 +            plugins.call(container, container, R.fn);
  1.1746 +            container.clear();
  1.1747 +            return container;
  1.1748 +        };
  1.1749 +        Paper[proto].clear = function () {
  1.1750 +            var c = this.canvas;
  1.1751 +            while (c.firstChild) {
  1.1752 +                c.removeChild(c.firstChild);
  1.1753 +            }
  1.1754 +            this.bottom = this.top = null;
  1.1755 +            (this.desc = $("desc"))[appendChild](doc.createTextNode("Created with Rapha\xebl"));
  1.1756 +            c[appendChild](this.desc);
  1.1757 +            c[appendChild](this.defs = $("defs"));
  1.1758 +        };
  1.1759 +        Paper[proto].remove = function () {
  1.1760 +            this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
  1.1761 +            for (var i in this) {
  1.1762 +                this[i] = removed(i);
  1.1763 +            }
  1.1764 +        };
  1.1765 +    }
  1.1766 +
  1.1767 +    // VML
  1.1768 +    if (R.vml) {
  1.1769 +        var map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
  1.1770 +            bites = /([clmz]),?([^clmz]*)/gi,
  1.1771 +            val = /-?[^,\s-]+/g,
  1.1772 +            coordsize = 1e3 + S + 1e3,
  1.1773 +            zoom = 10,
  1.1774 +            pathlike = {path: 1, rect: 1},
  1.1775 +            path2vml = function (path) {
  1.1776 +                var total =  /[ahqstv]/ig,
  1.1777 +                    command = pathToAbsolute;
  1.1778 +                Str(path).match(total) && (command = path2curve);
  1.1779 +                total = /[clmz]/g;
  1.1780 +                if (command == pathToAbsolute && !Str(path).match(total)) {
  1.1781 +                    var res = Str(path)[rp](bites, function (all, command, args) {
  1.1782 +                        var vals = [],
  1.1783 +                            isMove = lowerCase.call(command) == "m",
  1.1784 +                            res = map[command];
  1.1785 +                        args[rp](val, function (value) {
  1.1786 +                            if (isMove && vals[length] == 2) {
  1.1787 +                                res += vals + map[command == "m" ? "l" : "L"];
  1.1788 +                                vals = [];
  1.1789 +                            }
  1.1790 +                            vals[push](round(value * zoom));
  1.1791 +                        });
  1.1792 +                        return res + vals;
  1.1793 +                    });
  1.1794 +                    return res;
  1.1795 +                }
  1.1796 +                var pa = command(path), p, r;
  1.1797 +                res = [];
  1.1798 +                for (var i = 0, ii = pa[length]; i < ii; i++) {
  1.1799 +                    p = pa[i];
  1.1800 +                    r = lowerCase.call(pa[i][0]);
  1.1801 +                    r == "z" && (r = "x");
  1.1802 +                    for (var j = 1, jj = p[length]; j < jj; j++) {
  1.1803 +                        r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
  1.1804 +                    }
  1.1805 +                    res[push](r);
  1.1806 +                }
  1.1807 +                return res[join](S);
  1.1808 +            };
  1.1809 +        
  1.1810 +        R[toString] = function () {
  1.1811 +            return  "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
  1.1812 +        };
  1.1813 +        thePath = function (pathString, vml) {
  1.1814 +            var g = createNode("group");
  1.1815 +            g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
  1.1816 +            g.coordsize = vml.coordsize;
  1.1817 +            g.coordorigin = vml.coordorigin;
  1.1818 +            var el = createNode("shape"), ol = el.style;
  1.1819 +            ol.width = vml.width + "px";
  1.1820 +            ol.height = vml.height + "px";
  1.1821 +            el.coordsize = coordsize;
  1.1822 +            el.coordorigin = vml.coordorigin;
  1.1823 +            g[appendChild](el);
  1.1824 +            var p = new Element(el, g, vml),
  1.1825 +                attr = {fill: "none", stroke: "#000"};
  1.1826 +            pathString && (attr.path = pathString);
  1.1827 +            p.isAbsolute = true;
  1.1828 +            p.type = "path";
  1.1829 +            p.path = [];
  1.1830 +            p.Path = E;
  1.1831 +            setFillAndStroke(p, attr);
  1.1832 +            vml.canvas[appendChild](g);
  1.1833 +            return p;
  1.1834 +        };
  1.1835 +        setFillAndStroke = function (o, params) {
  1.1836 +            o.attrs = o.attrs || {};
  1.1837 +            var node = o.node,
  1.1838 +                a = o.attrs,
  1.1839 +                s = node.style,
  1.1840 +                xy,
  1.1841 +                newpath = (params.x != a.x || params.y != a.y || params.width != a.width || params.height != a.height || params.r != a.r) && o.type == "rect",
  1.1842 +                res = o;
  1.1843 +
  1.1844 +            for (var par in params) if (params[has](par)) {
  1.1845 +                a[par] = params[par];
  1.1846 +            }
  1.1847 +            if (newpath) {
  1.1848 +                a.path = rectPath(a.x, a.y, a.width, a.height, a.r);
  1.1849 +                o.X = a.x;
  1.1850 +                o.Y = a.y;
  1.1851 +                o.W = a.width;
  1.1852 +                o.H = a.height;
  1.1853 +            }
  1.1854 +            params.href && (node.href = params.href);
  1.1855 +            params.title && (node.title = params.title);
  1.1856 +            params.target && (node.target = params.target);
  1.1857 +            params.cursor && (s.cursor = params.cursor);
  1.1858 +            "blur" in params && o.blur(params.blur);
  1.1859 +            if (params.path && o.type == "path" || newpath) {
  1.1860 +                    node.path = path2vml(a.path);
  1.1861 +            }
  1.1862 +            if (params.rotation != null) {
  1.1863 +                o.rotate(params.rotation, true);
  1.1864 +            }
  1.1865 +            if (params.translation) {
  1.1866 +                xy = Str(params.translation)[split](separator);
  1.1867 +                translate.call(o, xy[0], xy[1]);
  1.1868 +                if (o._.rt.cx != null) {
  1.1869 +                    o._.rt.cx +=+ xy[0];
  1.1870 +                    o._.rt.cy +=+ xy[1];
  1.1871 +                    o.setBox(o.attrs, xy[0], xy[1]);
  1.1872 +                }
  1.1873 +            }
  1.1874 +            if (params.scale) {
  1.1875 +                xy = Str(params.scale)[split](separator);
  1.1876 +                o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
  1.1877 +            }
  1.1878 +            if ("clip-rect" in params) {
  1.1879 +                var rect = Str(params["clip-rect"])[split](separator);
  1.1880 +                if (rect[length] == 4) {
  1.1881 +                    rect[2] = +rect[2] + (+rect[0]);
  1.1882 +                    rect[3] = +rect[3] + (+rect[1]);
  1.1883 +                    var div = node.clipRect || doc.createElement("div"),
  1.1884 +                        dstyle = div.style,
  1.1885 +                        group = node.parentNode;
  1.1886 +                    dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
  1.1887 +                    if (!node.clipRect) {
  1.1888 +                        dstyle.position = "absolute";
  1.1889 +                        dstyle.top = 0;
  1.1890 +                        dstyle.left = 0;
  1.1891 +                        dstyle.width = o.paper.width + "px";
  1.1892 +                        dstyle.height = o.paper.height + "px";
  1.1893 +                        group.parentNode.insertBefore(div, group);
  1.1894 +                        div[appendChild](group);
  1.1895 +                        node.clipRect = div;
  1.1896 +                    }
  1.1897 +                }
  1.1898 +                if (!params["clip-rect"]) {
  1.1899 +                    node.clipRect && (node.clipRect.style.clip = E);
  1.1900 +                }
  1.1901 +            }
  1.1902 +            if (o.type == "image" && params.src) {
  1.1903 +                node.src = params.src;
  1.1904 +            }
  1.1905 +            if (o.type == "image" && params.opacity) {
  1.1906 +                node.filterOpacity = ms + ".Alpha(opacity=" + (params.opacity * 100) + ")";
  1.1907 +                s.filter = (node.filterMatrix || E) + (node.filterOpacity || E);
  1.1908 +            }
  1.1909 +            params.font && (s.font = params.font);
  1.1910 +            params["font-family"] && (s.fontFamily = '"' + params["font-family"][split](",")[0][rp](/^['"]+|['"]+$/g, E) + '"');
  1.1911 +            params["font-size"] && (s.fontSize = params["font-size"]);
  1.1912 +            params["font-weight"] && (s.fontWeight = params["font-weight"]);
  1.1913 +            params["font-style"] && (s.fontStyle = params["font-style"]);
  1.1914 +            if (params.opacity != null || 
  1.1915 +                params["stroke-width"] != null ||
  1.1916 +                params.fill != null ||
  1.1917 +                params.stroke != null ||
  1.1918 +                params["stroke-width"] != null ||
  1.1919 +                params["stroke-opacity"] != null ||
  1.1920 +                params["fill-opacity"] != null ||
  1.1921 +                params["stroke-dasharray"] != null ||
  1.1922 +                params["stroke-miterlimit"] != null ||
  1.1923 +                params["stroke-linejoin"] != null ||
  1.1924 +                params["stroke-linecap"] != null) {
  1.1925 +                node = o.shape || node;
  1.1926 +                var fill = (node.getElementsByTagName(fillString) && node.getElementsByTagName(fillString)[0]),
  1.1927 +                    newfill = false;
  1.1928 +                !fill && (newfill = fill = createNode(fillString));
  1.1929 +                if ("fill-opacity" in params || "opacity" in params) {
  1.1930 +                    var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
  1.1931 +                    opacity < 0 && (opacity = 0);
  1.1932 +                    opacity > 1 && (opacity = 1);
  1.1933 +                    fill.opacity = opacity;
  1.1934 +                }
  1.1935 +                params.fill && (fill.on = true);
  1.1936 +                if (fill.on == null || params.fill == "none") {
  1.1937 +                    fill.on = false;
  1.1938 +                }
  1.1939 +                if (fill.on && params.fill) {
  1.1940 +                    var isURL = params.fill.match(ISURL);
  1.1941 +                    if (isURL) {
  1.1942 +                        fill.src = isURL[1];
  1.1943 +                        fill.type = "tile";
  1.1944 +                    } else {
  1.1945 +                        fill.color = R.getRGB(params.fill).hex;
  1.1946 +                        fill.src = E;
  1.1947 +                        fill.type = "solid";
  1.1948 +                        if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || Str(params.fill).charAt() != "r") && addGradientFill(res, params.fill)) {
  1.1949 +                            a.fill = "none";
  1.1950 +                            a.gradient = params.fill;
  1.1951 +                        }
  1.1952 +                    }
  1.1953 +                }
  1.1954 +                newfill && node[appendChild](fill);
  1.1955 +                var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
  1.1956 +                newstroke = false;
  1.1957 +                !stroke && (newstroke = stroke = createNode("stroke"));
  1.1958 +                if ((params.stroke && params.stroke != "none") ||
  1.1959 +                    params["stroke-width"] ||
  1.1960 +                    params["stroke-opacity"] != null ||
  1.1961 +                    params["stroke-dasharray"] ||
  1.1962 +                    params["stroke-miterlimit"] ||
  1.1963 +                    params["stroke-linejoin"] ||
  1.1964 +                    params["stroke-linecap"]) {
  1.1965 +                    stroke.on = true;
  1.1966 +                }
  1.1967 +                (params.stroke == "none" || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
  1.1968 +                var strokeColor = R.getRGB(params.stroke);
  1.1969 +                stroke.on && params.stroke && (stroke.color = strokeColor.hex);
  1.1970 +                opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
  1.1971 +                var width = (toFloat(params["stroke-width"]) || 1) * .75;
  1.1972 +                opacity < 0 && (opacity = 0);
  1.1973 +                opacity > 1 && (opacity = 1);
  1.1974 +                params["stroke-width"] == null && (width = a["stroke-width"]);
  1.1975 +                params["stroke-width"] && (stroke.weight = width);
  1.1976 +                width && width < 1 && (opacity *= width) && (stroke.weight = 1);
  1.1977 +                stroke.opacity = opacity;
  1.1978 +                
  1.1979 +                params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
  1.1980 +                stroke.miterlimit = params["stroke-miterlimit"] || 8;
  1.1981 +                params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
  1.1982 +                if (params["stroke-dasharray"]) {
  1.1983 +                    var dasharray = {
  1.1984 +                        "-": "shortdash",
  1.1985 +                        ".": "shortdot",
  1.1986 +                        "-.": "shortdashdot",
  1.1987 +                        "-..": "shortdashdotdot",
  1.1988 +                        ". ": "dot",
  1.1989 +                        "- ": "dash",
  1.1990 +                        "--": "longdash",
  1.1991 +                        "- .": "dashdot",
  1.1992 +                        "--.": "longdashdot",
  1.1993 +                        "--..": "longdashdotdot"
  1.1994 +                    };
  1.1995 +                    stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
  1.1996 +                }
  1.1997 +                newstroke && node[appendChild](stroke);
  1.1998 +            }
  1.1999 +            if (res.type == "text") {
  1.2000 +                s = res.paper.span.style;
  1.2001 +                a.font && (s.font = a.font);
  1.2002 +                a["font-family"] && (s.fontFamily = a["font-family"]);
  1.2003 +                a["font-size"] && (s.fontSize = a["font-size"]);
  1.2004 +                a["font-weight"] && (s.fontWeight = a["font-weight"]);
  1.2005 +                a["font-style"] && (s.fontStyle = a["font-style"]);
  1.2006 +                res.node.string && (res.paper.span.innerHTML = Str(res.node.string)[rp](/</g, "&#60;")[rp](/&/g, "&#38;")[rp](/\n/g, "<br>"));
  1.2007 +                res.W = a.w = res.paper.span.offsetWidth;
  1.2008 +                res.H = a.h = res.paper.span.offsetHeight;
  1.2009 +                res.X = a.x;
  1.2010 +                res.Y = a.y + round(res.H / 2);
  1.2011 + 
  1.2012 +                // text-anchor emulationm
  1.2013 +                switch (a["text-anchor"]) {
  1.2014 +                    case "start":
  1.2015 +                        res.node.style["v-text-align"] = "left";
  1.2016 +                        res.bbx = round(res.W / 2);
  1.2017 +                    break;
  1.2018 +                    case "end":
  1.2019 +                        res.node.style["v-text-align"] = "right";
  1.2020 +                        res.bbx = -round(res.W / 2);
  1.2021 +                    break;
  1.2022 +                    default:
  1.2023 +                        res.node.style["v-text-align"] = "center";
  1.2024 +                    break;
  1.2025 +                }
  1.2026 +            }
  1.2027 +        };
  1.2028 +        addGradientFill = function (o, gradient) {
  1.2029 +            o.attrs = o.attrs || {};
  1.2030 +            var attrs = o.attrs,
  1.2031 +                fill,
  1.2032 +                type = "linear",
  1.2033 +                fxfy = ".5 .5";
  1.2034 +            o.attrs.gradient = gradient;
  1.2035 +            gradient = Str(gradient)[rp](radial_gradient, function (all, fx, fy) {
  1.2036 +                type = "radial";
  1.2037 +                if (fx && fy) {
  1.2038 +                    fx = toFloat(fx);
  1.2039 +                    fy = toFloat(fy);
  1.2040 +                    pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
  1.2041 +                    fxfy = fx + S + fy;
  1.2042 +                }
  1.2043 +                return E;
  1.2044 +            });
  1.2045 +            gradient = gradient[split](/\s*\-\s*/);
  1.2046 +            if (type == "linear") {
  1.2047 +                var angle = gradient.shift();
  1.2048 +                angle = -toFloat(angle);
  1.2049 +                if (isNaN(angle)) {
  1.2050 +                    return null;
  1.2051 +                }
  1.2052 +            }
  1.2053 +            var dots = parseDots(gradient);
  1.2054 +            if (!dots) {
  1.2055 +                return null;
  1.2056 +            }
  1.2057 +            o = o.shape || o.node;
  1.2058 +            fill = o.getElementsByTagName(fillString)[0] || createNode(fillString);
  1.2059 +            !fill.parentNode && o.appendChild(fill);
  1.2060 +            if (dots[length]) {
  1.2061 +                fill.on = true;
  1.2062 +                fill.method = "none";
  1.2063 +                fill.color = dots[0].color;
  1.2064 +                fill.color2 = dots[dots[length] - 1].color;
  1.2065 +                var clrs = [];
  1.2066 +                for (var i = 0, ii = dots[length]; i < ii; i++) {
  1.2067 +                    dots[i].offset && clrs[push](dots[i].offset + S + dots[i].color);
  1.2068 +                }
  1.2069 +                fill.colors && (fill.colors.value = clrs[length] ? clrs[join]() : "0% " + fill.color);
  1.2070 +                if (type == "radial") {
  1.2071 +                    fill.type = "gradientradial";
  1.2072 +                    fill.focus = "100%";
  1.2073 +                    fill.focussize = fxfy;
  1.2074 +                    fill.focusposition = fxfy;
  1.2075 +                } else {
  1.2076 +                    fill.type = "gradient";
  1.2077 +                    fill.angle = (270 - angle) % 360;
  1.2078 +                }
  1.2079 +            }
  1.2080 +            return 1;
  1.2081 +        };
  1.2082 +        Element = function (node, group, vml) {
  1.2083 +            var Rotation = 0,
  1.2084 +                RotX = 0,
  1.2085 +                RotY = 0,
  1.2086 +                Scale = 1;
  1.2087 +            this[0] = node;
  1.2088 +            this.id = R._oid++;
  1.2089 +            this.node = node;
  1.2090 +            node.raphael = this;
  1.2091 +            this.X = 0;
  1.2092 +            this.Y = 0;
  1.2093 +            this.attrs = {};
  1.2094 +            this.Group = group;
  1.2095 +            this.paper = vml;
  1.2096 +            this._ = {
  1.2097 +                tx: 0,
  1.2098 +                ty: 0,
  1.2099 +                rt: {deg:0},
  1.2100 +                sx: 1,
  1.2101 +                sy: 1
  1.2102 +            };
  1.2103 +            !vml.bottom && (vml.bottom = this);
  1.2104 +            this.prev = vml.top;
  1.2105 +            vml.top && (vml.top.next = this);
  1.2106 +            vml.top = this;
  1.2107 +            this.next = null;
  1.2108 +        };
  1.2109 +        Element[proto].rotate = function (deg, cx, cy) {
  1.2110 +            if (this.removed) {
  1.2111 +                return this;
  1.2112 +            }
  1.2113 +            if (deg == null) {
  1.2114 +                if (this._.rt.cx) {
  1.2115 +                    return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
  1.2116 +                }
  1.2117 +                return this._.rt.deg;
  1.2118 +            }
  1.2119 +            deg = Str(deg)[split](separator);
  1.2120 +            if (deg[length] - 1) {
  1.2121 +                cx = toFloat(deg[1]);
  1.2122 +                cy = toFloat(deg[2]);
  1.2123 +            }
  1.2124 +            deg = toFloat(deg[0]);
  1.2125 +            if (cx != null) {
  1.2126 +                this._.rt.deg = deg;
  1.2127 +            } else {
  1.2128 +                this._.rt.deg += deg;
  1.2129 +            }
  1.2130 +            cy == null && (cx = null);
  1.2131 +            this._.rt.cx = cx;
  1.2132 +            this._.rt.cy = cy;
  1.2133 +            this.setBox(this.attrs, cx, cy);
  1.2134 +            this.Group.style.rotation = this._.rt.deg;
  1.2135 +            // gradient fix for rotation. TODO
  1.2136 +            // var fill = (this.shape || this.node).getElementsByTagName(fillString);
  1.2137 +            // fill = fill[0] || {};
  1.2138 +            // var b = ((360 - this._.rt.deg) - 270) % 360;
  1.2139 +            // !R.is(fill.angle, "undefined") && (fill.angle = b);
  1.2140 +            return this;
  1.2141 +        };
  1.2142 +        Element[proto].setBox = function (params, cx, cy) {
  1.2143 +            if (this.removed) {
  1.2144 +                return this;
  1.2145 +            }
  1.2146 +            var gs = this.Group.style,
  1.2147 +                os = (this.shape && this.shape.style) || this.node.style;
  1.2148 +            params = params || {};
  1.2149 +            for (var i in params) if (params[has](i)) {
  1.2150 +                this.attrs[i] = params[i];
  1.2151 +            }
  1.2152 +            cx = cx || this._.rt.cx;
  1.2153 +            cy = cy || this._.rt.cy;
  1.2154 +            var attr = this.attrs,
  1.2155 +                x,
  1.2156 +                y,
  1.2157 +                w,
  1.2158 +                h;
  1.2159 +            switch (this.type) {
  1.2160 +                case "circle":
  1.2161 +                    x = attr.cx - attr.r;
  1.2162 +                    y = attr.cy - attr.r;
  1.2163 +                    w = h = attr.r * 2;
  1.2164 +                    break;
  1.2165 +                case "ellipse":
  1.2166 +                    x = attr.cx - attr.rx;
  1.2167 +                    y = attr.cy - attr.ry;
  1.2168 +                    w = attr.rx * 2;
  1.2169 +                    h = attr.ry * 2;
  1.2170 +                    break;
  1.2171 +                case "image":
  1.2172 +                    x = +attr.x;
  1.2173 +                    y = +attr.y;
  1.2174 +                    w = attr.width || 0;
  1.2175 +                    h = attr.height || 0;
  1.2176 +                    break;
  1.2177 +                case "text":
  1.2178 +                    this.textpath.v = ["m", round(attr.x), ", ", round(attr.y - 2), "l", round(attr.x) + 1, ", ", round(attr.y - 2)][join](E);
  1.2179 +                    x = attr.x - round(this.W / 2);
  1.2180 +                    y = attr.y - this.H / 2;
  1.2181 +                    w = this.W;
  1.2182 +                    h = this.H;
  1.2183 +                    break;
  1.2184 +                case "rect":
  1.2185 +                case "path":
  1.2186 +                    if (!this.attrs.path) {
  1.2187 +                        x = 0;
  1.2188 +                        y = 0;
  1.2189 +                        w = this.paper.width;
  1.2190 +                        h = this.paper.height;
  1.2191 +                    } else {
  1.2192 +                        var dim = pathDimensions(this.attrs.path);
  1.2193 +                        x = dim.x;
  1.2194 +                        y = dim.y;
  1.2195 +                        w = dim.width;
  1.2196 +                        h = dim.height;
  1.2197 +                    }
  1.2198 +                    break;
  1.2199 +                default:
  1.2200 +                    x = 0;
  1.2201 +                    y = 0;
  1.2202 +                    w = this.paper.width;
  1.2203 +                    h = this.paper.height;
  1.2204 +                    break;
  1.2205 +            }
  1.2206 +            cx = (cx == null) ? x + w / 2 : cx;
  1.2207 +            cy = (cy == null) ? y + h / 2 : cy;
  1.2208 +            var left = cx - this.paper.width / 2,
  1.2209 +                top = cy - this.paper.height / 2, t;
  1.2210 +            gs.left != (t = left + "px") && (gs.left = t);
  1.2211 +            gs.top != (t = top + "px") && (gs.top = t);
  1.2212 +            this.X = pathlike[has](this.type) ? -left : x;
  1.2213 +            this.Y = pathlike[has](this.type) ? -top : y;
  1.2214 +            this.W = w;
  1.2215 +            this.H = h;
  1.2216 +            if (pathlike[has](this.type)) {
  1.2217 +                os.left != (t = -left * zoom + "px") && (os.left = t);
  1.2218 +                os.top != (t = -top * zoom + "px") && (os.top = t);
  1.2219 +            } else if (this.type == "text") {
  1.2220 +                os.left != (t = -left + "px") && (os.left = t);
  1.2221 +                os.top != (t = -top + "px") && (os.top = t);
  1.2222 +            } else {
  1.2223 +                gs.width != (t = this.paper.width + "px") && (gs.width = t);
  1.2224 +                gs.height != (t = this.paper.height + "px") && (gs.height = t);
  1.2225 +                os.left != (t = x - left + "px") && (os.left = t);
  1.2226 +                os.top != (t = y - top + "px") && (os.top = t);
  1.2227 +                os.width != (t = w + "px") && (os.width = t);
  1.2228 +                os.height != (t = h + "px") && (os.height = t);
  1.2229 +            }
  1.2230 +        };
  1.2231 +        Element[proto].hide = function () {
  1.2232 +            !this.removed && (this.Group.style.display = "none");
  1.2233 +            return this;
  1.2234 +        };
  1.2235 +        Element[proto].show = function () {
  1.2236 +            !this.removed && (this.Group.style.display = "block");
  1.2237 +            return this;
  1.2238 +        };
  1.2239 +        Element[proto].getBBox = function () {
  1.2240 +            if (this.removed) {
  1.2241 +                return this;
  1.2242 +            }
  1.2243 +            if (pathlike[has](this.type)) {
  1.2244 +                return pathDimensions(this.attrs.path);
  1.2245 +            }
  1.2246 +            return {
  1.2247 +                x: this.X + (this.bbx || 0),
  1.2248 +                y: this.Y,
  1.2249 +                width: this.W,
  1.2250 +                height: this.H
  1.2251 +            };
  1.2252 +        };
  1.2253 +        Element[proto].remove = function () {
  1.2254 +            if (this.removed) {
  1.2255 +                return;
  1.2256 +            }
  1.2257 +            tear(this, this.paper);
  1.2258 +            this.node.parentNode.removeChild(this.node);
  1.2259 +            this.Group.parentNode.removeChild(this.Group);
  1.2260 +            this.shape && this.shape.parentNode.removeChild(this.shape);
  1.2261 +            for (var i in this) {
  1.2262 +                delete this[i];
  1.2263 +            }
  1.2264 +            this.removed = true;
  1.2265 +        };
  1.2266 +        Element[proto].attr = function (name, value) {
  1.2267 +            if (this.removed) {
  1.2268 +                return this;
  1.2269 +            }
  1.2270 +            if (name == null) {
  1.2271 +                var res = {};
  1.2272 +                for (var i in this.attrs) if (this.attrs[has](i)) {
  1.2273 +                    res[i] = this.attrs[i];
  1.2274 +                }
  1.2275 +                this._.rt.deg && (res.rotation = this.rotate());
  1.2276 +                (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
  1.2277 +                res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
  1.2278 +                return res;
  1.2279 +            }
  1.2280 +            if (value == null && R.is(name, string)) {
  1.2281 +                if (name == "translation") {
  1.2282 +                    return translate.call(this);
  1.2283 +                }
  1.2284 +                if (name == "rotation") {
  1.2285 +                    return this.rotate();
  1.2286 +                }
  1.2287 +                if (name == "scale") {
  1.2288 +                    return this.scale();
  1.2289 +                }
  1.2290 +                if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
  1.2291 +                    return this.attrs.gradient;
  1.2292 +                }
  1.2293 +                return this.attrs[name];
  1.2294 +            }
  1.2295 +            if (this.attrs && value == null && R.is(name, array)) {
  1.2296 +                var ii, values = {};
  1.2297 +                for (i = 0, ii = name[length]; i < ii; i++) {
  1.2298 +                    values[name[i]] = this.attr(name[i]);
  1.2299 +                }
  1.2300 +                return values;
  1.2301 +            }
  1.2302 +            var params;
  1.2303 +            if (value != null) {
  1.2304 +                params = {};
  1.2305 +                params[name] = value;
  1.2306 +            }
  1.2307 +            value == null && R.is(name, "object") && (params = name);
  1.2308 +            if (params) {
  1.2309 +                if (params.text && this.type == "text") {
  1.2310 +                    this.node.string = params.text;
  1.2311 +                }
  1.2312 +                setFillAndStroke(this, params);
  1.2313 +                if (params.gradient && (({circle: 1, ellipse: 1})[has](this.type) || Str(params.gradient).charAt() != "r")) {
  1.2314 +                    addGradientFill(this, params.gradient);
  1.2315 +                }
  1.2316 +                (!pathlike[has](this.type) || this._.rt.deg) && this.setBox(this.attrs);
  1.2317 +            }
  1.2318 +            return this;
  1.2319 +        };
  1.2320 +        Element[proto].toFront = function () {
  1.2321 +            !this.removed && this.Group.parentNode[appendChild](this.Group);
  1.2322 +            this.paper.top != this && tofront(this, this.paper);
  1.2323 +            return this;
  1.2324 +        };
  1.2325 +        Element[proto].toBack = function () {
  1.2326 +            if (this.removed) {
  1.2327 +                return this;
  1.2328 +            }
  1.2329 +            if (this.Group.parentNode.firstChild != this.Group) {
  1.2330 +                this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
  1.2331 +                toback(this, this.paper);
  1.2332 +            }
  1.2333 +            return this;
  1.2334 +        };
  1.2335 +        Element[proto].insertAfter = function (element) {
  1.2336 +            if (this.removed) {
  1.2337 +                return this;
  1.2338 +            }
  1.2339 +            if (element.constructor == Set) {
  1.2340 +                element = element[element.length];
  1.2341 +            }
  1.2342 +            if (element.Group.nextSibling) {
  1.2343 +                element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
  1.2344 +            } else {
  1.2345 +                element.Group.parentNode[appendChild](this.Group);
  1.2346 +            }
  1.2347 +            insertafter(this, element, this.paper);
  1.2348 +            return this;
  1.2349 +        };
  1.2350 +        Element[proto].insertBefore = function (element) {
  1.2351 +            if (this.removed) {
  1.2352 +                return this;
  1.2353 +            }
  1.2354 +            if (element.constructor == Set) {
  1.2355 +                element = element[0];
  1.2356 +            }
  1.2357 +            element.Group.parentNode.insertBefore(this.Group, element.Group);
  1.2358 +            insertbefore(this, element, this.paper);
  1.2359 +            return this;
  1.2360 +        };
  1.2361 +        var blurregexp = / progid:\S+Blur\([^\)]+\)/g;
  1.2362 +        Element[proto].blur = function (size) {
  1.2363 +            var s = this.node.runtimeStyle,
  1.2364 +                f = s.filter;
  1.2365 +            f = f.replace(blurregexp, E);
  1.2366 +            if (+size !== 0) {
  1.2367 +                this.attrs.blur = size;
  1.2368 +                s.filter = f + S + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
  1.2369 +                s.margin = R.format("-{0}px 0 0 -{0}px", round(+size || 1.5));
  1.2370 +            } else {
  1.2371 +                s.filter = f;
  1.2372 +                s.margin = 0;
  1.2373 +                delete this.attrs.blur;
  1.2374 +            }
  1.2375 +        };
  1.2376 + 
  1.2377 +        theCircle = function (vml, x, y, r) {
  1.2378 +            var g = createNode("group"),
  1.2379 +                o = createNode("oval"),
  1.2380 +                ol = o.style;
  1.2381 +            g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
  1.2382 +            g.coordsize = coordsize;
  1.2383 +            g.coordorigin = vml.coordorigin;
  1.2384 +            g[appendChild](o);
  1.2385 +            var res = new Element(o, g, vml);
  1.2386 +            res.type = "circle";
  1.2387 +            setFillAndStroke(res, {stroke: "#000", fill: "none"});
  1.2388 +            res.attrs.cx = x;
  1.2389 +            res.attrs.cy = y;
  1.2390 +            res.attrs.r = r;
  1.2391 +            res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
  1.2392 +            vml.canvas[appendChild](g);
  1.2393 +            return res;
  1.2394 +        };
  1.2395 +        function rectPath(x, y, w, h, r) {
  1.2396 +            if (r) {
  1.2397 +                return R.format("M{0},{1}l{2},0a{3},{3},0,0,1,{3},{3}l0,{5}a{3},{3},0,0,1,{4},{3}l{6},0a{3},{3},0,0,1,{4},{4}l0,{7}a{3},{3},0,0,1,{3},{4}z", x + r, y, w - r * 2, r, -r, h - r * 2, r * 2 - w, r * 2 - h);
  1.2398 +            } else {
  1.2399 +                return R.format("M{0},{1}l{2},0,0,{3},{4},0z", x, y, w, h, -w);
  1.2400 +            }
  1.2401 +        }
  1.2402 +        theRect = function (vml, x, y, w, h, r) {
  1.2403 +            var path = rectPath(x, y, w, h, r),
  1.2404 +                res = vml.path(path),
  1.2405 +                a = res.attrs;
  1.2406 +            res.X = a.x = x;
  1.2407 +            res.Y = a.y = y;
  1.2408 +            res.W = a.width = w;
  1.2409 +            res.H = a.height = h;
  1.2410 +            a.r = r;
  1.2411 +            a.path = path;
  1.2412 +            res.type = "rect";
  1.2413 +            return res;
  1.2414 +        };
  1.2415 +        theEllipse = function (vml, x, y, rx, ry) {
  1.2416 +            var g = createNode("group"),
  1.2417 +                o = createNode("oval"),
  1.2418 +                ol = o.style;
  1.2419 +            g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
  1.2420 +            g.coordsize = coordsize;
  1.2421 +            g.coordorigin = vml.coordorigin;
  1.2422 +            g[appendChild](o);
  1.2423 +            var res = new Element(o, g, vml);
  1.2424 +            res.type = "ellipse";
  1.2425 +            setFillAndStroke(res, {stroke: "#000"});
  1.2426 +            res.attrs.cx = x;
  1.2427 +            res.attrs.cy = y;
  1.2428 +            res.attrs.rx = rx;
  1.2429 +            res.attrs.ry = ry;
  1.2430 +            res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
  1.2431 +            vml.canvas[appendChild](g);
  1.2432 +            return res;
  1.2433 +        };
  1.2434 +        theImage = function (vml, src, x, y, w, h) {
  1.2435 +            var g = createNode("group"),
  1.2436 +                o = createNode("image"),
  1.2437 +                ol = o.style;
  1.2438 +            g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
  1.2439 +            g.coordsize = coordsize;
  1.2440 +            g.coordorigin = vml.coordorigin;
  1.2441 +            o.src = src;
  1.2442 +            g[appendChild](o);
  1.2443 +            var res = new Element(o, g, vml);
  1.2444 +            res.type = "image";
  1.2445 +            res.attrs.src = src;
  1.2446 +            res.attrs.x = x;
  1.2447 +            res.attrs.y = y;
  1.2448 +            res.attrs.w = w;
  1.2449 +            res.attrs.h = h;
  1.2450 +            res.setBox({x: x, y: y, width: w, height: h});
  1.2451 +            vml.canvas[appendChild](g);
  1.2452 +            return res;
  1.2453 +        };
  1.2454 +        theText = function (vml, x, y, text) {
  1.2455 +            var g = createNode("group"),
  1.2456 +                el = createNode("shape"),
  1.2457 +                ol = el.style,
  1.2458 +                path = createNode("path"),
  1.2459 +                ps = path.style,
  1.2460 +                o = createNode("textpath");
  1.2461 +            g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
  1.2462 +            g.coordsize = coordsize;
  1.2463 +            g.coordorigin = vml.coordorigin;
  1.2464 +            path.v = R.format("m{0},{1}l{2},{1}", round(x * 10), round(y * 10), round(x * 10) + 1);
  1.2465 +            path.textpathok = true;
  1.2466 +            ol.width = vml.width;
  1.2467 +            ol.height = vml.height;
  1.2468 +            o.string = Str(text);
  1.2469 +            o.on = true;
  1.2470 +            el[appendChild](o);
  1.2471 +            el[appendChild](path);
  1.2472 +            g[appendChild](el);
  1.2473 +            var res = new Element(o, g, vml);
  1.2474 +            res.shape = el;
  1.2475 +            res.textpath = path;
  1.2476 +            res.type = "text";
  1.2477 +            res.attrs.text = text;
  1.2478 +            res.attrs.x = x;
  1.2479 +            res.attrs.y = y;
  1.2480 +            res.attrs.w = 1;
  1.2481 +            res.attrs.h = 1;
  1.2482 +            setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
  1.2483 +            res.setBox();
  1.2484 +            vml.canvas[appendChild](g);
  1.2485 +            return res;
  1.2486 +        };
  1.2487 +        setSize = function (width, height) {
  1.2488 +            var cs = this.canvas.style;
  1.2489 +            width == +width && (width += "px");
  1.2490 +            height == +height && (height += "px");
  1.2491 +            cs.width = width;
  1.2492 +            cs.height = height;
  1.2493 +            cs.clip = "rect(0 " + width + " " + height + " 0)";
  1.2494 +            return this;
  1.2495 +        };
  1.2496 +        var createNode;
  1.2497 +        doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
  1.2498 +        try {
  1.2499 +            !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
  1.2500 +            createNode = function (tagName) {
  1.2501 +                return doc.createElement('<rvml:' + tagName + ' class="rvml">');
  1.2502 +            };
  1.2503 +        } catch (e) {
  1.2504 +            createNode = function (tagName) {
  1.2505 +                return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
  1.2506 +            };
  1.2507 +        }
  1.2508 +        create = function () {
  1.2509 +            var con = getContainer[apply](0, arguments),
  1.2510 +                container = con.container,
  1.2511 +                height = con.height,
  1.2512 +                s,
  1.2513 +                width = con.width,
  1.2514 +                x = con.x,
  1.2515 +                y = con.y;
  1.2516 +            if (!container) {
  1.2517 +                throw new Error("VML container not found.");
  1.2518 +            }
  1.2519 +            var res = new Paper,
  1.2520 +                c = res.canvas = doc.createElement("div"),
  1.2521 +                cs = c.style;
  1.2522 +            x = x || 0;
  1.2523 +            y = y || 0;
  1.2524 +            width = width || 512;
  1.2525 +            height = height || 342;
  1.2526 +            width == +width && (width += "px");
  1.2527 +            height == +height && (height += "px");
  1.2528 +            res.width = 1e3;
  1.2529 +            res.height = 1e3;
  1.2530 +            res.coordsize = zoom * 1e3 + S + zoom * 1e3;
  1.2531 +            res.coordorigin = "0 0";
  1.2532 +            res.span = doc.createElement("span");
  1.2533 +            res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
  1.2534 +            c[appendChild](res.span);
  1.2535 +            cs.cssText = R.format("width:{0};height:{1};display:inline-block;position:relative;clip:rect(0 {0} {1} 0);overflow:hidden", width, height);
  1.2536 +            if (container == 1) {
  1.2537 +                doc.body[appendChild](c);
  1.2538 +                cs.left = x + "px";
  1.2539 +                cs.top = y + "px";
  1.2540 +                cs.position = "absolute";
  1.2541 +            } else {
  1.2542 +                if (container.firstChild) {
  1.2543 +                    container.insertBefore(c, container.firstChild);
  1.2544 +                } else {
  1.2545 +                    container[appendChild](c);
  1.2546 +                }
  1.2547 +            }
  1.2548 +            plugins.call(res, res, R.fn);
  1.2549 +            return res;
  1.2550 +        };
  1.2551 +        Paper[proto].clear = function () {
  1.2552 +            this.canvas.innerHTML = E;
  1.2553 +            this.span = doc.createElement("span");
  1.2554 +            this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
  1.2555 +            this.canvas[appendChild](this.span);
  1.2556 +            this.bottom = this.top = null;
  1.2557 +        };
  1.2558 +        Paper[proto].remove = function () {
  1.2559 +            this.canvas.parentNode.removeChild(this.canvas);
  1.2560 +            for (var i in this) {
  1.2561 +                this[i] = removed(i);
  1.2562 +            }
  1.2563 +            return true;
  1.2564 +        };
  1.2565 +    }
  1.2566 + 
  1.2567 +    // rest
  1.2568 +    // WebKit rendering bug workaround method
  1.2569 +    if ((navigator.vendor == "Apple Computer, Inc.") && (navigator.userAgent.match(/Version\/(.*?)\s/)[1] < 4 || win.navigator.platform.slice(0, 2) == "iP")) {
  1.2570 +        Paper[proto].safari = function () {
  1.2571 +            var rect = this.rect(-99, -99, this.width + 99, this.height + 99).attr({stroke: "none"});
  1.2572 +            win.setTimeout(function () {rect.remove();});
  1.2573 +        };
  1.2574 +    } else {
  1.2575 +        Paper[proto].safari = function () {};
  1.2576 +    }
  1.2577 + 
  1.2578 +    // Events
  1.2579 +    var preventDefault = function () {
  1.2580 +        this.returnValue = false;
  1.2581 +    },
  1.2582 +    preventTouch = function () {
  1.2583 +        return this.originalEvent.preventDefault();
  1.2584 +    },
  1.2585 +    stopPropagation = function () {
  1.2586 +        this.cancelBubble = true;
  1.2587 +    },
  1.2588 +    stopTouch = function () {
  1.2589 +        return this.originalEvent.stopPropagation();
  1.2590 +    },
  1.2591 +    addEvent = (function () {
  1.2592 +        if (doc.addEventListener) {
  1.2593 +            return function (obj, type, fn, element) {
  1.2594 +                var realName = supportsTouch && touchMap[type] ? touchMap[type] : type;
  1.2595 +                var f = function (e) {
  1.2596 +                    if (supportsTouch && touchMap[has](type)) {
  1.2597 +                        for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
  1.2598 +                            if (e.targetTouches[i].target == obj) {
  1.2599 +                                var olde = e;
  1.2600 +                                e = e.targetTouches[i];
  1.2601 +                                e.originalEvent = olde;
  1.2602 +                                e.preventDefault = preventTouch;
  1.2603 +                                e.stopPropagation = stopTouch;
  1.2604 +                                break;
  1.2605 +                            }
  1.2606 +                        }
  1.2607 +                    }
  1.2608 +                    return fn.call(element, e);
  1.2609 +                };
  1.2610 +                obj.addEventListener(realName, f, false);
  1.2611 +                return function () {
  1.2612 +                    obj.removeEventListener(realName, f, false);
  1.2613 +                    return true;
  1.2614 +                };
  1.2615 +            };
  1.2616 +        } else if (doc.attachEvent) {
  1.2617 +            return function (obj, type, fn, element) {
  1.2618 +                var f = function (e) {
  1.2619 +                    e = e || win.event;
  1.2620 +                    e.preventDefault = e.preventDefault || preventDefault;
  1.2621 +                    e.stopPropagation = e.stopPropagation || stopPropagation;
  1.2622 +                    return fn.call(element, e);
  1.2623 +                };
  1.2624 +                obj.attachEvent("on" + type, f);
  1.2625 +                var detacher = function () {
  1.2626 +                    obj.detachEvent("on" + type, f);
  1.2627 +                    return true;
  1.2628 +                };
  1.2629 +                return detacher;
  1.2630 +            };
  1.2631 +        }
  1.2632 +    })(),
  1.2633 +    drag = [],
  1.2634 +    dragMove = function (e) {
  1.2635 +        var x = e.clientX,
  1.2636 +            y = e.clientY,
  1.2637 +            dragi,
  1.2638 +            j = drag.length;
  1.2639 +        while (j--) {
  1.2640 +            dragi = drag[j];
  1.2641 +            if (supportsTouch) {
  1.2642 +                var i = e.touches.length,
  1.2643 +                    touch;
  1.2644 +                while (i--) {
  1.2645 +                    touch = e.touches[i];
  1.2646 +                    if (touch.identifier == dragi.el._drag.id) {
  1.2647 +                        x = touch.clientX;
  1.2648 +                        y = touch.clientY;
  1.2649 +                        (e.originalEvent ? e.originalEvent : e).preventDefault();
  1.2650 +                        break;
  1.2651 +                    }
  1.2652 +                }
  1.2653 +            } else {
  1.2654 +                e.preventDefault();
  1.2655 +            }
  1.2656 +            dragi.move && dragi.move.call(dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y);
  1.2657 +        }
  1.2658 +    },
  1.2659 +    dragUp = function () {
  1.2660 +        R.unmousemove(dragMove).unmouseup(dragUp);
  1.2661 +        var i = drag.length,
  1.2662 +            dragi;
  1.2663 +        while (i--) {
  1.2664 +            dragi = drag[i];
  1.2665 +            dragi.el._drag = {};
  1.2666 +            dragi.end && dragi.end.call(dragi.el);
  1.2667 +        }
  1.2668 +        drag = [];
  1.2669 +    };
  1.2670 +    for (var i = events[length]; i--;) {
  1.2671 +        (function (eventName) {
  1.2672 +            R[eventName] = Element[proto][eventName] = function (fn) {
  1.2673 +                if (R.is(fn, "function")) {
  1.2674 +                    this.events = this.events || [];
  1.2675 +                    this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || doc, eventName, fn, this)});
  1.2676 +                }
  1.2677 +                return this;
  1.2678 +            };
  1.2679 +            R["un" + eventName] = Element[proto]["un" + eventName] = function (fn) {
  1.2680 +                var events = this.events,
  1.2681 +                    l = events[length];
  1.2682 +                while (l--) if (events[l].name == eventName && events[l].f == fn) {
  1.2683 +                    events[l].unbind();
  1.2684 +                    events.splice(l, 1);
  1.2685 +                    !events.length && delete this.events;
  1.2686 +                    return this;
  1.2687 +                }
  1.2688 +                return this;
  1.2689 +            };
  1.2690 +        })(events[i]);
  1.2691 +    }
  1.2692 +    Element[proto].hover = function (f_in, f_out) {
  1.2693 +        return this.mouseover(f_in).mouseout(f_out);
  1.2694 +    };
  1.2695 +    Element[proto].unhover = function (f_in, f_out) {
  1.2696 +        return this.unmouseover(f_in).unmouseout(f_out);
  1.2697 +    };
  1.2698 +    Element[proto].drag = function (onmove, onstart, onend) {
  1.2699 +        this._drag = {};
  1.2700 +        this.mousedown(function (e) {
  1.2701 +            (e.originalEvent || e).preventDefault();
  1.2702 +            this._drag.x = e.clientX;
  1.2703 +            this._drag.y = e.clientY;
  1.2704 +            this._drag.id = e.identifier;
  1.2705 +            onstart && onstart.call(this, e.clientX, e.clientY);
  1.2706 +            !drag.length && R.mousemove(dragMove).mouseup(dragUp);
  1.2707 +            drag.push({el: this, move: onmove, end: onend});
  1.2708 +        });
  1.2709 +        return this;
  1.2710 +    };
  1.2711 +    Element[proto].undrag = function (onmove, onstart, onend) {
  1.2712 +        var i = drag.length;
  1.2713 +        while (i--) {
  1.2714 +            drag[i].el == this && (drag[i].move == onmove && drag[i].end == onend) && drag.splice(i, 1);
  1.2715 +            !drag.length && R.unmousemove(dragMove).unmouseup(dragUp);
  1.2716 +        }
  1.2717 +    };
  1.2718 +    Paper[proto].circle = function (x, y, r) {
  1.2719 +        return theCircle(this, x || 0, y || 0, r || 0);
  1.2720 +    };
  1.2721 +    Paper[proto].rect = function (x, y, w, h, r) {
  1.2722 +        return theRect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
  1.2723 +    };
  1.2724 +    Paper[proto].ellipse = function (x, y, rx, ry) {
  1.2725 +        return theEllipse(this, x || 0, y || 0, rx || 0, ry || 0);
  1.2726 +    };
  1.2727 +    Paper[proto].path = function (pathString) {
  1.2728 +        pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
  1.2729 +        return thePath(R.format[apply](R, arguments), this);
  1.2730 +    };
  1.2731 +    Paper[proto].image = function (src, x, y, w, h) {
  1.2732 +        return theImage(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
  1.2733 +    };
  1.2734 +    Paper[proto].text = function (x, y, text) {
  1.2735 +        return theText(this, x || 0, y || 0, text || E);
  1.2736 +    };
  1.2737 +    Paper[proto].set = function (itemsArray) {
  1.2738 +        arguments[length] > 1 && (itemsArray = Array[proto].splice.call(arguments, 0, arguments[length]));
  1.2739 +        return new Set(itemsArray);
  1.2740 +    };
  1.2741 +    Paper[proto].setSize = setSize;
  1.2742 +    Paper[proto].top = Paper[proto].bottom = null;
  1.2743 +    Paper[proto].raphael = R;
  1.2744 +    function x_y() {
  1.2745 +        return this.x + S + this.y;
  1.2746 +    }
  1.2747 +    Element[proto].resetScale = function () {
  1.2748 +        if (this.removed) {
  1.2749 +            return this;
  1.2750 +        }
  1.2751 +        this._.sx = 1;
  1.2752 +        this._.sy = 1;
  1.2753 +        this.attrs.scale = "1 1";
  1.2754 +    };
  1.2755 +    Element[proto].scale = function (x, y, cx, cy) {
  1.2756 +        if (this.removed) {
  1.2757 +            return this;
  1.2758 +        }
  1.2759 +        if (x == null && y == null) {
  1.2760 +            return {
  1.2761 +                x: this._.sx,
  1.2762 +                y: this._.sy,
  1.2763 +                toString: x_y
  1.2764 +            };
  1.2765 +        }
  1.2766 +        y = y || x;
  1.2767 +        !+y && (y = x);
  1.2768 +        var dx,
  1.2769 +            dy,
  1.2770 +            dcx,
  1.2771 +            dcy,
  1.2772 +            a = this.attrs;
  1.2773 +        if (x != 0) {
  1.2774 +            var bb = this.getBBox(),
  1.2775 +                rcx = bb.x + bb.width / 2,
  1.2776 +                rcy = bb.y + bb.height / 2,
  1.2777 +                kx = x / this._.sx,
  1.2778 +                ky = y / this._.sy;
  1.2779 +            cx = (+cx || cx == 0) ? cx : rcx;
  1.2780 +            cy = (+cy || cy == 0) ? cy : rcy;
  1.2781 +            var dirx = ~~(x / math.abs(x)),
  1.2782 +                diry = ~~(y / math.abs(y)),
  1.2783 +                s = this.node.style,
  1.2784 +                ncx = cx + (rcx - cx) * kx,
  1.2785 +                ncy = cy + (rcy - cy) * ky;
  1.2786 +            switch (this.type) {
  1.2787 +                case "rect":
  1.2788 +                case "image":
  1.2789 +                    var neww = a.width * dirx * kx,
  1.2790 +                        newh = a.height * diry * ky;
  1.2791 +                    this.attr({
  1.2792 +                        height: newh,
  1.2793 +                        r: a.r * mmin(dirx * kx, diry * ky),
  1.2794 +                        width: neww,
  1.2795 +                        x: ncx - neww / 2,
  1.2796 +                        y: ncy - newh / 2
  1.2797 +                    });
  1.2798 +                    break;
  1.2799 +                case "circle":
  1.2800 +                case "ellipse":
  1.2801 +                    this.attr({
  1.2802 +                        rx: a.rx * dirx * kx,
  1.2803 +                        ry: a.ry * diry * ky,
  1.2804 +                        r: a.r * mmin(dirx * kx, diry * ky),
  1.2805 +                        cx: ncx,
  1.2806 +                        cy: ncy
  1.2807 +                    });
  1.2808 +                    break;
  1.2809 +                case "text":
  1.2810 +                    this.attr({
  1.2811 +                        x: ncx,
  1.2812 +                        y: ncy
  1.2813 +                    });
  1.2814 +                    break;
  1.2815 +                case "path":
  1.2816 +                    var path = pathToRelative(a.path),
  1.2817 +                        skip = true;
  1.2818 +                    for (var i = 0, ii = path[length]; i < ii; i++) {
  1.2819 +                        var p = path[i],
  1.2820 +                            P0 = upperCase.call(p[0]);
  1.2821 +                        if (P0 == "M" && skip) {
  1.2822 +                            continue;
  1.2823 +                        } else {
  1.2824 +                            skip = false;
  1.2825 +                        }
  1.2826 +                        if (P0 == "A") {
  1.2827 +                            p[path[i][length] - 2] *= kx;
  1.2828 +                            p[path[i][length] - 1] *= ky;
  1.2829 +                            p[1] *= dirx * kx;
  1.2830 +                            p[2] *= diry * ky;
  1.2831 +                            p[5] = +!(dirx + diry ? !+p[5] : +p[5]);
  1.2832 +                        } else if (P0 == "H") {
  1.2833 +                            for (var j = 1, jj = p[length]; j < jj; j++) {
  1.2834 +                                p[j] *= kx;
  1.2835 +                            }
  1.2836 +                        } else if (P0 == "V") {
  1.2837 +                            for (j = 1, jj = p[length]; j < jj; j++) {
  1.2838 +                                p[j] *= ky;
  1.2839 +                            }
  1.2840 +                         } else {
  1.2841 +                            for (j = 1, jj = p[length]; j < jj; j++) {
  1.2842 +                                p[j] *= (j % 2) ? kx : ky;
  1.2843 +                            }
  1.2844 +                        }
  1.2845 +                    }
  1.2846 +                    var dim2 = pathDimensions(path);
  1.2847 +                    dx = ncx - dim2.x - dim2.width / 2;
  1.2848 +                    dy = ncy - dim2.y - dim2.height / 2;
  1.2849 +                    path[0][1] += dx;
  1.2850 +                    path[0][2] += dy;
  1.2851 +                    this.attr({path: path});
  1.2852 +                break;
  1.2853 +            }
  1.2854 +            if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
  1.2855 +                if (this.transformations) {
  1.2856 +                    this.transformations[2] = "scale("[concat](dirx, ",", diry, ")");
  1.2857 +                    this.node[setAttribute]("transform", this.transformations[join](S));
  1.2858 +                    dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
  1.2859 +                    dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
  1.2860 +                    this.attr({x: dx, y: dy});
  1.2861 +                    a.fx = dirx - 1;
  1.2862 +                    a.fy = diry - 1;
  1.2863 +                } else {
  1.2864 +                    this.node.filterMatrix = ms + ".Matrix(M11="[concat](dirx,
  1.2865 +                        ", M12=0, M21=0, M22=", diry,
  1.2866 +                        ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
  1.2867 +                    s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
  1.2868 +                }
  1.2869 +            } else {
  1.2870 +                if (this.transformations) {
  1.2871 +                    this.transformations[2] = E;
  1.2872 +                    this.node[setAttribute]("transform", this.transformations[join](S));
  1.2873 +                    a.fx = 0;
  1.2874 +                    a.fy = 0;
  1.2875 +                } else {
  1.2876 +                    this.node.filterMatrix = E;
  1.2877 +                    s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
  1.2878 +                }
  1.2879 +            }
  1.2880 +            a.scale = [x, y, cx, cy][join](S);
  1.2881 +            this._.sx = x;
  1.2882 +            this._.sy = y;
  1.2883 +        }
  1.2884 +        return this;
  1.2885 +    };
  1.2886 +    Element[proto].clone = function () {
  1.2887 +        if (this.removed) {
  1.2888 +            return null;
  1.2889 +        }
  1.2890 +        var attr = this.attr();
  1.2891 +        delete attr.scale;
  1.2892 +        delete attr.translation;
  1.2893 +        return this.paper[this.type]().attr(attr);
  1.2894 +    };
  1.2895 +    var getPointAtSegmentLength = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
  1.2896 +        var len = 0,
  1.2897 +            old;
  1.2898 +        for (var i = 0; i < 1.01; i+=.01) {
  1.2899 +            var dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i);
  1.2900 +            i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
  1.2901 +            if (len >= length) {
  1.2902 +                return dot;
  1.2903 +            }
  1.2904 +            old = dot;
  1.2905 +        }
  1.2906 +    }),
  1.2907 +    getLengthFactory = function (istotal, subpath) {
  1.2908 +        return function (path, length, onlystart) {
  1.2909 +            path = path2curve(path);
  1.2910 +            var x, y, p, l, sp = "", subpaths = {}, point,
  1.2911 +                len = 0;
  1.2912 +            for (var i = 0, ii = path.length; i < ii; i++) {
  1.2913 +                p = path[i];
  1.2914 +                if (p[0] == "M") {
  1.2915 +                    x = +p[1];
  1.2916 +                    y = +p[2];
  1.2917 +                } else {
  1.2918 +                    l = segmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
  1.2919 +                    if (len + l > length) {
  1.2920 +                        if (subpath && !subpaths.start) {
  1.2921 +                            point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
  1.2922 +                            sp += ["C", point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
  1.2923 +                            if (onlystart) {return sp;}
  1.2924 +                            subpaths.start = sp;
  1.2925 +                            sp = ["M", point.x, point.y + "C", point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]][join]();
  1.2926 +                            len += l;
  1.2927 +                            x = +p[5];
  1.2928 +                            y = +p[6];
  1.2929 +                            continue;
  1.2930 +                        }
  1.2931 +                        if (!istotal && !subpath) {
  1.2932 +                            point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
  1.2933 +                            return {x: point.x, y: point.y, alpha: point.alpha};
  1.2934 +                        }
  1.2935 +                    }
  1.2936 +                    len += l;
  1.2937 +                    x = +p[5];
  1.2938 +                    y = +p[6];
  1.2939 +                }
  1.2940 +                sp += p;
  1.2941 +            }
  1.2942 +            subpaths.end = sp;
  1.2943 +            point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[1], p[2], p[3], p[4], p[5], p[6], 1);
  1.2944 +            point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha});
  1.2945 +            return point;
  1.2946 +        };
  1.2947 +    },
  1.2948 +    segmentLength = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
  1.2949 +        var old = {x: 0, y: 0},
  1.2950 +            len = 0;
  1.2951 +        for (var i = 0; i < 1.01; i+=.01) {
  1.2952 +            var dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i);
  1.2953 +            i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
  1.2954 +            old = dot;
  1.2955 +        }
  1.2956 +        return len;
  1.2957 +    });
  1.2958 +    var getTotalLength = getLengthFactory(1),
  1.2959 +        getPointAtLength = getLengthFactory(),
  1.2960 +        getSubpathsAtLength = getLengthFactory(0, 1);
  1.2961 +    Element[proto].getTotalLength = function () {
  1.2962 +        if (this.type != "path") {return;}
  1.2963 +        if (this.node.getTotalLength) {
  1.2964 +            return this.node.getTotalLength();
  1.2965 +        }
  1.2966 +        return getTotalLength(this.attrs.path);
  1.2967 +    };
  1.2968 +    Element[proto].getPointAtLength = function (length) {
  1.2969 +        if (this.type != "path") {return;}
  1.2970 +        if (this.node.getPointAtLength) {
  1.2971 +            return this.node.getPointAtLength(length);
  1.2972 +        }
  1.2973 +        return getPointAtLength(this.attrs.path, length);
  1.2974 +    };
  1.2975 +    Element[proto].getSubpath = function (from, to) {
  1.2976 +        if (this.type != "path") {return;}
  1.2977 +        if (math.abs(this.getTotalLength() - to) < 1e-6) {
  1.2978 +            return getSubpathsAtLength(this.attrs.path, from).end;
  1.2979 +        }
  1.2980 +        var a = getSubpathsAtLength(this.attrs.path, to, 1);
  1.2981 +        return from ? getSubpathsAtLength(a, from).end : a;
  1.2982 +    };
  1.2983 +
  1.2984 +    // animation easing formulas
  1.2985 +    R.easing_formulas = {
  1.2986 +        linear: function (n) {
  1.2987 +            return n;
  1.2988 +        },
  1.2989 +        "<": function (n) {
  1.2990 +            return pow(n, 3);
  1.2991 +        },
  1.2992 +        ">": function (n) {
  1.2993 +            return pow(n - 1, 3) + 1;
  1.2994 +        },
  1.2995 +        "<>": function (n) {
  1.2996 +            n = n * 2;
  1.2997 +            if (n < 1) {
  1.2998 +                return pow(n, 3) / 2;
  1.2999 +            }
  1.3000 +            n -= 2;
  1.3001 +            return (pow(n, 3) + 2) / 2;
  1.3002 +        },
  1.3003 +        backIn: function (n) {
  1.3004 +            var s = 1.70158;
  1.3005 +            return n * n * ((s + 1) * n - s);
  1.3006 +        },
  1.3007 +        backOut: function (n) {
  1.3008 +            n = n - 1;
  1.3009 +            var s = 1.70158;
  1.3010 +            return n * n * ((s + 1) * n + s) + 1;
  1.3011 +        },
  1.3012 +        elastic: function (n) {
  1.3013 +            if (n == 0 || n == 1) {
  1.3014 +                return n;
  1.3015 +            }
  1.3016 +            var p = .3,
  1.3017 +                s = p / 4;
  1.3018 +            return pow(2, -10 * n) * math.sin((n - s) * (2 * math.PI) / p) + 1;
  1.3019 +        },
  1.3020 +        bounce: function (n) {
  1.3021 +            var s = 7.5625,
  1.3022 +                p = 2.75,
  1.3023 +                l;
  1.3024 +            if (n < (1 / p)) {
  1.3025 +                l = s * n * n;
  1.3026 +            } else {
  1.3027 +                if (n < (2 / p)) {
  1.3028 +                    n -= (1.5 / p);
  1.3029 +                    l = s * n * n + .75;
  1.3030 +                } else {
  1.3031 +                    if (n < (2.5 / p)) {
  1.3032 +                        n -= (2.25 / p);
  1.3033 +                        l = s * n * n + .9375;
  1.3034 +                    } else {
  1.3035 +                        n -= (2.625 / p);
  1.3036 +                        l = s * n * n + .984375;
  1.3037 +                    }
  1.3038 +                }
  1.3039 +            }
  1.3040 +            return l;
  1.3041 +        }
  1.3042 +    };
  1.3043 +
  1.3044 +    var animationElements = {length : 0},
  1.3045 +        animation = function () {
  1.3046 +            var Now = +new Date;
  1.3047 +            for (var l in animationElements) if (l != "length" && animationElements[has](l)) {
  1.3048 +                var e = animationElements[l];
  1.3049 +                if (e.stop || e.el.removed) {
  1.3050 +                    delete animationElements[l];
  1.3051 +                    animationElements[length]--;
  1.3052 +                    continue;
  1.3053 +                }
  1.3054 +                var time = Now - e.start,
  1.3055 +                    ms = e.ms,
  1.3056 +                    easing = e.easing,
  1.3057 +                    from = e.from,
  1.3058 +                    diff = e.diff,
  1.3059 +                    to = e.to,
  1.3060 +                    t = e.t,
  1.3061 +                    prev = e.prev || 0,
  1.3062 +                    that = e.el,
  1.3063 +                    callback = e.callback,
  1.3064 +                    set = {},
  1.3065 +                    now;
  1.3066 +                if (time < ms) {
  1.3067 +                    var pos = R.easing_formulas[easing] ? R.easing_formulas[easing](time / ms) : time / ms;
  1.3068 +                    for (var attr in from) if (from[has](attr)) {
  1.3069 +                        switch (availableAnimAttrs[attr]) {
  1.3070 +                            case "along":
  1.3071 +                                now = pos * ms * diff[attr];
  1.3072 +                                to.back && (now = to.len - now);
  1.3073 +                                var point = getPointAtLength(to[attr], now);
  1.3074 +                                that.translate(diff.sx - diff.x || 0, diff.sy - diff.y || 0);
  1.3075 +                                diff.x = point.x;
  1.3076 +                                diff.y = point.y;
  1.3077 +                                that.translate(point.x - diff.sx, point.y - diff.sy);
  1.3078 +                                to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
  1.3079 +                                break;
  1.3080 +                            case nu:
  1.3081 +                                now = +from[attr] + pos * ms * diff[attr];
  1.3082 +                                break;
  1.3083 +                            case "colour":
  1.3084 +                                now = "rgb(" + [
  1.3085 +                                    upto255(round(from[attr].r + pos * ms * diff[attr].r)),
  1.3086 +                                    upto255(round(from[attr].g + pos * ms * diff[attr].g)),
  1.3087 +                                    upto255(round(from[attr].b + pos * ms * diff[attr].b))
  1.3088 +                                ][join](",") + ")";
  1.3089 +                                break;
  1.3090 +                            case "path":
  1.3091 +                                now = [];
  1.3092 +                                for (var i = 0, ii = from[attr][length]; i < ii; i++) {
  1.3093 +                                    now[i] = [from[attr][i][0]];
  1.3094 +                                    for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
  1.3095 +                                        now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
  1.3096 +                                    }
  1.3097 +                                    now[i] = now[i][join](S);
  1.3098 +                                }
  1.3099 +                                now = now[join](S);
  1.3100 +                                break;
  1.3101 +                            case "csv":
  1.3102 +                                switch (attr) {
  1.3103 +                                    case "translation":
  1.3104 +                                        var x = diff[attr][0] * (time - prev),
  1.3105 +                                            y = diff[attr][1] * (time - prev);
  1.3106 +                                        t.x += x;
  1.3107 +                                        t.y += y;
  1.3108 +                                        now = x + S + y;
  1.3109 +                                    break;
  1.3110 +                                    case "rotation":
  1.3111 +                                        now = +from[attr][0] + pos * ms * diff[attr][0];
  1.3112 +                                        from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
  1.3113 +                                    break;
  1.3114 +                                    case "scale":
  1.3115 +                                        now = [+from[attr][0] + pos * ms * diff[attr][0], +from[attr][1] + pos * ms * diff[attr][1], (2 in to[attr] ? to[attr][2] : E), (3 in to[attr] ? to[attr][3] : E)][join](S);
  1.3116 +                                    break;
  1.3117 +                                    case "clip-rect":
  1.3118 +                                        now = [];
  1.3119 +                                        i = 4;
  1.3120 +                                        while (i--) {
  1.3121 +                                            now[i] = +from[attr][i] + pos * ms * diff[attr][i];
  1.3122 +                                        }
  1.3123 +                                    break;
  1.3124 +                                }
  1.3125 +                                break;
  1.3126 +                        }
  1.3127 +                        set[attr] = now;
  1.3128 +                    }
  1.3129 +                    that.attr(set);
  1.3130 +                    that._run && that._run.call(that);
  1.3131 +                } else {
  1.3132 +                    if (to.along) {
  1.3133 +                        point = getPointAtLength(to.along, to.len * !to.back);
  1.3134 +                        that.translate(diff.sx - (diff.x || 0) + point.x - diff.sx, diff.sy - (diff.y || 0) + point.y - diff.sy);
  1.3135 +                        to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
  1.3136 +                    }
  1.3137 +                    (t.x || t.y) && that.translate(-t.x, -t.y);
  1.3138 +                    to.scale && (to.scale += E);
  1.3139 +                    that.attr(to);
  1.3140 +                    delete animationElements[l];
  1.3141 +                    animationElements[length]--;
  1.3142 +                    that.in_animation = null;
  1.3143 +                    R.is(callback, "function") && callback.call(that);
  1.3144 +                }
  1.3145 +                e.prev = time;
  1.3146 +            }
  1.3147 +            R.svg && that && that.paper && that.paper.safari();
  1.3148 +            animationElements[length] && win.setTimeout(animation);
  1.3149 +        },
  1.3150 +        upto255 = function (color) {
  1.3151 +            return mmax(mmin(color, 255), 0);
  1.3152 +        },
  1.3153 +        translate = function (x, y) {
  1.3154 +            if (x == null) {
  1.3155 +                return {x: this._.tx, y: this._.ty, toString: x_y};
  1.3156 +            }
  1.3157 +            this._.tx += +x;
  1.3158 +            this._.ty += +y;
  1.3159 +            switch (this.type) {
  1.3160 +                case "circle":
  1.3161 +                case "ellipse":
  1.3162 +                    this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy});
  1.3163 +                    break;
  1.3164 +                case "rect":
  1.3165 +                case "image":
  1.3166 +                case "text":
  1.3167 +                    this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y});
  1.3168 +                    break;
  1.3169 +                case "path":
  1.3170 +                    var path = pathToRelative(this.attrs.path);
  1.3171 +                    path[0][1] += +x;
  1.3172 +                    path[0][2] += +y;
  1.3173 +                    this.attr({path: path});
  1.3174 +                break;
  1.3175 +            }
  1.3176 +            return this;
  1.3177 +        };
  1.3178 +    Element[proto].animateWith = function (element, params, ms, easing, callback) {
  1.3179 +        animationElements[element.id] && (params.start = animationElements[element.id].start);
  1.3180 +        return this.animate(params, ms, easing, callback);
  1.3181 +    };
  1.3182 +    Element[proto].animateAlong = along();
  1.3183 +    Element[proto].animateAlongBack = along(1);
  1.3184 +    function along(isBack) {
  1.3185 +        return function (path, ms, rotate, callback) {
  1.3186 +            var params = {back: isBack};
  1.3187 +            R.is(rotate, "function") ? (callback = rotate) : (params.rot = rotate);
  1.3188 +            path && path.constructor == Element && (path = path.attrs.path);
  1.3189 +            path && (params.along = path);
  1.3190 +            return this.animate(params, ms, callback);
  1.3191 +        };
  1.3192 +    }
  1.3193 +    Element[proto].onAnimation = function (f) {
  1.3194 +        this._run = f || 0;
  1.3195 +        return this;
  1.3196 +    };
  1.3197 +    Element[proto].animate = function (params, ms, easing, callback) {
  1.3198 +        if (R.is(easing, "function") || !easing) {
  1.3199 +            callback = easing || null;
  1.3200 +        }
  1.3201 +        var from = {},
  1.3202 +            to = {},
  1.3203 +            diff = {};
  1.3204 +        for (var attr in params) if (params[has](attr)) {
  1.3205 +            if (availableAnimAttrs[has](attr)) {
  1.3206 +                from[attr] = this.attr(attr);
  1.3207 +                (from[attr] == null) && (from[attr] = availableAttrs[attr]);
  1.3208 +                to[attr] = params[attr];
  1.3209 +                switch (availableAnimAttrs[attr]) {
  1.3210 +                    case "along":
  1.3211 +                        var len = getTotalLength(params[attr]);
  1.3212 +                        var point = getPointAtLength(params[attr], len * !!params.back);
  1.3213 +                        var bb = this.getBBox();
  1.3214 +                        diff[attr] = len / ms;
  1.3215 +                        diff.tx = bb.x;
  1.3216 +                        diff.ty = bb.y;
  1.3217 +                        diff.sx = point.x;
  1.3218 +                        diff.sy = point.y;
  1.3219 +                        to.rot = params.rot;
  1.3220 +                        to.back = params.back;
  1.3221 +                        to.len = len;
  1.3222 +                        params.rot && (diff.r = toFloat(this.rotate()) || 0);
  1.3223 +                        break;
  1.3224 +                    case nu:
  1.3225 +                        diff[attr] = (to[attr] - from[attr]) / ms;
  1.3226 +                        break;
  1.3227 +                    case "colour":
  1.3228 +                        from[attr] = R.getRGB(from[attr]);
  1.3229 +                        var toColour = R.getRGB(to[attr]);
  1.3230 +                        diff[attr] = {
  1.3231 +                            r: (toColour.r - from[attr].r) / ms,
  1.3232 +                            g: (toColour.g - from[attr].g) / ms,
  1.3233 +                            b: (toColour.b - from[attr].b) / ms
  1.3234 +                        };
  1.3235 +                        break;
  1.3236 +                    case "path":
  1.3237 +                        var pathes = path2curve(from[attr], to[attr]);
  1.3238 +                        from[attr] = pathes[0];
  1.3239 +                        var toPath = pathes[1];
  1.3240 +                        diff[attr] = [];
  1.3241 +                        for (var i = 0, ii = from[attr][length]; i < ii; i++) {
  1.3242 +                            diff[attr][i] = [0];
  1.3243 +                            for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
  1.3244 +                                diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
  1.3245 +                            }
  1.3246 +                        }
  1.3247 +                        break;
  1.3248 +                    case "csv":
  1.3249 +                        var values = Str(params[attr])[split](separator),
  1.3250 +                            from2 = Str(from[attr])[split](separator);
  1.3251 +                        switch (attr) {
  1.3252 +                            case "translation":
  1.3253 +                                from[attr] = [0, 0];
  1.3254 +                                diff[attr] = [values[0] / ms, values[1] / ms];
  1.3255 +                            break;
  1.3256 +                            case "rotation":
  1.3257 +                                from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
  1.3258 +                                diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
  1.3259 +                            break;
  1.3260 +                            case "scale":
  1.3261 +                                params[attr] = values;
  1.3262 +                                from[attr] = Str(from[attr])[split](separator);
  1.3263 +                                diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
  1.3264 +                            break;
  1.3265 +                            case "clip-rect":
  1.3266 +                                from[attr] = Str(from[attr])[split](separator);
  1.3267 +                                diff[attr] = [];
  1.3268 +                                i = 4;
  1.3269 +                                while (i--) {
  1.3270 +                                    diff[attr][i] = (values[i] - from[attr][i]) / ms;
  1.3271 +                                }
  1.3272 +                            break;
  1.3273 +                        }
  1.3274 +                        to[attr] = values;
  1.3275 +                }
  1.3276 +            }
  1.3277 +        }
  1.3278 +        this.stop();
  1.3279 +        this.in_animation = 1;
  1.3280 +        animationElements[this.id] = {
  1.3281 +            start: params.start || +new Date,
  1.3282 +            ms: ms,
  1.3283 +            easing: easing,
  1.3284 +            from: from,
  1.3285 +            diff: diff,
  1.3286 +            to: to,
  1.3287 +            el: this,
  1.3288 +            callback: callback,
  1.3289 +            t: {x: 0, y: 0}
  1.3290 +        };
  1.3291 +        ++animationElements[length] == 1 && animation();
  1.3292 +        return this;
  1.3293 +    };
  1.3294 +    Element[proto].stop = function () {
  1.3295 +        animationElements[this.id] && animationElements[length]--;
  1.3296 +        delete animationElements[this.id];
  1.3297 +        return this;
  1.3298 +    };
  1.3299 +    Element[proto].translate = function (x, y) {
  1.3300 +        return this.attr({translation: x + " " + y});
  1.3301 +    };
  1.3302 +    Element[proto][toString] = function () {
  1.3303 +        return "Rapha\xebl\u2019s object";
  1.3304 +    };
  1.3305 +    R.ae = animationElements;
  1.3306 + 
  1.3307 +    // Set
  1.3308 +    var Set = function (items) {
  1.3309 +        this.items = [];
  1.3310 +        this[length] = 0;
  1.3311 +        this.type = "set";
  1.3312 +        if (items) {
  1.3313 +            for (var i = 0, ii = items[length]; i < ii; i++) {
  1.3314 +                if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
  1.3315 +                    this[this.items[length]] = this.items[this.items[length]] = items[i];
  1.3316 +                    this[length]++;
  1.3317 +                }
  1.3318 +            }
  1.3319 +        }
  1.3320 +    };
  1.3321 +    Set[proto][push] = function () {
  1.3322 +        var item,
  1.3323 +            len;
  1.3324 +        for (var i = 0, ii = arguments[length]; i < ii; i++) {
  1.3325 +            item = arguments[i];
  1.3326 +            if (item && (item.constructor == Element || item.constructor == Set)) {
  1.3327 +                len = this.items[length];
  1.3328 +                this[len] = this.items[len] = item;
  1.3329 +                this[length]++;
  1.3330 +            }
  1.3331 +        }
  1.3332 +        return this;
  1.3333 +    };
  1.3334 +    Set[proto].pop = function () {
  1.3335 +        delete this[this[length]--];
  1.3336 +        return this.items.pop();
  1.3337 +    };
  1.3338 +    for (var method in Element[proto]) if (Element[proto][has](method)) {
  1.3339 +        Set[proto][method] = (function (methodname) {
  1.3340 +            return function () {
  1.3341 +                for (var i = 0, ii = this.items[length]; i < ii; i++) {
  1.3342 +                    this.items[i][methodname][apply](this.items[i], arguments);
  1.3343 +                }
  1.3344 +                return this;
  1.3345 +            };
  1.3346 +        })(method);
  1.3347 +    }
  1.3348 +    Set[proto].attr = function (name, value) {
  1.3349 +        if (name && R.is(name, array) && R.is(name[0], "object")) {
  1.3350 +            for (var j = 0, jj = name[length]; j < jj; j++) {
  1.3351 +                this.items[j].attr(name[j]);
  1.3352 +            }
  1.3353 +        } else {
  1.3354 +            for (var i = 0, ii = this.items[length]; i < ii; i++) {
  1.3355 +                this.items[i].attr(name, value);
  1.3356 +            }
  1.3357 +        }
  1.3358 +        return this;
  1.3359 +    };
  1.3360 +    Set[proto].animate = function (params, ms, easing, callback) {
  1.3361 +        (R.is(easing, "function") || !easing) && (callback = easing || null);
  1.3362 +        var len = this.items[length],
  1.3363 +            i = len,
  1.3364 +            item,
  1.3365 +            set = this,
  1.3366 +            collector;
  1.3367 +        callback && (collector = function () {
  1.3368 +            !--len && callback.call(set);
  1.3369 +        });
  1.3370 +        easing = R.is(easing, string) ? easing : collector;
  1.3371 +        item = this.items[--i].animate(params, ms, easing, collector);
  1.3372 +        while (i--) {
  1.3373 +            this.items[i].animateWith(item, params, ms, easing, collector);
  1.3374 +        }
  1.3375 +        return this;
  1.3376 +    };
  1.3377 +    Set[proto].insertAfter = function (el) {
  1.3378 +        var i = this.items[length];
  1.3379 +        while (i--) {
  1.3380 +            this.items[i].insertAfter(el);
  1.3381 +        }
  1.3382 +        return this;
  1.3383 +    };
  1.3384 +    Set[proto].getBBox = function () {
  1.3385 +        var x = [],
  1.3386 +            y = [],
  1.3387 +            w = [],
  1.3388 +            h = [];
  1.3389 +        for (var i = this.items[length]; i--;) {
  1.3390 +            var box = this.items[i].getBBox();
  1.3391 +            x[push](box.x);
  1.3392 +            y[push](box.y);
  1.3393 +            w[push](box.x + box.width);
  1.3394 +            h[push](box.y + box.height);
  1.3395 +        }
  1.3396 +        x = mmin[apply](0, x);
  1.3397 +        y = mmin[apply](0, y);
  1.3398 +        return {
  1.3399 +            x: x,
  1.3400 +            y: y,
  1.3401 +            width: mmax[apply](0, w) - x,
  1.3402 +            height: mmax[apply](0, h) - y
  1.3403 +        };
  1.3404 +    };
  1.3405 +    Set[proto].clone = function (s) {
  1.3406 +        s = new Set;
  1.3407 +        for (var i = 0, ii = this.items[length]; i < ii; i++) {
  1.3408 +            s[push](this.items[i].clone());
  1.3409 +        }
  1.3410 +        return s;
  1.3411 +    };
  1.3412 +
  1.3413 +    R.registerFont = function (font) {
  1.3414 +        if (!font.face) {
  1.3415 +            return font;
  1.3416 +        }
  1.3417 +        this.fonts = this.fonts || {};
  1.3418 +        var fontcopy = {
  1.3419 +                w: font.w,
  1.3420 +                face: {},
  1.3421 +                glyphs: {}
  1.3422 +            },
  1.3423 +            family = font.face["font-family"];
  1.3424 +        for (var prop in font.face) if (font.face[has](prop)) {
  1.3425 +            fontcopy.face[prop] = font.face[prop];
  1.3426 +        }
  1.3427 +        if (this.fonts[family]) {
  1.3428 +            this.fonts[family][push](fontcopy);
  1.3429 +        } else {
  1.3430 +            this.fonts[family] = [fontcopy];
  1.3431 +        }
  1.3432 +        if (!font.svg) {
  1.3433 +            fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
  1.3434 +            for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
  1.3435 +                var path = font.glyphs[glyph];
  1.3436 +                fontcopy.glyphs[glyph] = {
  1.3437 +                    w: path.w,
  1.3438 +                    k: {},
  1.3439 +                    d: path.d && "M" + path.d[rp](/[mlcxtrv]/g, function (command) {
  1.3440 +                            return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
  1.3441 +                        }) + "z"
  1.3442 +                };
  1.3443 +                if (path.k) {
  1.3444 +                    for (var k in path.k) if (path[has](k)) {
  1.3445 +                        fontcopy.glyphs[glyph].k[k] = path.k[k];
  1.3446 +                    }
  1.3447 +                }
  1.3448 +            }
  1.3449 +        }
  1.3450 +        return font;
  1.3451 +    };
  1.3452 +    Paper[proto].getFont = function (family, weight, style, stretch) {
  1.3453 +        stretch = stretch || "normal";
  1.3454 +        style = style || "normal";
  1.3455 +        weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
  1.3456 +        if (!R.fonts) {
  1.3457 +            return;
  1.3458 +        }
  1.3459 +        var font = R.fonts[family];
  1.3460 +        if (!font) {
  1.3461 +            var name = new RegExp("(^|\\s)" + family[rp](/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
  1.3462 +            for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
  1.3463 +                if (name.test(fontName)) {
  1.3464 +                    font = R.fonts[fontName];
  1.3465 +                    break;
  1.3466 +                }
  1.3467 +            }
  1.3468 +        }
  1.3469 +        var thefont;
  1.3470 +        if (font) {
  1.3471 +            for (var i = 0, ii = font[length]; i < ii; i++) {
  1.3472 +                thefont = font[i];
  1.3473 +                if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
  1.3474 +                    break;
  1.3475 +                }
  1.3476 +            }
  1.3477 +        }
  1.3478 +        return thefont;
  1.3479 +    };
  1.3480 +    Paper[proto].print = function (x, y, string, font, size, origin) {
  1.3481 +        origin = origin || "middle"; // baseline|middle
  1.3482 +        var out = this.set(),
  1.3483 +            letters = Str(string)[split](E),
  1.3484 +            shift = 0,
  1.3485 +            path = E,
  1.3486 +            scale;
  1.3487 +        R.is(font, string) && (font = this.getFont(font));
  1.3488 +        if (font) {
  1.3489 +            scale = (size || 16) / font.face["units-per-em"];
  1.3490 +            var bb = font.face.bbox.split(separator),
  1.3491 +                top = +bb[0],
  1.3492 +                height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
  1.3493 +            for (var i = 0, ii = letters[length]; i < ii; i++) {
  1.3494 +                var prev = i && font.glyphs[letters[i - 1]] || {},
  1.3495 +                    curr = font.glyphs[letters[i]];
  1.3496 +                shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0;
  1.3497 +                curr && curr.d && out[push](this.path(curr.d).attr({fill: "#000", stroke: "none", translation: [shift, 0]}));
  1.3498 +            }
  1.3499 +            out.scale(scale, scale, top, height).translate(x - top, y - height);
  1.3500 +        }
  1.3501 +        return out;
  1.3502 +    };
  1.3503 +
  1.3504 +    var formatrg = /\{(\d+)\}/g;
  1.3505 +    R.format = function (token, params) {
  1.3506 +        var args = R.is(params, array) ? [0][concat](params) : arguments;
  1.3507 +        token && R.is(token, string) && args[length] - 1 && (token = token[rp](formatrg, function (str, i) {
  1.3508 +            return args[++i] == null ? E : args[i];
  1.3509 +        }));
  1.3510 +        return token || E;
  1.3511 +    };
  1.3512 +    R.ninja = function () {
  1.3513 +        oldRaphael.was ? (Raphael = oldRaphael.is) : delete Raphael;
  1.3514 +        return R;
  1.3515 +    };
  1.3516 +    R.el = Element[proto];
  1.3517 +    return R;
  1.3518 +})();
  1.3519 \ No newline at end of file