/*!
 * Raphael 1.4.3 - JavaScript Vector Library
 *
 * Copyright (c) 2010 Dmitry Baranovskiy (http://raphaeljs.com)
 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
 */
 
Raphael = (function () {
    function R() {
        if (R.is(arguments[0], array)) {
            var a = arguments[0],
                cnv = create[apply](R, a.splice(0, 3 + R.is(a[0], nu))),
                res = cnv.set();
            for (var i = 0, ii = a[length]; i < ii; i++) {
                var j = a[i] || {};
                elements.test(j.type) && res[push](cnv[j.type]().attr(j));
            }
            return res;
        }
        return create[apply](R, arguments);
    }
    R.version = "1.4.3";
    var separator = /[, ]+/,
        elements = /^(circle|rect|path|ellipse|text|image)$/,
        proto = "prototype",
        has = "hasOwnProperty",
        doc = document,
        win = window,
        oldRaphael = {
            was: Object[proto][has].call(win, "Raphael"),
            is: win.Raphael
        },
        Paper = function () {},
        appendChild = "appendChild",
        apply = "apply",
        concat = "concat",
        supportsTouch = "createTouch" in doc,
        E = "",
        S = " ",
        split = "split",
        events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend orientationchange touchcancel gesturestart gesturechange gestureend"[split](S),
        touchMap = {
            mousedown: "touchstart",
            mousemove: "touchmove",
            mouseup: "touchend"
        },
        join = "join",
        length = "length",
        lowerCase = String[proto].toLowerCase,
        math = Math,
        mmax = math.max,
        mmin = math.min,
        nu = "number",
        string = "string",
        array = "array",
        toString = "toString",
        fillString = "fill",
        objectToString = Object[proto][toString],
        paper = {},
        pow = math.pow,
        push = "push",
        rg = /^(?=[\da-f]$)/,
        ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
        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*\)|hs[bl]\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hs[bl]\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i,
        round = math.round,
        setAttribute = "setAttribute",
        toFloat = parseFloat,
        toInt = parseInt,
        ms = " progid:DXImageTransform.Microsoft",
        upperCase = String[proto].toUpperCase,
        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},
        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},
        rp = "replace";
    R.type = (win.SVGAngle || doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
    if (R.type == "VML") {
        var d = doc.createElement("div");
        d.innerHTML = '<!--[if vml]><br><br><![endif]-->';
        if (d.childNodes[length] != 2) {
            return R.type = null;
        }
        d = null;
    }
    R.svg = !(R.vml = R.type == "VML");
    Paper[proto] = R[proto];
    R._id = 0;
    R._oid = 0;
    R.fn = {};
    R.is = function (o, type) {
        type = lowerCase.call(type);
        return  (type == "object" && o === Object(o)) ||
                (type == "undefined" && typeof o == type) ||
                (type == "null" && o == null) ||
                lowerCase.call(objectToString.call(o).slice(8, -1)) == type;
    };

    R.setWindow = function (newwin) {
        win = newwin;
        doc = win.document;
    };
    // colour utilities
    var toHex = function (color) {
        if (R.vml) {
            // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
            var trim = /^\s+|\s+$/g;
            toHex = cacher(function (color) {
                var bod;
                color = (color + E)[rp](trim, E);
                try {
                    var docum = new win.ActiveXObject("htmlfile");
                    docum.write("<body>");
                    docum.close();
                    bod = docum.body;
                } catch(e) {
                    bod = win.createPopup().document.body;
                }
                var range = bod.createTextRange();
                try {
                    bod.style.color = color;
                    var value = range.queryCommandValue("ForeColor");
                    value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
                    return "#" + ("000000" + value[toString](16)).slice(-6);
                } catch(e) {
                    return "none";
                }
            });
        } else {
            var i = doc.createElement("i");
            i.title = "Rapha\xebl Colour Picker";
            i.style.display = "none";
            doc.body[appendChild](i);
            toHex = cacher(function (color) {
                i.style.color = color;
                return doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
            });
        }
        return toHex(color);
    };
    var hsbtoString = function () {
        return "hsb(" + [this.h, this.s, this.b] + ")";
    },
    rgbtoString = function () {
        return this.hex;
    };
    R.hsb2rgb = cacher(function (hue, saturation, brightness) {
        if (R.is(hue, "object") && "h" in hue && "s" in hue && "b" in hue) {
            brightness = hue.b;
            saturation = hue.s;
            hue = hue.h;
        }
        var red,
            green,
            blue;
        if (brightness == 0) {
            return {r: 0, g: 0, b: 0, hex: "#000"};
        }
        if (hue > 1 || saturation > 1 || brightness > 1) {
            hue /= 255;
            saturation /= 255;
            brightness /= 255;
        }
        var i = ~~(hue * 6),
            f = (hue * 6) - i,
            p = brightness * (1 - saturation),
            q = brightness * (1 - (saturation * f)),
            t = brightness * (1 - (saturation * (1 - f)));
        red = [brightness, q, p, p, t, brightness, brightness][i];
        green = [t, brightness, brightness, q, p, p, t][i];
        blue = [p, p, t, brightness, brightness, q, p][i];
        red *= 255;
        green *= 255;
        blue *= 255;
        var rgb = {r: red, g: green, b: blue, toString: rgbtoString},
            r = (~~red)[toString](16),
            g = (~~green)[toString](16),
            b = (~~blue)[toString](16);
        r = r[rp](rg, "0");
        g = g[rp](rg, "0");
        b = b[rp](rg, "0");
        rgb.hex = "#" + r + g + b;
        return rgb;
    }, R);
    R.rgb2hsb = cacher(function (red, green, blue) {
        if (R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
            blue = red.b;
            green = red.g;
            red = red.r;
        }
        if (R.is(red, string)) {
            var clr = R.getRGB(red);
            red = clr.r;
            green = clr.g;
            blue = clr.b;
        }
        if (red > 1 || green > 1 || blue > 1) {
            red /= 255;
            green /= 255;
            blue /= 255;
        }
        var max = mmax(red, green, blue),
            min = mmin(red, green, blue),
            hue,
            saturation,
            brightness = max;
        if (min == max) {
            return {h: 0, s: 0, b: max};
        } else {
            var delta = (max - min);
            saturation = delta / max;
            if (red == max) {
                hue = (green - blue) / delta;
            } else if (green == max) {
                hue = 2 + ((blue - red) / delta);
            } else {
                hue = 4 + ((red - green) / delta);
            }
            hue /= 6;
            hue < 0 && hue++;
            hue > 1 && hue--;
        }
        return {h: hue, s: saturation, b: brightness, toString: hsbtoString};
    }, R);
    var p2s = /,?([achlmqrstvxz]),?/gi,
        commaSpaces = /\s*,\s*/,
        hsrg = {hs: 1, rg: 1};
    R._path2string = function () {
        return this.join(",")[rp](p2s, "$1");
    };
    function cacher(f, scope, postprocessor) {
        function newf() {
            var arg = Array[proto].slice.call(arguments, 0),
                args = arg[join]("\u25ba"),
                cache = newf.cache = newf.cache || {},
                count = newf.count = newf.count || [];
            if (cache[has](args)) {
                return postprocessor ? postprocessor(cache[args]) : cache[args];
            }
            count[length] >= 1e3 && delete cache[count.shift()];
            count[push](args);
            cache[args] = f[apply](scope, arg);
            return postprocessor ? postprocessor(cache[args]) : cache[args];
        }
        return newf;
    }
 
    R.getRGB = cacher(function (colour) {
        if (!colour || !!((colour = colour + E).indexOf("-") + 1)) {
            return {r: -1, g: -1, b: -1, hex: "none", error: 1};
        }
        if (colour == "none") {
            return {r: -1, g: -1, b: -1, hex: "none"};
        }
        !(hsrg[has](colour.substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
        var res,
            red,
            green,
            blue,
            opacity,
            t,
            rgb = colour.match(colourRegExp);
        if (rgb) {
            if (rgb[2]) {
                blue = toInt(rgb[2].substring(5), 16);
                green = toInt(rgb[2].substring(3, 5), 16);
                red = toInt(rgb[2].substring(1, 3), 16);
            }
            if (rgb[3]) {
                blue = toInt((t = rgb[3].charAt(3)) + t, 16);
                green = toInt((t = rgb[3].charAt(2)) + t, 16);
                red = toInt((t = rgb[3].charAt(1)) + t, 16);
            }
            if (rgb[4]) {
                rgb = rgb[4][split](commaSpaces);
                red = toFloat(rgb[0]);
                green = toFloat(rgb[1]);
                blue = toFloat(rgb[2]);
                opacity = toFloat(rgb[3]);
            }
            if (rgb[5]) {
                rgb = rgb[5][split](commaSpaces);
                red = toFloat(rgb[0]) * 2.55;
                green = toFloat(rgb[1]) * 2.55;
                blue = toFloat(rgb[2]) * 2.55;
                opacity = toFloat(rgb[3]);
            }
            if (rgb[6]) {
                rgb = rgb[6][split](commaSpaces);
                red = toFloat(rgb[0]);
                green = toFloat(rgb[1]);
                blue = toFloat(rgb[2]);
                return R.hsb2rgb(red, green, blue);
            }
            if (rgb[7]) {
                rgb = rgb[7][split](commaSpaces);
                red = toFloat(rgb[0]) * 2.55;
                green = toFloat(rgb[1]) * 2.55;
                blue = toFloat(rgb[2]) * 2.55;
                return R.hsb2rgb(red, green, blue);
            }
            rgb = {r: red, g: green, b: blue};
            var r = (~~red)[toString](16),
                g = (~~green)[toString](16),
                b = (~~blue)[toString](16);
            r = r[rp](rg, "0");
            g = g[rp](rg, "0");
            b = b[rp](rg, "0");
            rgb.hex = "#" + r + g + b;
            isFinite(toFloat(opacity)) && (rgb.o = opacity);
            return rgb;
        }
        return {r: -1, g: -1, b: -1, hex: "none", error: 1};
    }, R);
    R.getColor = function (value) {
        var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
            rgb = this.hsb2rgb(start.h, start.s, start.b);
        start.h += .075;
        if (start.h > 1) {
            start.h = 0;
            start.s -= .2;
            start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
        }
        return rgb.hex;
    };
    R.getColor.reset = function () {
        delete this.start;
    };
    // path utilities
    var pathCommand = /([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig,
        pathValues = /(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig;
    R.parsePathString = cacher(function (pathString) {
        if (!pathString) {
            return null;
        }
        var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
            data = [];
        if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
            data = pathClone(pathString);
        }
        if (!data[length]) {
            (pathString + E)[rp](pathCommand, function (a, b, c) {
                var params = [],
                    name = lowerCase.call(b);
                c[rp](pathValues, function (a, b) {
                    b && params[push](+b);
                });
                if (name == "m" && params[length] > 2) {
                    data[push]([b][concat](params.splice(0, 2)));
                    name = "l";
                    b = b == "m" ? "l" : "L";
                }
                while (params[length] >= paramCounts[name]) {
                    data[push]([b][concat](params.splice(0, paramCounts[name])));
                    if (!paramCounts[name]) {
                        break;
                    }
                }
            });
        }
        data[toString] = R._path2string;
        return data;
    });
    R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
        var t1 = 1 - t,
            x = pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
            y = pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y,
            mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x),
            my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y),
            nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x),
            ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y),
            ax = (1 - t) * p1x + t * c1x,
            ay = (1 - t) * p1y + t * c1y,
            cx = (1 - t) * c2x + t * p2x,
            cy = (1 - t) * c2y + t * p2y,
            alpha = (90 - math.atan((mx - nx) / (my - ny)) * 180 / math.PI);
        (mx > nx || my < ny) && (alpha += 180);
        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};
    };
    var pathDimensions = cacher(function (path) {
        if (!path) {
            return {x: 0, y: 0, width: 0, height: 0};
        }
        path = path2curve(path);
        var x = 0, 
            y = 0,
            X = [],
            Y = [],
            p;
        for (var i = 0, ii = path[length]; i < ii; i++) {
            p = path[i];
            if (p[0] == "M") {
                x = p[1];
                y = p[2];
                X[push](x);
                Y[push](y);
            } else {
                var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
                X = X[concat](dim.min.x, dim.max.x);
                Y = Y[concat](dim.min.y, dim.max.y);
                x = p[5];
                y = p[6];
            }
        }
        var xmin = mmin[apply](0, X),
            ymin = mmin[apply](0, Y);
        return {
            x: xmin,
            y: ymin,
            width: mmax[apply](0, X) - xmin,
            height: mmax[apply](0, Y) - ymin
        };
    }),
        pathClone = function (pathArray) {
            var res = [];
            if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
                pathArray = R.parsePathString(pathArray);
            }
            for (var i = 0, ii = pathArray[length]; i < ii; i++) {
                res[i] = [];
                for (var j = 0, jj = pathArray[i][length]; j < jj; j++) {
                    res[i][j] = pathArray[i][j];
                }
            }
            res[toString] = R._path2string;
            return res;
        },
        pathToRelative = cacher(function (pathArray) {
            if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
                pathArray = R.parsePathString(pathArray);
            }
            var res = [],
                x = 0,
                y = 0,
                mx = 0,
                my = 0,
                start = 0;
            if (pathArray[0][0] == "M") {
                x = pathArray[0][1];
                y = pathArray[0][2];
                mx = x;
                my = y;
                start++;
                res[push](["M", x, y]);
            }
            for (var i = start, ii = pathArray[length]; i < ii; i++) {
                var r = res[i] = [],
                    pa = pathArray[i];
                if (pa[0] != lowerCase.call(pa[0])) {
                    r[0] = lowerCase.call(pa[0]);
                    switch (r[0]) {
                        case "a":
                            r[1] = pa[1];
                            r[2] = pa[2];
                            r[3] = pa[3];
                            r[4] = pa[4];
                            r[5] = pa[5];
                            r[6] = +(pa[6] - x).toFixed(3);
                            r[7] = +(pa[7] - y).toFixed(3);
                            break;
                        case "v":
                            r[1] = +(pa[1] - y).toFixed(3);
                            break;
                        case "m":
                            mx = pa[1];
                            my = pa[2];
                        default:
                            for (var j = 1, jj = pa[length]; j < jj; j++) {
                                r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
                            }
                    }
                } else {
                    r = res[i] = [];
                    if (pa[0] == "m") {
                        mx = pa[1] + x;
                        my = pa[2] + y;
                    }
                    for (var k = 0, kk = pa[length]; k < kk; k++) {
                        res[i][k] = pa[k];
                    }
                }
                var len = res[i][length];
                switch (res[i][0]) {
                    case "z":
                        x = mx;
                        y = my;
                        break;
                    case "h":
                        x += +res[i][len - 1];
                        break;
                    case "v":
                        y += +res[i][len - 1];
                        break;
                    default:
                        x += +res[i][len - 2];
                        y += +res[i][len - 1];
                }
            }
            res[toString] = R._path2string;
            return res;
        }, 0, pathClone),
        pathToAbsolute = cacher(function (pathArray) {
            if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
                pathArray = R.parsePathString(pathArray);
            }
            var res = [],
                x = 0,
                y = 0,
                mx = 0,
                my = 0,
                start = 0;
            if (pathArray[0][0] == "M") {
                x = +pathArray[0][1];
                y = +pathArray[0][2];
                mx = x;
                my = y;
                start++;
                res[0] = ["M", x, y];
            }
            for (var i = start, ii = pathArray[length]; i < ii; i++) {
                var r = res[i] = [],
                    pa = pathArray[i];
                if (pa[0] != upperCase.call(pa[0])) {
                    r[0] = upperCase.call(pa[0]);
                    switch (r[0]) {
                        case "A":
                            r[1] = pa[1];
                            r[2] = pa[2];
                            r[3] = pa[3];
                            r[4] = pa[4];
                            r[5] = pa[5];
                            r[6] = +(pa[6] + x);
                            r[7] = +(pa[7] + y);
                            break;
                        case "V":
                            r[1] = +pa[1] + y;
                            break;
                        case "H":
                            r[1] = +pa[1] + x;
                            break;
                        case "M":
                            mx = +pa[1] + x;
                            my = +pa[2] + y;
                        default:
                            for (var j = 1, jj = pa[length]; j < jj; j++) {
                                r[j] = +pa[j] + ((j % 2) ? x : y);
                            }
                    }
                } else {
                    for (var k = 0, kk = pa[length]; k < kk; k++) {
                        res[i][k] = pa[k];
                    }
                }
                switch (r[0]) {
                    case "Z":
                        x = mx;
                        y = my;
                        break;
                    case "H":
                        x = r[1];
                        break;
                    case "V":
                        y = r[1];
                        break;
                    default:
                        x = res[i][res[i][length] - 2];
                        y = res[i][res[i][length] - 1];
                }
            }
            res[toString] = R._path2string;
            return res;
        }, null, pathClone),
        l2c = function (x1, y1, x2, y2) {
            return [x1, y1, x2, y2, x2, y2];
        },
        q2c = function (x1, y1, ax, ay, x2, y2) {
            var _13 = 1 / 3,
                _23 = 2 / 3;
            return [
                    _13 * x1 + _23 * ax,
                    _13 * y1 + _23 * ay,
                    _13 * x2 + _23 * ax,
                    _13 * y2 + _23 * ay,
                    x2,
                    y2
                ];
        },
        a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
            // for more information of where this math came from visit:
            // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
            var PI = math.PI,
                _120 = PI * 120 / 180,
                rad = PI / 180 * (+angle || 0),
                res = [],
                xy,
                rotate = cacher(function (x, y, rad) {
                    var X = x * math.cos(rad) - y * math.sin(rad),
                        Y = x * math.sin(rad) + y * math.cos(rad);
                    return {x: X, y: Y};
                });
            if (!recursive) {
                xy = rotate(x1, y1, -rad);
                x1 = xy.x;
                y1 = xy.y;
                xy = rotate(x2, y2, -rad);
                x2 = xy.x;
                y2 = xy.y;
                var cos = math.cos(PI / 180 * angle),
                    sin = math.sin(PI / 180 * angle),
                    x = (x1 - x2) / 2,
                    y = (y1 - y2) / 2;
                var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
                if (h > 1) {
                    h = math.sqrt(h);
                    rx = h * rx;
                    ry = h * ry;
                }
                var rx2 = rx * rx,
                    ry2 = ry * ry,
                    k = (large_arc_flag == sweep_flag ? -1 : 1) *
                        math.sqrt(math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
                    cx = k * rx * y / ry + (x1 + x2) / 2,
                    cy = k * -ry * x / rx + (y1 + y2) / 2,
                    f1 = math.asin(((y1 - cy) / ry).toFixed(7)),
                    f2 = math.asin(((y2 - cy) / ry).toFixed(7));

                f1 = x1 < cx ? PI - f1 : f1;
                f2 = x2 < cx ? PI - f2 : f2;
                f1 < 0 && (f1 = PI * 2 + f1);
                f2 < 0 && (f2 = PI * 2 + f2);
                if (sweep_flag && f1 > f2) {
                    f1 = f1 - PI * 2;
                }
                if (!sweep_flag && f2 > f1) {
                    f2 = f2 - PI * 2;
                }
            } else {
                f1 = recursive[0];
                f2 = recursive[1];
                cx = recursive[2];
                cy = recursive[3];
            }
            var df = f2 - f1;
            if (math.abs(df) > _120) {
                var f2old = f2,
                    x2old = x2,
                    y2old = y2;
                f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
                x2 = cx + rx * math.cos(f2);
                y2 = cy + ry * math.sin(f2);
                res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
            }
            df = f2 - f1;
            var c1 = math.cos(f1),
                s1 = math.sin(f1),
                c2 = math.cos(f2),
                s2 = math.sin(f2),
                t = math.tan(df / 4),
                hx = 4 / 3 * rx * t,
                hy = 4 / 3 * ry * t,
                m1 = [x1, y1],
                m2 = [x1 + hx * s1, y1 - hy * c1],
                m3 = [x2 + hx * s2, y2 - hy * c2],
                m4 = [x2, y2];
            m2[0] = 2 * m1[0] - m2[0];
            m2[1] = 2 * m1[1] - m2[1];
            if (recursive) {
                return [m2, m3, m4][concat](res);
            } else {
                res = [m2, m3, m4][concat](res)[join]()[split](",");
                var newres = [];
                for (var i = 0, ii = res[length]; i < ii; i++) {
                    newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
                }
                return newres;
            }
        },
        findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
            var t1 = 1 - t;
            return {
                x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
                y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
            };
        },
        curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
            var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
                b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
                c = p1x - c1x,
                t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
                t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
                y = [p1y, p2y],
                x = [p1x, p2x],
                dot;
            math.abs(t1) > 1e12 && (t1 = .5);
            math.abs(t2) > 1e12 && (t2 = .5);
            if (t1 > 0 && t1 < 1) {
                dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
                x[push](dot.x);
                y[push](dot.y);
            }
            if (t2 > 0 && t2 < 1) {
                dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
                x[push](dot.x);
                y[push](dot.y);
            }
            a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
            b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
            c = p1y - c1y;
            t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
            t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
            math.abs(t1) > 1e12 && (t1 = .5);
            math.abs(t2) > 1e12 && (t2 = .5);
            if (t1 > 0 && t1 < 1) {
                dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
                x[push](dot.x);
                y[push](dot.y);
            }
            if (t2 > 0 && t2 < 1) {
                dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
                x[push](dot.x);
                y[push](dot.y);
            }
            return {
                min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
                max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
            };
        }),
        path2curve = cacher(function (path, path2) {
            var p = pathToAbsolute(path),
                p2 = path2 && pathToAbsolute(path2),
                attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
                attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
                processPath = function (path, d) {
                    var nx, ny;
                    if (!path) {
                        return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
                    }
                    !(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null);
                    switch (path[0]) {
                        case "M":
                            d.X = path[1];
                            d.Y = path[2];
                            break;
                        case "A":
                            path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
                            break;
                        case "S":
                            nx = d.x + (d.x - (d.bx || d.x));
                            ny = d.y + (d.y - (d.by || d.y));
                            path = ["C", nx, ny][concat](path.slice(1));
                            break;
                        case "T":
                            d.qx = d.x + (d.x - (d.qx || d.x));
                            d.qy = d.y + (d.y - (d.qy || d.y));
                            path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
                            break;
                        case "Q":
                            d.qx = path[1];
                            d.qy = path[2];
                            path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
                            break;
                        case "L":
                            path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
                            break;
                        case "H":
                            path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
                            break;
                        case "V":
                            path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
                            break;
                        case "Z":
                            path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
                            break;
                    }
                    return path;
                },
                fixArc = function (pp, i) {
                    if (pp[i][length] > 7) {
                        pp[i].shift();
                        var pi = pp[i];
                        while (pi[length]) {
                            pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
                        }
                        pp.splice(i, 1);
                        ii = mmax(p[length], p2 && p2[length] || 0);
                    }
                },
                fixM = function (path1, path2, a1, a2, i) {
                    if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
                        path2.splice(i, 0, ["M", a2.x, a2.y]);
                        a1.bx = 0;
                        a1.by = 0;
                        a1.x = path1[i][1];
                        a1.y = path1[i][2];
                        ii = mmax(p[length], p2 && p2[length] || 0);
                    }
                };
            for (var i = 0, ii = mmax(p[length], p2 && p2[length] || 0); i < ii; i++) {
                p[i] = processPath(p[i], attrs);
                fixArc(p, i);
                p2 && (p2[i] = processPath(p2[i], attrs2));
                p2 && fixArc(p2, i);
                fixM(p, p2, attrs, attrs2, i);
                fixM(p2, p, attrs2, attrs, i);
                var seg = p[i],
                    seg2 = p2 && p2[i],
                    seglen = seg[length],
                    seg2len = p2 && seg2[length];
                attrs.x = seg[seglen - 2];
                attrs.y = seg[seglen - 1];
                attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
                attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
                attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
                attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
                attrs2.x = p2 && seg2[seg2len - 2];
                attrs2.y = p2 && seg2[seg2len - 1];
            }
            return p2 ? [p, p2] : p;
        }, null, pathClone),
        parseDots = cacher(function (gradient) {
            var dots = [];
            for (var i = 0, ii = gradient[length]; i < ii; i++) {
                var dot = {},
                    par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
                dot.color = R.getRGB(par[1]);
                if (dot.color.error) {
                    return null;
                }
                dot.color = dot.color.hex;
                par[2] && (dot.offset = par[2] + "%");
                dots[push](dot);
            }
            for (i = 1, ii = dots[length] - 1; i < ii; i++) {
                if (!dots[i].offset) {
                    var start = toFloat(dots[i - 1].offset || 0),
                        end = 0;
                    for (var j = i + 1; j < ii; j++) {
                        if (dots[j].offset) {
                            end = dots[j].offset;
                            break;
                        }
                    }
                    if (!end) {
                        end = 100;
                        j = ii;
                    }
                    end = toFloat(end);
                    var d = (end - start) / (j - i + 1);
                    for (; i < j; i++) {
                        start += d;
                        dots[i].offset = start + "%";
                    }
                }
            }
            return dots;
        }),
        getContainer = function (x, y, w, h) {
            var container;
            if (R.is(x, string) || R.is(x, "object")) {
                container = R.is(x, string) ? doc.getElementById(x) : x;
                if (container.tagName) {
                    if (y == null) {
                        return {
                            container: container,
                            width: container.style.pixelWidth || container.offsetWidth,
                            height: container.style.pixelHeight || container.offsetHeight
                        };
                    } else {
                        return {container: container, width: y, height: w};
                    }
                }
            } else {
                return {container: 1, x: x, y: y, width: w, height: h};
            }
        },
        plugins = function (con, add) {
            var that = this;
            for (var prop in add) {
                if (add[has](prop) && !(prop in con)) {
                    switch (typeof add[prop]) {
                        case "function":
                            (function (f) {
                                con[prop] = con === that ? f : function () { return f[apply](that, arguments); };
                            })(add[prop]);
                        break;
                        case "object":
                            con[prop] = con[prop] || {};
                            plugins.call(this, con[prop], add[prop]);
                        break;
                        default:
                            con[prop] = add[prop];
                        break;
                    }
                }
            }
        },
        tear = function (el, paper) {
            el == paper.top && (paper.top = el.prev);
            el == paper.bottom && (paper.bottom = el.next);
            el.next && (el.next.prev = el.prev);
            el.prev && (el.prev.next = el.next);
        },
        tofront = function (el, paper) {
            if (paper.top === el) {
                return;
            }
            tear(el, paper);
            el.next = null;
            el.prev = paper.top;
            paper.top.next = el;
            paper.top = el;
        },
        toback = function (el, paper) {
            if (paper.bottom === el) {
                return;
            }
            tear(el, paper);
            el.next = paper.bottom;
            el.prev = null;
            paper.bottom.prev = el;
            paper.bottom = el;
        },
        insertafter = function (el, el2, paper) {
            tear(el, paper);
            el2 == paper.top && (paper.top = el);
            el2.next && (el2.next.prev = el);
            el.next = el2.next;
            el.prev = el2;
            el2.next = el;
        },
        insertbefore = function (el, el2, paper) {
            tear(el, paper);
            el2 == paper.bottom && (paper.bottom = el);
            el2.prev && (el2.prev.next = el);
            el.prev = el2.prev;
            el2.prev = el;
            el.next = el2;
        },
        removed = function (methodname) {
            return function () {
                throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object");
            };
        },
        radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/;
 
    // SVG
    if (R.svg) {
        Paper[proto].svgns = "http://www.w3.org/2000/svg";
        Paper[proto].xlink = "http://www.w3.org/1999/xlink";
        round = function (num) {
            return +num + (~~num === num) * .5;
        };
        var $ = function (el, attr) {
            if (attr) {
                for (var key in attr) {
                    if (attr[has](key)) {
                        el[setAttribute](key, attr[key] + E);
                    }
                }
            } else {
                el = doc.createElementNS(Paper[proto].svgns, el);
                el.style.webkitTapHighlightColor = "rgba(0,0,0,0)";
                return el;
            }
        };
        R[toString] = function () {
            return  "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
        };
        var thePath = function (pathString, SVG) {
            var el = $("path");
            SVG.canvas && SVG.canvas[appendChild](el);
            var p = new Element(el, SVG);
            p.type = "path";
            setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString});
            return p;
        };
        var addGradientFill = function (o, gradient, SVG) {
            var type = "linear",
                fx = .5, fy = .5,
                s = o.style;
            gradient = (gradient + E)[rp](radial_gradient, function (all, _fx, _fy) {
                type = "radial";
                if (_fx && _fy) {
                    fx = toFloat(_fx);
                    fy = toFloat(_fy);
                    var dir = ((fy > .5) * 2 - 1);
                    pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
                        (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
                        fy != .5 &&
                        (fy = fy.toFixed(5) - 1e-5 * dir);
                }
                return E;
            });
            gradient = gradient[split](/\s*\-\s*/);
            if (type == "linear") {
                var angle = gradient.shift();
                angle = -toFloat(angle);
                if (isNaN(angle)) {
                    return null;
                }
                var vector = [0, 0, math.cos(angle * math.PI / 180), math.sin(angle * math.PI / 180)],
                    max = 1 / (mmax(math.abs(vector[2]), math.abs(vector[3])) || 1);
                vector[2] *= max;
                vector[3] *= max;
                if (vector[2] < 0) {
                    vector[0] = -vector[2];
                    vector[2] = 0;
                }
                if (vector[3] < 0) {
                    vector[1] = -vector[3];
                    vector[3] = 0;
                }
            }
            var dots = parseDots(gradient);
            if (!dots) {
                return null;
            }
            var id = o.getAttribute(fillString);
            id = id.match(/^url\(#(.*)\)$/);
            id && SVG.defs.removeChild(doc.getElementById(id[1]));
            
            var el = $(type + "Gradient");
            el.id = "r" + (R._id++)[toString](36);
            $(el, type == "radial" ? {fx: fx, fy: fy} : {x1: vector[0], y1: vector[1], x2: vector[2], y2: vector[3]});
            SVG.defs[appendChild](el);
            for (var i = 0, ii = dots[length]; i < ii; i++) {
                var stop = $("stop");
                $(stop, {
                    offset: dots[i].offset ? dots[i].offset : !i ? "0%" : "100%",
                    "stop-color": dots[i].color || "#fff"
                });
                el[appendChild](stop);
            }
            $(o, {
                fill: "url(#" + el.id + ")",
                opacity: 1,
                "fill-opacity": 1
            });
            s.fill = E;
            s.opacity = 1;
            s.fillOpacity = 1;
            return 1;
        };
        var updatePosition = function (o) {
            var bbox = o.getBBox();
            $(o.pattern, {patternTransform: R.format("translate({0},{1})", bbox.x, bbox.y)});
        };
        var setFillAndStroke = function (o, params) {
            var dasharray = {
                    "": [0],
                    "none": [0],
                    "-": [3, 1],
                    ".": [1, 1],
                    "-.": [3, 1, 1, 1],
                    "-..": [3, 1, 1, 1, 1, 1],
                    ". ": [1, 3],
                    "- ": [4, 3],
                    "--": [8, 3],
                    "- .": [4, 3, 1, 3],
                    "--.": [8, 3, 1, 3],
                    "--..": [8, 3, 1, 3, 1, 3]
                },
                node = o.node,
                attrs = o.attrs,
                rot = o.rotate(),
                addDashes = function (o, value) {
                    value = dasharray[lowerCase.call(value)];
                    if (value) {
                        var width = o.attrs["stroke-width"] || "1",
                            butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
                            dashes = [];
                        var i = value[length];
                        while (i--) {
                            dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
                        }
                        $(node, {"stroke-dasharray": dashes[join](",")});
                    }
                };
            params[has]("rotation") && (rot = params.rotation);
            var rotxy = (rot + E)[split](separator);
            if (!(rotxy.length - 1)) {
                rotxy = null;
            } else {
                rotxy[1] = +rotxy[1];
                rotxy[2] = +rotxy[2];
            }
            toFloat(rot) && o.rotate(0, true);
            for (var att in params) {
                if (params[has](att)) {
                    if (!availableAttrs[has](att)) {
                        continue;
                    }
                    var value = params[att];
                    attrs[att] = value;
                    switch (att) {
                        case "blur":
                            o.blur(value);
                            break;
                        case "rotation":
                            o.rotate(value, true);
                            break;
                        case "href":
                        case "title":
                        case "target":
                            var pn = node.parentNode;
                            if (lowerCase.call(pn.tagName) != "a") {
                                var hl = $("a");
                                pn.insertBefore(hl, node);
                                hl[appendChild](node);
                                pn = hl;
                            }
                            pn.setAttributeNS(o.paper.xlink, att, value);
                            break;
                        case "cursor":
                            node.style.cursor = value;
                            break;
                        case "clip-rect":
                            var rect = (value + E)[split](separator);
                            if (rect[length] == 4) {
                                o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
                                var el = $("clipPath"),
                                    rc = $("rect");
                                el.id = "r" + (R._id++)[toString](36);
                                $(rc, {
                                    x: rect[0],
                                    y: rect[1],
                                    width: rect[2],
                                    height: rect[3]
                                });
                                el[appendChild](rc);
                                o.paper.defs[appendChild](el);
                                $(node, {"clip-path": "url(#" + el.id + ")"});
                                o.clip = rc;
                            }
                            if (!value) {
                                var clip = doc.getElementById(node.getAttribute("clip-path")[rp](/(^url\(#|\)$)/g, E));
                                clip && clip.parentNode.removeChild(clip);
                                $(node, {"clip-path": E});
                                delete o.clip;
                            }
                        break;
                        case "path":
                            if (o.type == "path") {
                                $(node, {d: value ? attrs.path = pathToAbsolute(value) : "M0,0"});
                            }
                            break;
                        case "width":
                            node[setAttribute](att, value);
                            if (attrs.fx) {
                                att = "x";
                                value = attrs.x;
                            } else {
                                break;
                            }
                        case "x":
                            if (attrs.fx) {
                                value = -attrs.x - (attrs.width || 0);
                            }
                        case "rx":
                            if (att == "rx" && o.type == "rect") {
                                break;
                            }
                        case "cx":
                            rotxy && (att == "x" || att == "cx") && (rotxy[1] += value - attrs[att]);
                            node[setAttribute](att, round(value));
                            o.pattern && updatePosition(o);
                            break;
                        case "height":
                            node[setAttribute](att, value);
                            if (attrs.fy) {
                                att = "y";
                                value = attrs.y;
                            } else {
                                break;
                            }
                        case "y":
                            if (attrs.fy) {
                                value = -attrs.y - (attrs.height || 0);
                            }
                        case "ry":
                            if (att == "ry" && o.type == "rect") {
                                break;
                            }
                        case "cy":
                            rotxy && (att == "y" || att == "cy") && (rotxy[2] += value - attrs[att]);
                            node[setAttribute](att, round(value));
                            o.pattern && updatePosition(o);
                            break;
                        case "r":
                            if (o.type == "rect") {
                                $(node, {rx: value, ry: value});
                            } else {
                                node[setAttribute](att, value);
                            }
                            break;
                        case "src":
                            if (o.type == "image") {
                                node.setAttributeNS(o.paper.xlink, "href", value);
                            }
                            break;
                        case "stroke-width":
                            node.style.strokeWidth = value;
                            // Need following line for Firefox
                            node[setAttribute](att, value);
                            if (attrs["stroke-dasharray"]) {
                                addDashes(o, attrs["stroke-dasharray"]);
                            }
                            break;
                        case "stroke-dasharray":
                            addDashes(o, value);
                            break;
                        case "translation":
                            var xy = (value + E)[split](separator);
                            xy[0] = +xy[0] || 0;
                            xy[1] = +xy[1] || 0;
                            if (rotxy) {
                                rotxy[1] += xy[0];
                                rotxy[2] += xy[1];
                            }
                            translate.call(o, xy[0], xy[1]);
                            break;
                        case "scale":
                            xy = (value + E)[split](separator);
                            o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, isNaN(toFloat(xy[2])) ? null : +xy[2], isNaN(toFloat(xy[3])) ? null : +xy[3]);
                            break;
                        case fillString:
                            var isURL = (value + E).match(ISURL);
                            if (isURL) {
                                el = $("pattern");
                                var ig = $("image");
                                el.id = "r" + (R._id++)[toString](36);
                                $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
                                $(ig, {x: 0, y: 0});
                                ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
                                el[appendChild](ig);
 
                                var img = doc.createElement("img");
                                img.style.cssText = "position:absolute;left:-9999em;top-9999em";
                                img.onload = function () {
                                    $(el, {width: this.offsetWidth, height: this.offsetHeight});
                                    $(ig, {width: this.offsetWidth, height: this.offsetHeight});
                                    doc.body.removeChild(this);
                                    o.paper.safari();
                                };
                                doc.body[appendChild](img);
                                img.src = isURL[1];
                                o.paper.defs[appendChild](el);
                                node.style.fill = "url(#" + el.id + ")";
                                $(node, {fill: "url(#" + el.id + ")"});
                                o.pattern = el;
                                o.pattern && updatePosition(o);
                                break;
                            }
                            var clr = R.getRGB(value);
                            if (!clr.error) {
                                delete params.gradient;
                                delete attrs.gradient;
                                !R.is(attrs.opacity, "undefined") &&
                                    R.is(params.opacity, "undefined") &&
                                    $(node, {opacity: attrs.opacity});
                                !R.is(attrs["fill-opacity"], "undefined") &&
                                    R.is(params["fill-opacity"], "undefined") &&
                                    $(node, {"fill-opacity": attrs["fill-opacity"]});
                            } else if ((({circle: 1, ellipse: 1})[has](o.type) || (value + E).charAt() != "r") && addGradientFill(node, value, o.paper)) {
                                attrs.gradient = value;
                                attrs.fill = "none";
                                break;
                            }
                            clr[has]("o") && $(node, {"fill-opacity": clr.o / 100});
                        case "stroke":
                            clr = R.getRGB(value);
                            node[setAttribute](att, clr.hex);
                            att == "stroke" && clr[has]("o") && $(node, {"stroke-opacity": clr.o / 100});
                            break;
                        case "gradient":
                            (({circle: 1, ellipse: 1})[has](o.type) || (value + E).charAt() != "r") && addGradientFill(node, value, o.paper);
                            break;
                        case "opacity":
                        case "fill-opacity":
                            if (attrs.gradient) {
                                var gradient = doc.getElementById(node.getAttribute(fillString)[rp](/^url\(#|\)$/g, E));
                                if (gradient) {
                                    var stops = gradient.getElementsByTagName("stop");
                                    stops[stops[length] - 1][setAttribute]("stop-opacity", value);
                                }
                                break;
                            }
                        default:
                            att == "font-size" && (value = toInt(value, 10) + "px");
                            var cssrule = att[rp](/(\-.)/g, function (w) {
                                return upperCase.call(w.substring(1));
                            });
                            node.style[cssrule] = value;
                            // Need following line for Firefox
                            node[setAttribute](att, value);
                            break;
                    }
                }
            }
            
            tuneText(o, params);
            if (rotxy) {
                o.rotate(rotxy.join(S));
            } else {
                toFloat(rot) && o.rotate(rot, true);
            }
        };
        var leading = 1.2,
        tuneText = function (el, params) {
            if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
                return;
            }
            var a = el.attrs,
                node = el.node,
                fontSize = node.firstChild ? toInt(doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
 
            if (params[has]("text")) {
                a.text = params.text;
                while (node.firstChild) {
                    node.removeChild(node.firstChild);
                }
                var texts = (params.text + E)[split]("\n");
                for (var i = 0, ii = texts[length]; i < ii; i++) if (texts[i]) {
                    var tspan = $("tspan");
                    i && $(tspan, {dy: fontSize * leading, x: a.x});
                    tspan[appendChild](doc.createTextNode(texts[i]));
                    node[appendChild](tspan);
                }
            } else {
                texts = node.getElementsByTagName("tspan");
                for (i = 0, ii = texts[length]; i < ii; i++) {
                    i && $(texts[i], {dy: fontSize * leading, x: a.x});
                }
            }
            $(node, {y: a.y});
            var bb = el.getBBox(),
                dif = a.y - (bb.y + bb.height / 2);
            dif && isFinite(dif) && $(node, {y: a.y + dif});
        },
        Element = function (node, svg) {
            var X = 0,
                Y = 0;
            this[0] = node;
            this.id = R._oid++;
            this.node = node;
            node.raphael = this;
            this.paper = svg;
            this.attrs = this.attrs || {};
            this.transformations = []; // rotate, translate, scale
            this._ = {
                tx: 0,
                ty: 0,
                rt: {deg: 0, cx: 0, cy: 0},
                sx: 1,
                sy: 1
            };
            !svg.bottom && (svg.bottom = this);
            this.prev = svg.top;
            svg.top && (svg.top.next = this);
            svg.top = this;
            this.next = null;
        };
        Element[proto].rotate = function (deg, cx, cy) {
            if (this.removed) {
                return this;
            }
            if (deg == null) {
                if (this._.rt.cx) {
                    return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
                }
                return this._.rt.deg;
            }
            var bbox = this.getBBox();
            deg = (deg + E)[split](separator);
            if (deg[length] - 1) {
                cx = toFloat(deg[1]);
                cy = toFloat(deg[2]);
            }
            deg = toFloat(deg[0]);
            if (cx != null) {
                this._.rt.deg = deg;
            } else {
                this._.rt.deg += deg;
            }
            (cy == null) && (cx = null);
            this._.rt.cx = cx;
            this._.rt.cy = cy;
            cx = cx == null ? bbox.x + bbox.width / 2 : cx;
            cy = cy == null ? bbox.y + bbox.height / 2 : cy;
            if (this._.rt.deg) {
                this.transformations[0] = R.format("rotate({0} {1} {2})", this._.rt.deg, cx, cy);
                this.clip && $(this.clip, {transform: R.format("rotate({0} {1} {2})", -this._.rt.deg, cx, cy)});
            } else {
                this.transformations[0] = E;
                this.clip && $(this.clip, {transform: E});
            }
            $(this.node, {transform: this.transformations[join](S)});
            return this;
        };
        Element[proto].hide = function () {
            !this.removed && (this.node.style.display = "none");
            return this;
        };
        Element[proto].show = function () {
            !this.removed && (this.node.style.display = "");
            return this;
        };
        Element[proto].remove = function () {
            if (this.removed) {
                return;
            }
            tear(this, this.paper);
            this.node.parentNode.removeChild(this.node);
            for (var i in this) {
                delete this[i];
            }
            this.removed = true;
        };
        Element[proto].getBBox = function () {
            if (this.removed) {
                return this;
            }
            if (this.type == "path") {
                return pathDimensions(this.attrs.path);
            }
            if (this.node.style.display == "none") {
                this.show();
                var hide = true;
            }
            var bbox = {};
            try {
                bbox = this.node.getBBox();
            } catch(e) {
                // Firefox 3.0.x plays badly here
            } finally {
                bbox = bbox || {};
            }
            if (this.type == "text") {
                bbox = {x: bbox.x, y: Infinity, width: 0, height: 0};
                for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
                    var bb = this.node.getExtentOfChar(i);
                    (bb.y < bbox.y) && (bbox.y = bb.y);
                    (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
                    (bb.x + bb.width - bbox.x > bbox.width) && (bbox.width = bb.x + bb.width - bbox.x);
                }
            }
            hide && this.hide();
            return bbox;
        };
        Element[proto].attr = function (name, value) {
            if (this.removed) {
                return this;
            }
            if (name == null) {
                var res = {};
                for (var i in this.attrs) if (this.attrs[has](i)) {
                    res[i] = this.attrs[i];
                }
                this._.rt.deg && (res.rotation = this.rotate());
                (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
                res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
                return res;
            }
            if (value == null && R.is(name, string)) {
                if (name == "translation") {
                    return translate.call(this);
                }
                if (name == "rotation") {
                    return this.rotate();
                }
                if (name == "scale") {
                    return this.scale();
                }
                if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
                    return this.attrs.gradient;
                }
                return this.attrs[name];
            }
            if (value == null && R.is(name, array)) {
                var values = {};
                for (var j = 0, jj = name.length; j < jj; j++) {
                    values[name[j]] = this.attr(name[j]);
                }
                return values;
            }
            if (value != null) {
                var params = {};
                params[name] = value;
                setFillAndStroke(this, params);
            } else if (name != null && R.is(name, "object")) {
                setFillAndStroke(this, name);
            }
            return this;
        };
        Element[proto].toFront = function () {
            if (this.removed) {
                return this;
            }
            this.node.parentNode[appendChild](this.node);
            var svg = this.paper;
            svg.top != this && tofront(this, svg);
            return this;
        };
        Element[proto].toBack = function () {
            if (this.removed) {
                return this;
            }
            if (this.node.parentNode.firstChild != this.node) {
                this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
                toback(this, this.paper);
                var svg = this.paper;
            }
            return this;
        };
        Element[proto].insertAfter = function (element) {
            if (this.removed) {
                return this;
            }
            var node = element.node;
            if (node.nextSibling) {
                node.parentNode.insertBefore(this.node, node.nextSibling);
            } else {
                node.parentNode[appendChild](this.node);
            }
            insertafter(this, element, this.paper);
            return this;
        };
        Element[proto].insertBefore = function (element) {
            if (this.removed) {
                return this;
            }
            var node = element.node;
            node.parentNode.insertBefore(this.node, node);
            insertbefore(this, element, this.paper);
            return this;
        };
        Element[proto].blur = function (size) {
            // Experimental. No Safari support. Use it on your own risk.
            var t = this;
            if (+size !== 0) {
                var fltr = $("filter"),
                    blur = $("feGaussianBlur");
                t.attrs.blur = size;
                fltr.id = "r" + (R._id++)[toString](36);
                $(blur, {stdDeviation: +size || 1.5});
                fltr.appendChild(blur);
                t.paper.defs.appendChild(fltr);
                t._blur = fltr;
                $(t.node, {filter: "url(#" + fltr.id + ")"});
            } else {
                if (t._blur) {
                    t._blur.parentNode.removeChild(t._blur);
                    delete t._blur;
                    delete t.attrs.blur;
                }
                t.node.removeAttribute("filter");
            }
        };
        var theCircle = function (svg, x, y, r) {
            x = round(x);
            y = round(y);
            var el = $("circle");
            svg.canvas && svg.canvas[appendChild](el);
            var res = new Element(el, svg);
            res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
            res.type = "circle";
            $(el, res.attrs);
            return res;
        };
        var theRect = function (svg, x, y, w, h, r) {
            x = round(x);
            y = round(y);
            var el = $("rect");
            svg.canvas && svg.canvas[appendChild](el);
            var res = new Element(el, svg);
            res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
            res.type = "rect";
            $(el, res.attrs);
            return res;
        };
        var theEllipse = function (svg, x, y, rx, ry) {
            x = round(x);
            y = round(y);
            var el = $("ellipse");
            svg.canvas && svg.canvas[appendChild](el);
            var res = new Element(el, svg);
            res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
            res.type = "ellipse";
            $(el, res.attrs);
            return res;
        };
        var theImage = function (svg, src, x, y, w, h) {
            var el = $("image");
            $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
            el.setAttributeNS(svg.xlink, "href", src);
            svg.canvas && svg.canvas[appendChild](el);
            var res = new Element(el, svg);
            res.attrs = {x: x, y: y, width: w, height: h, src: src};
            res.type = "image";
            return res;
        };
        var theText = function (svg, x, y, text) {
            var el = $("text");
            $(el, {x: x, y: y, "text-anchor": "middle"});
            svg.canvas && svg.canvas[appendChild](el);
            var res = new Element(el, svg);
            res.attrs = {x: x, y: y, "text-anchor": "middle", text: text, font: availableAttrs.font, stroke: "none", fill: "#000"};
            res.type = "text";
            setFillAndStroke(res, res.attrs);
            return res;
        };
        var setSize = function (width, height) {
            this.width = width || this.width;
            this.height = height || this.height;
            this.canvas[setAttribute]("width", this.width);
            this.canvas[setAttribute]("height", this.height);
            return this;
        };
        var create = function () {
            var con = getContainer[apply](0, arguments),
                container = con && con.container,
                x = con.x,
                y = con.y,
                width = con.width,
                height = con.height;
            if (!container) {
                throw new Error("SVG container not found.");
            }
            var cnvs = $("svg");
            x = x || 0;
            y = y || 0;
            width = width || 512;
            height = height || 342;
            $(cnvs, {
                xmlns: "http://www.w3.org/2000/svg",
                version: 1.1,
                width: width,
                height: height
            });
            if (container == 1) {
                cnvs.style.cssText = "position:absolute;left:" + x + "px;top:" + y + "px";
                doc.body[appendChild](cnvs);
            } else {
                if (container.firstChild) {
                    container.insertBefore(cnvs, container.firstChild);
                } else {
                    container[appendChild](cnvs);
                }
            }
            container = new Paper;
            container.width = width;
            container.height = height;
            container.canvas = cnvs;
            plugins.call(container, container, R.fn);
            container.clear();
            return container;
        };
        Paper[proto].clear = function () {
            var c = this.canvas;
            while (c.firstChild) {
                c.removeChild(c.firstChild);
            }
            this.bottom = this.top = null;
            (this.desc = $("desc"))[appendChild](doc.createTextNode("Created with Rapha\xebl"));
            c[appendChild](this.desc);
            c[appendChild](this.defs = $("defs"));
        };
        Paper[proto].remove = function () {
            this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
            for (var i in this) {
                this[i] = removed(i);
            }
        };
    }

    // VML
    if (R.vml) {
        var map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
            bites = /([clmz]),?([^clmz]*)/gi,
            val = /-?[^,\s-]+/g,
            coordsize = 1e3 + S + 1e3,
            zoom = 10,
            pathlike = {path: 1, rect: 1},
            path2vml = function (path) {
                var total =  /[ahqstv]/ig,
                    command = pathToAbsolute;
                (path + E).match(total) && (command = path2curve);
                total = /[clmz]/g;
                if (command == pathToAbsolute && !(path + E).match(total)) {
                    var res = (path + E)[rp](bites, function (all, command, args) {
                        var vals = [],
                            isMove = lowerCase.call(command) == "m",
                            res = map[command];
                        args[rp](val, function (value) {
                            if (isMove && vals[length] == 2) {
                                res += vals + map[command == "m" ? "l" : "L"];
                                vals = [];
                            }
                            vals[push](round(value * zoom));
                        });
                        return res + vals;
                    });
                    return res;
                }
                var pa = command(path), p, r;
                res = [];
                for (var i = 0, ii = pa[length]; i < ii; i++) {
                    p = pa[i];
                    r = lowerCase.call(pa[i][0]);
                    r == "z" && (r = "x");
                    for (var j = 1, jj = p[length]; j < jj; j++) {
                        r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
                    }
                    res[push](r);
                }
                return res[join](S);
            };
        
        R[toString] = function () {
            return  "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
        };
        thePath = function (pathString, vml) {
            var g = createNode("group");
            g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
            g.coordsize = vml.coordsize;
            g.coordorigin = vml.coordorigin;
            var el = createNode("shape"), ol = el.style;
            ol.width = vml.width + "px";
            ol.height = vml.height + "px";
            el.coordsize = coordsize;
            el.coordorigin = vml.coordorigin;
            g[appendChild](el);
            var p = new Element(el, g, vml),
                attr = {fill: "none", stroke: "#000"};
            pathString && (attr.path = pathString);
            p.isAbsolute = true;
            p.type = "path";
            p.path = [];
            p.Path = E;
            setFillAndStroke(p, attr);
            vml.canvas[appendChild](g);
            return p;
        };
        setFillAndStroke = function (o, params) {
            o.attrs = o.attrs || {};
            var node = o.node,
                a = o.attrs,
                s = node.style,
                xy,
                newpath = (params.x != a.x || params.y != a.y || params.width != a.width || params.height != a.height || params.r != a.r) && o.type == "rect",
                res = o;
            
            for (var par in params) if (params[has](par)) {
                a[par] = params[par];
            }
            if (newpath) {
                a.path = rectPath(a.x, a.y, a.width, a.height, a.r);
                o.X = a.x;
                o.Y = a.y;
                o.W = a.width;
                o.H = a.height;
            }
            params.href && (node.href = params.href);
            params.title && (node.title = params.title);
            params.target && (node.target = params.target);
            params.cursor && (s.cursor = params.cursor);
            "blur" in params && o.blur(params.blur);
            if (params.path && o.type == "path" || newpath) {
                    node.path = path2vml(a.path);
            }
            if (params.rotation != null) {
                o.rotate(params.rotation, true);
            }
            if (params.translation) {
                xy = (params.translation + E)[split](separator);
                translate.call(o, xy[0], xy[1]);
                if (o._.rt.cx != null) {
                    o._.rt.cx +=+ xy[0];
                    o._.rt.cy +=+ xy[1];
                    o.setBox(o.attrs, xy[0], xy[1]);
                }
            }
            if (params.scale) {
                xy = (params.scale + E)[split](separator);
                o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
            }
            if ("clip-rect" in params) {
                var rect = (params["clip-rect"] + E)[split](separator);
                if (rect[length] == 4) {
                    rect[2] = +rect[2] + (+rect[0]);
                    rect[3] = +rect[3] + (+rect[1]);
                    var div = node.clipRect || doc.createElement("div"),
                        dstyle = div.style,
                        group = node.parentNode;
                    dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
                    if (!node.clipRect) {
                        dstyle.position = "absolute";
                        dstyle.top = 0;
                        dstyle.left = 0;
                        dstyle.width = o.paper.width + "px";
                        dstyle.height = o.paper.height + "px";
                        group.parentNode.insertBefore(div, group);
                        div[appendChild](group);
                        node.clipRect = div;
                    }
                }
                if (!params["clip-rect"]) {
                    node.clipRect && (node.clipRect.style.clip = E);
                }
            }
            if (o.type == "image" && params.src) {
                node.src = params.src;
            }
            if (o.type == "image" && params.opacity) {
                node.filterOpacity = ms + ".Alpha(opacity=" + (params.opacity * 100) + ")";
                s.filter = (node.filterMatrix || E) + (node.filterOpacity || E);
            }
            params.font && (s.font = params.font);
            params["font-family"] && (s.fontFamily = '"' + params["font-family"][split](",")[0][rp](/^['"]+|['"]+$/g, E) + '"');
            params["font-size"] && (s.fontSize = params["font-size"]);
            params["font-weight"] && (s.fontWeight = params["font-weight"]);
            params["font-style"] && (s.fontStyle = params["font-style"]);
            if (params.opacity != null || 
                params["stroke-width"] != null ||
                params.fill != null ||
                params.stroke != null ||
                params["stroke-width"] != null ||
                params["stroke-opacity"] != null ||
                params["fill-opacity"] != null ||
                params["stroke-dasharray"] != null ||
                params["stroke-miterlimit"] != null ||
                params["stroke-linejoin"] != null ||
                params["stroke-linecap"] != null) {
                node = o.shape || node;
                var fill = (node.getElementsByTagName(fillString) && node.getElementsByTagName(fillString)[0]),
                    newfill = false;
                !fill && (newfill = fill = createNode(fillString));
                if ("fill-opacity" in params || "opacity" in params) {
                    var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
                    opacity < 0 && (opacity = 0);
                    opacity > 1 && (opacity = 1);
                    fill.opacity = opacity;
                }
                params.fill && (fill.on = true);
                if (fill.on == null || params.fill == "none") {
                    fill.on = false;
                }
                if (fill.on && params.fill) {
                    var isURL = params.fill.match(ISURL);
                    if (isURL) {
                        fill.src = isURL[1];
                        fill.type = "tile";
                    } else {
                        fill.color = R.getRGB(params.fill).hex;
                        fill.src = E;
                        fill.type = "solid";
                        if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || (params.fill + E).charAt() != "r") && addGradientFill(res, params.fill)) {
                            a.fill = "none";
                            a.gradient = params.fill;
                        }
                    }
                }
                newfill && node[appendChild](fill);
                var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
                newstroke = false;
                !stroke && (newstroke = stroke = createNode("stroke"));
                if ((params.stroke && params.stroke != "none") ||
                    params["stroke-width"] ||
                    params["stroke-opacity"] != null ||
                    params["stroke-dasharray"] ||
                    params["stroke-miterlimit"] ||
                    params["stroke-linejoin"] ||
                    params["stroke-linecap"]) {
                    stroke.on = true;
                }
                (params.stroke == "none" || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
                var strokeColor = R.getRGB(params.stroke);
                stroke.on && params.stroke && (stroke.color = strokeColor.hex);
                opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
                var width = (toFloat(params["stroke-width"]) || 1) * .75;
                opacity < 0 && (opacity = 0);
                opacity > 1 && (opacity = 1);
                params["stroke-width"] == null && (width = a["stroke-width"]);
                params["stroke-width"] && (stroke.weight = width);
                width && width < 1 && (opacity *= width) && (stroke.weight = 1);
                stroke.opacity = opacity;
                
                params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
                stroke.miterlimit = params["stroke-miterlimit"] || 8;
                params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
                if (params["stroke-dasharray"]) {
                    var dasharray = {
                        "-": "shortdash",
                        ".": "shortdot",
                        "-.": "shortdashdot",
                        "-..": "shortdashdotdot",
                        ". ": "dot",
                        "- ": "dash",
                        "--": "longdash",
                        "- .": "dashdot",
                        "--.": "longdashdot",
                        "--..": "longdashdotdot"
                    };
                    stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
                }
                newstroke && node[appendChild](stroke);
            }
            if (res.type == "text") {
                s = res.paper.span.style;
                a.font && (s.font = a.font);
                a["font-family"] && (s.fontFamily = a["font-family"]);
                a["font-size"] && (s.fontSize = a["font-size"]);
                a["font-weight"] && (s.fontWeight = a["font-weight"]);
                a["font-style"] && (s.fontStyle = a["font-style"]);
                res.node.string && (res.paper.span.innerHTML = (res.node.string + E)[rp](/</g, "&#60;")[rp](/&/g, "&#38;")[rp](/\n/g, "<br>"));
                res.W = a.w = res.paper.span.offsetWidth;
                res.H = a.h = res.paper.span.offsetHeight;
                res.X = a.x;
                res.Y = a.y + round(res.H / 2);
 
                // text-anchor emulationm
                switch (a["text-anchor"]) {
                    case "start":
                        res.node.style["v-text-align"] = "left";
                        res.bbx = round(res.W / 2);
                    break;
                    case "end":
                        res.node.style["v-text-align"] = "right";
                        res.bbx = -round(res.W / 2);
                    break;
                    default:
                        res.node.style["v-text-align"] = "center";
                    break;
                }
            }
        };
        addGradientFill = function (o, gradient) {
            o.attrs = o.attrs || {};
            var attrs = o.attrs,
                fill,
                type = "linear",
                fxfy = ".5 .5";
            o.attrs.gradient = gradient;
            gradient = (gradient + E)[rp](radial_gradient, function (all, fx, fy) {
                type = "radial";
                if (fx && fy) {
                    fx = toFloat(fx);
                    fy = toFloat(fy);
                    pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
                    fxfy = fx + S + fy;
                }
                return E;
            });
            gradient = gradient[split](/\s*\-\s*/);
            if (type == "linear") {
                var angle = gradient.shift();
                angle = -toFloat(angle);
                if (isNaN(angle)) {
                    return null;
                }
            }
            var dots = parseDots(gradient);
            if (!dots) {
                return null;
            }
            o = o.shape || o.node;
            fill = o.getElementsByTagName(fillString)[0] || createNode(fillString);
            !fill.parentNode && o.appendChild(fill);
            if (dots[length]) {
                fill.on = true;
                fill.method = "none";
                fill.color = dots[0].color;
                fill.color2 = dots[dots[length] - 1].color;
                var clrs = [];
                for (var i = 0, ii = dots[length]; i < ii; i++) {
                    dots[i].offset && clrs[push](dots[i].offset + S + dots[i].color);
                }
                fill.colors && (fill.colors.value = clrs[length] ? clrs[join]() : "0% " + fill.color);
                if (type == "radial") {
                    fill.type = "gradientradial";
                    fill.focus = "100%";
                    fill.focussize = fxfy;
                    fill.focusposition = fxfy;
                } else {
                    fill.type = "gradient";
                    fill.angle = (270 - angle) % 360;
                }
            }
            return 1;
        };
        Element = function (node, group, vml) {
            var Rotation = 0,
                RotX = 0,
                RotY = 0,
                Scale = 1;
            this[0] = node;
            this.id = R._oid++;
            this.node = node;
            node.raphael = this;
            this.X = 0;
            this.Y = 0;
            this.attrs = {};
            this.Group = group;
            this.paper = vml;
            this._ = {
                tx: 0,
                ty: 0,
                rt: {deg:0},
                sx: 1,
                sy: 1
            };
            !vml.bottom && (vml.bottom = this);
            this.prev = vml.top;
            vml.top && (vml.top.next = this);
            vml.top = this;
            this.next = null;
        };
        Element[proto].rotate = function (deg, cx, cy) {
            if (this.removed) {
                return this;
            }
            if (deg == null) {
                if (this._.rt.cx) {
                    return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
                }
                return this._.rt.deg;
            }
            deg = (deg + E)[split](separator);
            if (deg[length] - 1) {
                cx = toFloat(deg[1]);
                cy = toFloat(deg[2]);
            }
            deg = toFloat(deg[0]);
            if (cx != null) {
                this._.rt.deg = deg;
            } else {
                this._.rt.deg += deg;
            }
            cy == null && (cx = null);
            this._.rt.cx = cx;
            this._.rt.cy = cy;
            this.setBox(this.attrs, cx, cy);
            this.Group.style.rotation = this._.rt.deg;
            // gradient fix for rotation. TODO
            // var fill = (this.shape || this.node).getElementsByTagName(fillString);
            // fill = fill[0] || {};
            // var b = ((360 - this._.rt.deg) - 270) % 360;
            // !R.is(fill.angle, "undefined") && (fill.angle = b);
            return this;
        };
        Element[proto].setBox = function (params, cx, cy) {
            if (this.removed) {
                return this;
            }
            var gs = this.Group.style,
                os = (this.shape && this.shape.style) || this.node.style;
            params = params || {};
            for (var i in params) if (params[has](i)) {
                this.attrs[i] = params[i];
            }
            cx = cx || this._.rt.cx;
            cy = cy || this._.rt.cy;
            var attr = this.attrs,
                x,
                y,
                w,
                h;
            switch (this.type) {
                case "circle":
                    x = attr.cx - attr.r;
                    y = attr.cy - attr.r;
                    w = h = attr.r * 2;
                    break;
                case "ellipse":
                    x = attr.cx - attr.rx;
                    y = attr.cy - attr.ry;
                    w = attr.rx * 2;
                    h = attr.ry * 2;
                    break;
                case "image":
                    x = +attr.x;
                    y = +attr.y;
                    w = attr.width || 0;
                    h = attr.height || 0;
                    break;
                case "text":
                    this.textpath.v = ["m", round(attr.x), ", ", round(attr.y - 2), "l", round(attr.x) + 1, ", ", round(attr.y - 2)][join](E);
                    x = attr.x - round(this.W / 2);
                    y = attr.y - this.H / 2;
                    w = this.W;
                    h = this.H;
                    break;
                case "rect":
                case "path":
                    if (!this.attrs.path) {
                        x = 0;
                        y = 0;
                        w = this.paper.width;
                        h = this.paper.height;
                    } else {
                        var dim = pathDimensions(this.attrs.path);
                        x = dim.x;
                        y = dim.y;
                        w = dim.width;
                        h = dim.height;
                    }
                    break;
                default:
                    x = 0;
                    y = 0;
                    w = this.paper.width;
                    h = this.paper.height;
                    break;
            }
            cx = (cx == null) ? x + w / 2 : cx;
            cy = (cy == null) ? y + h / 2 : cy;
            var left = cx - this.paper.width / 2,
                top = cy - this.paper.height / 2, t;
            gs.left != (t = left + "px") && (gs.left = t);
            gs.top != (t = top + "px") && (gs.top = t);
            this.X = pathlike[has](this.type) ? -left : x;
            this.Y = pathlike[has](this.type) ? -top : y;
            this.W = w;
            this.H = h;
            if (pathlike[has](this.type)) {
                os.left != (t = -left * zoom + "px") && (os.left = t);
                os.top != (t = -top * zoom + "px") && (os.top = t);
            } else if (this.type == "text") {
                os.left != (t = -left + "px") && (os.left = t);
                os.top != (t = -top + "px") && (os.top = t);
            } else {
                gs.width != (t = this.paper.width + "px") && (gs.width = t);
                gs.height != (t = this.paper.height + "px") && (gs.height = t);
                os.left != (t = x - left + "px") && (os.left = t);
                os.top != (t = y - top + "px") && (os.top = t);
                os.width != (t = w + "px") && (os.width = t);
                os.height != (t = h + "px") && (os.height = t);
            }
        };
        Element[proto].hide = function () {
            !this.removed && (this.Group.style.display = "none");
            return this;
        };
        Element[proto].show = function () {
            !this.removed && (this.Group.style.display = "block");
            return this;
        };
        Element[proto].getBBox = function () {
            if (this.removed) {
                return this;
            }
            if (pathlike[has](this.type)) {
                return pathDimensions(this.attrs.path);
            }
            return {
                x: this.X + (this.bbx || 0),
                y: this.Y,
                width: this.W,
                height: this.H
            };
        };
        Element[proto].remove = function () {
            if (this.removed) {
                return;
            }
            tear(this, this.paper);
            this.node.parentNode.removeChild(this.node);
            this.Group.parentNode.removeChild(this.Group);
            this.shape && this.shape.parentNode.removeChild(this.shape);
            for (var i in this) {
                delete this[i];
            }
            this.removed = true;
        };
        Element[proto].attr = function (name, value) {
            if (this.removed) {
                return this;
            }
            if (name == null) {
                var res = {};
                for (var i in this.attrs) if (this.attrs[has](i)) {
                    res[i] = this.attrs[i];
                }
                this._.rt.deg && (res.rotation = this.rotate());
                (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
                res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
                return res;
            }
            if (value == null && R.is(name, string)) {
                if (name == "translation") {
                    return translate.call(this);
                }
                if (name == "rotation") {
                    return this.rotate();
                }
                if (name == "scale") {
                    return this.scale();
                }
                if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
                    return this.attrs.gradient;
                }
                return this.attrs[name];
            }
            if (this.attrs && value == null && R.is(name, array)) {
                var ii, values = {};
                for (i = 0, ii = name[length]; i < ii; i++) {
                    values[name[i]] = this.attr(name[i]);
                }
                return values;
            }
            var params;
            if (value != null) {
                params = {};
                params[name] = value;
            }
            value == null && R.is(name, "object") && (params = name);
            if (params) {
                if (params.text && this.type == "text") {
                    this.node.string = params.text;
                }
                setFillAndStroke(this, params);
                if (params.gradient && (({circle: 1, ellipse: 1})[has](this.type) || (params.gradient + E).charAt() != "r")) {
                    addGradientFill(this, params.gradient);
                }
                (!pathlike[has](this.type) || this._.rt.deg) && this.setBox(this.attrs);
            }
            return this;
        };
        Element[proto].toFront = function () {
            !this.removed && this.Group.parentNode[appendChild](this.Group);
            this.paper.top != this && tofront(this, this.paper);
            return this;
        };
        Element[proto].toBack = function () {
            if (this.removed) {
                return this;
            }
            if (this.Group.parentNode.firstChild != this.Group) {
                this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
                toback(this, this.paper);
            }
            return this;
        };
        Element[proto].insertAfter = function (element) {
            if (this.removed) {
                return this;
            }
            if (element.Group.nextSibling) {
                element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
            } else {
                element.Group.parentNode[appendChild](this.Group);
            }
            insertafter(this, element, this.paper);
            return this;
        };
        Element[proto].insertBefore = function (element) {
            if (this.removed) {
                return this;
            }
            element.Group.parentNode.insertBefore(this.Group, element.Group);
            insertbefore(this, element, this.paper);
            return this;
        };
        var blurregexp = / progid:\S+Blur\([^\)]+\)/g;
        Element[proto].blur = function (size) {
            var s = this.node.style,
                f = s.filter;
            f = f.replace(blurregexp, "");
            if (+size !== 0) {
                this.attrs.blur = size;
                s.filter = f + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
                s.margin = Raphael.format("-{0}px 0 0 -{0}px", Math.round(+size || 1.5));
            } else {
                s.filter = f;
                s.margin = 0;
                delete this.attrs.blur;
            }
        };
 
        theCircle = function (vml, x, y, r) {
            var g = createNode("group"),
                o = createNode("oval"),
                ol = o.style;
            g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
            g.coordsize = coordsize;
            g.coordorigin = vml.coordorigin;
            g[appendChild](o);
            var res = new Element(o, g, vml);
            res.type = "circle";
            setFillAndStroke(res, {stroke: "#000", fill: "none"});
            res.attrs.cx = x;
            res.attrs.cy = y;
            res.attrs.r = r;
            res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
            vml.canvas[appendChild](g);
            return res;
        };
        function rectPath(x, y, w, h, r) {
            if (r) {
                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);
            } else {
                return R.format("M{0},{1}l{2},0,0,{3},{4},0z", x, y, w, h, -w);
            }
        }
        theRect = function (vml, x, y, w, h, r) {
            var path = rectPath(x, y, w, h, r),
                res = vml.path(path),
                a = res.attrs;
            res.X = a.x = x;
            res.Y = a.y = y;
            res.W = a.width = w;
            res.H = a.height = h;
            a.r = r;
            a.path = path;
            res.type = "rect";
            return res;
        };
        theEllipse = function (vml, x, y, rx, ry) {
            var g = createNode("group"),
                o = createNode("oval"),
                ol = o.style;
            g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
            g.coordsize = coordsize;
            g.coordorigin = vml.coordorigin;
            g[appendChild](o);
            var res = new Element(o, g, vml);
            res.type = "ellipse";
            setFillAndStroke(res, {stroke: "#000"});
            res.attrs.cx = x;
            res.attrs.cy = y;
            res.attrs.rx = rx;
            res.attrs.ry = ry;
            res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
            vml.canvas[appendChild](g);
            return res;
        };
        theImage = function (vml, src, x, y, w, h) {
            var g = createNode("group"),
                o = createNode("image"),
                ol = o.style;
            g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
            g.coordsize = coordsize;
            g.coordorigin = vml.coordorigin;
            o.src = src;
            g[appendChild](o);
            var res = new Element(o, g, vml);
            res.type = "image";
            res.attrs.src = src;
            res.attrs.x = x;
            res.attrs.y = y;
            res.attrs.w = w;
            res.attrs.h = h;
            res.setBox({x: x, y: y, width: w, height: h});
            vml.canvas[appendChild](g);
            return res;
        };
        theText = function (vml, x, y, text) {
            var g = createNode("group"),
                el = createNode("shape"),
                ol = el.style,
                path = createNode("path"),
                ps = path.style,
                o = createNode("textpath");
            g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
            g.coordsize = coordsize;
            g.coordorigin = vml.coordorigin;
            path.v = R.format("m{0},{1}l{2},{1}", round(x * 10), round(y * 10), round(x * 10) + 1);
            path.textpathok = true;
            ol.width = vml.width;
            ol.height = vml.height;
            o.string = text + E;
            o.on = true;
            el[appendChild](o);
            el[appendChild](path);
            g[appendChild](el);
            var res = new Element(o, g, vml);
            res.shape = el;
            res.textpath = path;
            res.type = "text";
            res.attrs.text = text;
            res.attrs.x = x;
            res.attrs.y = y;
            res.attrs.w = 1;
            res.attrs.h = 1;
            setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
            res.setBox();
            vml.canvas[appendChild](g);
            return res;
        };
        setSize = function (width, height) {
            var cs = this.canvas.style;
            width == +width && (width += "px");
            height == +height && (height += "px");
            cs.width = width;
            cs.height = height;
            cs.clip = "rect(0 " + width + " " + height + " 0)";
            return this;
        };
        var createNode;
        doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
        try {
            !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
            createNode = function (tagName) {
                return doc.createElement('<rvml:' + tagName + ' class="rvml">');
            };
        } catch (e) {
            createNode = function (tagName) {
                return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
            };
        }
        create = function () {
            var con = getContainer[apply](0, arguments),
                container = con.container,
                height = con.height,
                s,
                width = con.width,
                x = con.x,
                y = con.y;
            if (!container) {
                throw new Error("VML container not found.");
            }
            var res = new Paper,
                c = res.canvas = doc.createElement("div"),
                cs = c.style;
            x = x || 0;
            y = y || 0;
            width = width || 512;
            height = height || 342;
            width == +width && (width += "px");
            height == +height && (height += "px");
            res.width = 1e3;
            res.height = 1e3;
            res.coordsize = zoom * 1e3 + S + zoom * 1e3;
            res.coordorigin = "0 0";
            res.span = doc.createElement("span");
            res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
            c[appendChild](res.span);
            cs.cssText = R.format("width:{0};height:{1};display:inline-block;position:relative;clip:rect(0 {0} {1} 0);overflow:hidden", width, height);
            if (container == 1) {
                doc.body[appendChild](c);
                cs.left = x + "px";
                cs.top = y + "px";
                cs.position = "absolute";
            } else {
                if (container.firstChild) {
                    container.insertBefore(c, container.firstChild);
                } else {
                    container[appendChild](c);
                }
            }
            plugins.call(res, res, R.fn);
            return res;
        };
        Paper[proto].clear = function () {
            this.canvas.innerHTML = E;
            this.span = doc.createElement("span");
            this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
            this.canvas[appendChild](this.span);
            this.bottom = this.top = null;
        };
        Paper[proto].remove = function () {
            this.canvas.parentNode.removeChild(this.canvas);
            for (var i in this) {
                this[i] = removed(i);
            }
            return true;
        };
    }
 
    // rest
    // Safari or Chrome (WebKit) rendering bug workaround method
    if ((/^Apple|^Google/).test(win.navigator.vendor) && (!(win.navigator.userAgent.indexOf("Version/4.0") + 1) || win.navigator.platform.slice(0, 2) == "iP")) {
        Paper[proto].safari = function () {
            var rect = this.rect(-99, -99, this.width + 99, this.height + 99);
            win.setTimeout(function () {rect.remove();});
        };
    } else {
        Paper[proto].safari = function () {};
    }
 
    // Events
    var preventDefault = function () {
        this.returnValue = false;
    },
    preventTouch = function () {
        return this.originalEvent.preventDefault();
    },
    stopPropagation = function () {
        this.cancelBubble = true;
    },
    stopTouch = function () {
        return this.originalEvent.stopPropagation();
    },
    addEvent = (function () {
        if (doc.addEventListener) {
            return function (obj, type, fn, element) {
                var realName = supportsTouch && touchMap[type] ? touchMap[type] : type;
                var f = function (e) {
                    if (supportsTouch && touchMap[has](type)) {
                        for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
                            if (e.targetTouches[i].target == obj) {
                                var olde = e;
                                e = e.targetTouches[i];
                                e.originalEvent = olde;
                                e.preventDefault = preventTouch;
                                e.stopPropagation = stopTouch;
                                break;
                            }
                        }
                    }
                    return fn.call(element, e);
                };
                obj.addEventListener(realName, f, false);
                return function () {
                    obj.removeEventListener(realName, f, false);
                    return true;
                };
            };
        } else if (doc.attachEvent) {
            return function (obj, type, fn, element) {
                var f = function (e) {
                    e = e || win.event;
                    e.preventDefault = e.preventDefault || preventDefault;
                    e.stopPropagation = e.stopPropagation || stopPropagation;
                    return fn.call(element, e);
                };
                obj.attachEvent("on" + type, f);
                var detacher = function () {
                    obj.detachEvent("on" + type, f);
                    return true;
                };
                return detacher;
            };
        }
    })();
    for (var i = events[length]; i--;) {
        (function (eventName) {
            R[eventName] = Element[proto][eventName] = function (fn) {
                if (R.is(fn, "function")) {
                    this.events = this.events || [];
                    this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || doc, eventName, fn, this)});
                }
                return this;
            };
            R["un" + eventName] = Element[proto]["un" + eventName] = function (fn) {
                var events = this.events,
                    l = events[length];
                while (l--) if (events[l].name == eventName && events[l].f == fn) {
                    events[l].unbind();
                    events.splice(l, 1);
                    !events.length && delete this.events;
                    return this;
                }
                return this;
            };
        })(events[i]);
    }
    Element[proto].hover = function (f_in, f_out) {
        return this.mouseover(f_in).mouseout(f_out);
    };
    Element[proto].unhover = function (f_in, f_out) {
        return this.unmouseover(f_in).unmouseout(f_out);
    };
    Element[proto].drag = function (onmove, onstart, onend) {
        this._drag = {};
        var el = this.mousedown(function (e) {
            (e.originalEvent ? e.originalEvent : e).preventDefault();
            this._drag.x = e.clientX;
            this._drag.y = e.clientY;
            this._drag.id = e.identifier;
            onstart && onstart.call(this, e.clientX, e.clientY);
            Raphael.mousemove(move).mouseup(up);
        }),
            move = function (e) {
                var x = e.clientX,
                    y = e.clientY;
                if (supportsTouch) {
                    var i = e.touches.length,
                        touch;
                    while (i--) {
                        touch = e.touches[i];
                        if (touch.identifier == el._drag.id) {
                            x = touch.clientX;
                            y = touch.clientY;
                            (e.originalEvent ? e.originalEvent : e).preventDefault();
                            break;
                        }
                    }
                } else {
                    e.preventDefault();
                }
                onmove && onmove.call(el, x - el._drag.x, y - el._drag.y, x, y);
            },
            up = function () {
                el._drag = {};
                Raphael.unmousemove(move).unmouseup(up);
                onend && onend.call(el);
            };
        return this;
    };
    Paper[proto].circle = function (x, y, r) {
        return theCircle(this, x || 0, y || 0, r || 0);
    };
    Paper[proto].rect = function (x, y, w, h, r) {
        return theRect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
    };
    Paper[proto].ellipse = function (x, y, rx, ry) {
        return theEllipse(this, x || 0, y || 0, rx || 0, ry || 0);
    };
    Paper[proto].path = function (pathString) {
        pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
        return thePath(R.format[apply](R, arguments), this);
    };
    Paper[proto].image = function (src, x, y, w, h) {
        return theImage(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
    };
    Paper[proto].text = function (x, y, text) {
        return theText(this, x || 0, y || 0, text || E);
    };
    Paper[proto].set = function (itemsArray) {
        arguments[length] > 1 && (itemsArray = Array[proto].splice.call(arguments, 0, arguments[length]));
        return new Set(itemsArray);
    };
    Paper[proto].setSize = setSize;
    Paper[proto].top = Paper[proto].bottom = null;
    Paper[proto].raphael = R;
    function x_y() {
        return this.x + S + this.y;
    }
    Element[proto].resetScale = function () {
        if (this.removed) {
            return this;
        }
        this._.sx = 1;
        this._.sy = 1;
        this.attrs.scale = "1 1";
    };
    Element[proto].scale = function (x, y, cx, cy) {
        if (this.removed) {
            return this;
        }
        if (x == null && y == null) {
            return {
                x: this._.sx,
                y: this._.sy,
                toString: x_y
            };
        }
        y = y || x;
        !+y && (y = x);
        var dx,
            dy,
            dcx,
            dcy,
            a = this.attrs;
        if (x != 0) {
            var bb = this.getBBox(),
                rcx = bb.x + bb.width / 2,
                rcy = bb.y + bb.height / 2,
                kx = x / this._.sx,
                ky = y / this._.sy;
            cx = (+cx || cx == 0) ? cx : rcx;
            cy = (+cy || cy == 0) ? cy : rcy;
            var dirx = ~~(x / math.abs(x)),
                diry = ~~(y / math.abs(y)),
                s = this.node.style,
                ncx = cx + (rcx - cx) * kx,
                ncy = cy + (rcy - cy) * ky;
            switch (this.type) {
                case "rect":
                case "image":
                    var neww = a.width * dirx * kx,
                        newh = a.height * diry * ky;
                    this.attr({
                        height: newh,
                        r: a.r * mmin(dirx * kx, diry * ky),
                        width: neww,
                        x: ncx - neww / 2,
                        y: ncy - newh / 2
                    });
                    break;
                case "circle":
                case "ellipse":
                    this.attr({
                        rx: a.rx * dirx * kx,
                        ry: a.ry * diry * ky,
                        r: a.r * mmin(dirx * kx, diry * ky),
                        cx: ncx,
                        cy: ncy
                    });
                    break;
                case "text":
                    this.attr({
                        x: ncx,
                        y: ncy
                    });
                    break;
                case "path":
                    var path = pathToRelative(a.path),
                        skip = true;
                    for (var i = 0, ii = path[length]; i < ii; i++) {
                        var p = path[i],
                            P0 = upperCase.call(p[0]);
                        if (P0 == "M" && skip) {
                            continue;
                        } else {
                            skip = false;
                        }
                        if (P0 == "A") {
                            p[path[i][length] - 2] *= kx;
                            p[path[i][length] - 1] *= ky;
                            p[1] *= dirx * kx;
                            p[2] *= diry * ky;
                            p[5] = +!(dirx + diry ? !+p[5] : +p[5]);
                        } else if (P0 == "H") {
                            for (var j = 1, jj = p[length]; j < jj; j++) {
                                p[j] *= kx;
                            }
                        } else if (P0 == "V") {
                            for (j = 1, jj = p[length]; j < jj; j++) {
                                p[j] *= ky;
                            }
                         } else {
                            for (j = 1, jj = p[length]; j < jj; j++) {
                                p[j] *= (j % 2) ? kx : ky;
                            }
                        }
                    }
                    var dim2 = pathDimensions(path);
                    dx = ncx - dim2.x - dim2.width / 2;
                    dy = ncy - dim2.y - dim2.height / 2;
                    path[0][1] += dx;
                    path[0][2] += dy;
                    this.attr({path: path});
                break;
            }
            if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
                if (this.transformations) {
                    this.transformations[2] = "scale("[concat](dirx, ",", diry, ")");
                    this.node[setAttribute]("transform", this.transformations[join](S));
                    dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
                    dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
                    this.attr({x: dx, y: dy});
                    a.fx = dirx - 1;
                    a.fy = diry - 1;
                } else {
                    this.node.filterMatrix = ms + ".Matrix(M11="[concat](dirx,
                        ", M12=0, M21=0, M22=", diry,
                        ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
                    s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
                }
            } else {
                if (this.transformations) {
                    this.transformations[2] = E;
                    this.node[setAttribute]("transform", this.transformations[join](S));
                    a.fx = 0;
                    a.fy = 0;
                } else {
                    this.node.filterMatrix = E;
                    s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
                }
            }
            a.scale = [x, y, cx, cy][join](S);
            this._.sx = x;
            this._.sy = y;
        }
        return this;
    };
    Element[proto].clone = function () {
        if (this.removed) {
            return null;
        }
        var attr = this.attr();
        delete attr.scale;
        delete attr.translation;
        return this.paper[this.type]().attr(attr);
    };
    var getPointAtSegmentLength = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
        var len = 0,
            old;
        for (var i = 0; i < 1.001; i+=.001) {
            var dot = R.findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i);
            i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
            if (len >= length) {
                return dot;
            }
            old = dot;
        }
    }),
    getLengthFactory = function (istotal, subpath) {
        return function (path, length, onlystart) {
            path = path2curve(path);
            var x, y, p, l, sp = "", subpaths = {}, point,
                len = 0;
            for (var i = 0, ii = path.length; i < ii; i++) {
                p = path[i];
                if (p[0] == "M") {
                    x = +p[1];
                    y = +p[2];
                } else {
                    l = segmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
                    if (len + l > length) {
                        if (subpath && !subpaths.start) {
                            point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
                            sp += ["C", point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
                            if (onlystart) {return sp;}
                            subpaths.start = sp;
                            sp = ["M", point.x, point.y + "C", point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]][join]();
                            len += l;
                            x = +p[5];
                            y = +p[6];
                            continue;
                        }
                        if (!istotal && !subpath) {
                            point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
                            return {x: point.x, y: point.y, alpha: point.alpha};
                        }
                    }
                    len += l;
                    x = +p[5];
                    y = +p[6];
                }
                sp += p;
            }
            subpaths.end = sp;
            point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[1], p[2], p[3], p[4], p[5], p[6], 1);
            point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha});
            return point;
        };
    },
    segmentLength = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
        var old = {x: 0, y: 0},
            len = 0;
        for (var i = 0; i < 1.01; i+=.01) {
            var dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i);
            i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
            old = dot;
        }
        return len;
    });
    var getTotalLength = getLengthFactory(1),
        getPointAtLength = getLengthFactory(),
        getSubpathsAtLength = getLengthFactory(0, 1);
    Element[proto].getTotalLength = function () {
        if (this.type != "path") {return;}
        if (this.node.getTotalLength) {
            return this.node.getTotalLength();
        }
        return getTotalLength(this.attrs.path);
    };
    Element[proto].getPointAtLength = function (length) {
        if (this.type != "path") {return;}
        return getPointAtLength(this.attrs.path, length);
    };
    Element[proto].getSubpath = function (from, to) {
        if (this.type != "path") {return;}
        if (math.abs(this.getTotalLength() - to) < 1e-6) {
            return getSubpathsAtLength(this.attrs.path, from).end;
        }
        var a = getSubpathsAtLength(this.attrs.path, to, 1);
        return from ? getSubpathsAtLength(a, from).end : a;
    };

    // animation easing formulas
    R.easing_formulas = {
        linear: function (n) {
            return n;
        },
        "<": function (n) {
            return pow(n, 3);
        },
        ">": function (n) {
            return pow(n - 1, 3) + 1;
        },
        "<>": function (n) {
            n = n * 2;
            if (n < 1) {
                return pow(n, 3) / 2;
            }
            n -= 2;
            return (pow(n, 3) + 2) / 2;
        },
        backIn: function (n) {
            var s = 1.70158;
            return n * n * ((s + 1) * n - s);
        },
        backOut: function (n) {
            n = n - 1;
            var s = 1.70158;
            return n * n * ((s + 1) * n + s) + 1;
        },
        elastic: function (n) {
            if (n == 0 || n == 1) {
                return n;
            }
            var p = .3,
                s = p / 4;
            return pow(2, -10 * n) * math.sin((n - s) * (2 * math.PI) / p) + 1;
        },
        bounce: function (n) {
            var s = 7.5625,
                p = 2.75,
                l;
            if (n < (1 / p)) {
                l = s * n * n;
            } else {
                if (n < (2 / p)) {
                    n -= (1.5 / p);
                    l = s * n * n + .75;
                } else {
                    if (n < (2.5 / p)) {
                        n -= (2.25 / p);
                        l = s * n * n + .9375;
                    } else {
                        n -= (2.625 / p);
                        l = s * n * n + .984375;
                    }
                }
            }
            return l;
        }
    };

    var animationElements = {length : 0},
        animation = function () {
            var Now = +new Date;
            for (var l in animationElements) if (l != "length" && animationElements[has](l)) {
                var e = animationElements[l];
                if (e.stop || e.el.removed) {
                    delete animationElements[l];
                    animationElements[length]--;
                    continue;
                }
                var time = Now - e.start,
                    ms = e.ms,
                    easing = e.easing,
                    from = e.from,
                    diff = e.diff,
                    to = e.to,
                    t = e.t,
                    prev = e.prev || 0,
                    that = e.el,
                    callback = e.callback,
                    set = {},
                    now;
                if (time < ms) {
                    var pos = R.easing_formulas[easing] ? R.easing_formulas[easing](time / ms) : time / ms;
                    for (var attr in from) if (from[has](attr)) {
                        switch (availableAnimAttrs[attr]) {
                            case "along":
                                now = pos * ms * diff[attr];
                                to.back && (now = to.len - now);
                                var point = getPointAtLength(to[attr], now);
                                that.translate(diff.sx - diff.x || 0, diff.sy - diff.y || 0);
                                diff.x = point.x;
                                diff.y = point.y;
                                that.translate(point.x - diff.sx, point.y - diff.sy);
                                to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
                                break;
                            case nu:
                                now = +from[attr] + pos * ms * diff[attr];
                                break;
                            case "colour":
                                now = "rgb(" + [
                                    upto255(round(from[attr].r + pos * ms * diff[attr].r)),
                                    upto255(round(from[attr].g + pos * ms * diff[attr].g)),
                                    upto255(round(from[attr].b + pos * ms * diff[attr].b))
                                ][join](",") + ")";
                                break;
                            case "path":
                                now = [];
                                for (var i = 0, ii = from[attr][length]; i < ii; i++) {
                                    now[i] = [from[attr][i][0]];
                                    for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
                                        now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
                                    }
                                    now[i] = now[i][join](S);
                                }
                                now = now[join](S);
                                break;
                            case "csv":
                                switch (attr) {
                                    case "translation":
                                        var x = diff[attr][0] * (time - prev),
                                            y = diff[attr][1] * (time - prev);
                                        t.x += x;
                                        t.y += y;
                                        now = x + S + y;
                                    break;
                                    case "rotation":
                                        now = +from[attr][0] + pos * ms * diff[attr][0];
                                        from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
                                    break;
                                    case "scale":
                                        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);
                                    break;
                                    case "clip-rect":
                                        now = [];
                                        i = 4;
                                        while (i--) {
                                            now[i] = +from[attr][i] + pos * ms * diff[attr][i];
                                        }
                                    break;
                                }
                                break;
                        }
                        set[attr] = now;
                    }
                    that.attr(set);
                    that._run && that._run.call(that);
                } else {
                    if (to.along) {
                        point = getPointAtLength(to.along, to.len * !to.back);
                        that.translate(diff.sx - (diff.x || 0) + point.x - diff.sx, diff.sy - (diff.y || 0) + point.y - diff.sy);
                        to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
                    }
                    (t.x || t.y) && that.translate(-t.x, -t.y);
                    to.scale && (to.scale += E);
                    that.attr(to);
                    delete animationElements[l];
                    animationElements[length]--;
                    that.in_animation = null;
                    R.is(callback, "function") && callback.call(that);
                }
                e.prev = time;
            }
            R.svg && that && that.paper && that.paper.safari();
            animationElements[length] && win.setTimeout(animation);
        },
        upto255 = function (color) {
            return mmax(mmin(color, 255), 0);
        },
        translate = function (x, y) {
            if (x == null) {
                return {x: this._.tx, y: this._.ty, toString: x_y};
            }
            this._.tx += +x;
            this._.ty += +y;
            switch (this.type) {
                case "circle":
                case "ellipse":
                    this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy});
                    break;
                case "rect":
                case "image":
                case "text":
                    this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y});
                    break;
                case "path":
                    var path = pathToRelative(this.attrs.path);
                    path[0][1] += +x;
                    path[0][2] += +y;
                    this.attr({path: path});
                break;
            }
            return this;
        };
    Element[proto].animateWith = function (element, params, ms, easing, callback) {
        animationElements[element.id] && (params.start = animationElements[element.id].start);
        return this.animate(params, ms, easing, callback);
    };
    Element[proto].animateAlong = along();
    Element[proto].animateAlongBack = along(1);
    function along(isBack) {
        return function (path, ms, rotate, callback) {
            var params = {back: isBack};
            R.is(rotate, "function") ? (callback = rotate) : (params.rot = rotate);
            path && path.constructor == Element && (path = path.attrs.path);
            path && (params.along = path);
            return this.animate(params, ms, callback);
        };
    }
    Element[proto].onAnimation = function (f) {
        this._run = f || 0;
        return this;
    };
    Element[proto].animate = function (params, ms, easing, callback) {
        if (R.is(easing, "function") || !easing) {
            callback = easing || null;
        }
        var from = {},
            to = {},
            diff = {};
        for (var attr in params) if (params[has](attr)) {
            if (availableAnimAttrs[has](attr)) {
                from[attr] = this.attr(attr);
                (from[attr] == null) && (from[attr] = availableAttrs[attr]);
                to[attr] = params[attr];
                switch (availableAnimAttrs[attr]) {
                    case "along":
                        var len = getTotalLength(params[attr]),
                            point = getPointAtLength(params[attr], len * !!params.back),
                            bb = this.getBBox();
                        diff[attr] = len / ms;
                        diff.tx = bb.x;
                        diff.ty = bb.y;
                        diff.sx = point.x;
                        diff.sy = point.y;
                        to.rot = params.rot;
                        to.back = params.back;
                        to.len = len;
                        params.rot && (diff.r = toFloat(this.rotate()) || 0);
                        break;
                    case nu:
                        diff[attr] = (to[attr] - from[attr]) / ms;
                        break;
                    case "colour":
                        from[attr] = R.getRGB(from[attr]);
                        var toColour = R.getRGB(to[attr]);
                        diff[attr] = {
                            r: (toColour.r - from[attr].r) / ms,
                            g: (toColour.g - from[attr].g) / ms,
                            b: (toColour.b - from[attr].b) / ms
                        };
                        break;
                    case "path":
                        var pathes = path2curve(from[attr], to[attr]);
                        from[attr] = pathes[0];
                        var toPath = pathes[1];
                        diff[attr] = [];
                        for (var i = 0, ii = from[attr][length]; i < ii; i++) {
                            diff[attr][i] = [0];
                            for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
                                diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
                            }
                        }
                        break;
                    case "csv":
                        var values = (params[attr] + E)[split](separator),
                            from2 = (from[attr] + E)[split](separator);
                        switch (attr) {
                            case "translation":
                                from[attr] = [0, 0];
                                diff[attr] = [values[0] / ms, values[1] / ms];
                            break;
                            case "rotation":
                                from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
                                diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
                            break;
                            case "scale":
                                params[attr] = values;
                                from[attr] = (from[attr] + E)[split](separator);
                                diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
                            break;
                            case "clip-rect":
                                from[attr] = (from[attr] + E)[split](separator);
                                diff[attr] = [];
                                i = 4;
                                while (i--) {
                                    diff[attr][i] = (values[i] - from[attr][i]) / ms;
                                }
                            break;
                        }
                        to[attr] = values;
                }
            }
        }
        this.stop();
        this.in_animation = 1;
        animationElements[this.id] = {
            start: params.start || +new Date,
            ms: ms,
            easing: easing,
            from: from,
            diff: diff,
            to: to,
            el: this,
            callback: callback,
            t: {x: 0, y: 0}
        };
        ++animationElements[length] == 1 && animation();
        return this;
    };
    Element[proto].stop = function () {
        animationElements[this.id] && animationElements[length]--;
        delete animationElements[this.id];
        return this;
    };
    Element[proto].translate = function (x, y) {
        return this.attr({translation: x + " " + y});
    };
    Element[proto][toString] = function () {
        return "Rapha\xebl\u2019s object";
    };
    R.ae = animationElements;
 
    // Set
    var Set = function (items) {
        this.items = [];
        this[length] = 0;
        this.type = "set";
        if (items) {
            for (var i = 0, ii = items[length]; i < ii; i++) {
                if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
                    this[this.items[length]] = this.items[this.items[length]] = items[i];
                    this[length]++;
                }
            }
        }
    };
    Set[proto][push] = function () {
        var item,
            len;
        for (var i = 0, ii = arguments[length]; i < ii; i++) {
            item = arguments[i];
            if (item && (item.constructor == Element || item.constructor == Set)) {
                len = this.items[length];
                this[len] = this.items[len] = item;
                this[length]++;
            }
        }
        return this;
    };
    Set[proto].pop = function () {
        delete this[this[length]--];
        return this.items.pop();
    };
    for (var method in Element[proto]) if (Element[proto][has](method)) {
        Set[proto][method] = (function (methodname) {
            return function () {
                for (var i = 0, ii = this.items[length]; i < ii; i++) {
                    this.items[i][methodname][apply](this.items[i], arguments);
                }
                return this;
            };
        })(method);
    }
    Set[proto].attr = function (name, value) {
        if (name && R.is(name, array) && R.is(name[0], "object")) {
            for (var j = 0, jj = name[length]; j < jj; j++) {
                this.items[j].attr(name[j]);
            }
        } else {
            for (var i = 0, ii = this.items[length]; i < ii; i++) {
                this.items[i].attr(name, value);
            }
        }
        return this;
    };
    Set[proto].animate = function (params, ms, easing, callback) {
        (R.is(easing, "function") || !easing) && (callback = easing || null);
        var len = this.items[length],
            i = len,
            item,
            set = this,
            collector;
        callback && (collector = function () {
            !--len && callback.call(set);
        });
        easing = R.is(easing, string) ? easing : collector;
        item = this.items[--i].animate(params, ms, easing, collector);
        while (i--) {
            this.items[i].animateWith(item, params, ms, easing, collector);
        }
        return this;
    };
    Set[proto].insertAfter = function (el) {
        var i = this.items[length];
        while (i--) {
            this.items[i].insertAfter(el);
        }
        return this;
    };
    Set[proto].getBBox = function () {
        var x = [],
            y = [],
            w = [],
            h = [];
        for (var i = this.items[length]; i--;) {
            var box = this.items[i].getBBox();
            x[push](box.x);
            y[push](box.y);
            w[push](box.x + box.width);
            h[push](box.y + box.height);
        }
        x = mmin[apply](0, x);
        y = mmin[apply](0, y);
        return {
            x: x,
            y: y,
            width: mmax[apply](0, w) - x,
            height: mmax[apply](0, h) - y
        };
    };
    Set[proto].clone = function (s) {
        s = new Set;
        for (var i = 0, ii = this.items[length]; i < ii; i++) {
            s[push](this.items[i].clone());
        }
        return s;
    };

    R.registerFont = function (font) {
        if (!font.face) {
            return font;
        }
        this.fonts = this.fonts || {};
        var fontcopy = {
                w: font.w,
                face: {},
                glyphs: {}
            },
            family = font.face["font-family"];
        for (var prop in font.face) if (font.face[has](prop)) {
            fontcopy.face[prop] = font.face[prop];
        }
        if (this.fonts[family]) {
            this.fonts[family][push](fontcopy);
        } else {
            this.fonts[family] = [fontcopy];
        }
        if (!font.svg) {
            fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
            for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
                var path = font.glyphs[glyph];
                fontcopy.glyphs[glyph] = {
                    w: path.w,
                    k: {},
                    d: path.d && "M" + path.d[rp](/[mlcxtrv]/g, function (command) {
                            return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
                        }) + "z"
                };
                if (path.k) {
                    for (var k in path.k) if (path[has](k)) {
                        fontcopy.glyphs[glyph].k[k] = path.k[k];
                    }
                }
            }
        }
        return font;
    };
    Paper[proto].getFont = function (family, weight, style, stretch) {
        stretch = stretch || "normal";
        style = style || "normal";
        weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
        if (!R.fonts) {
            return;
        }
        var font = R.fonts[family];
        if (!font) {
            var name = new RegExp("(^|\\s)" + family[rp](/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
            for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
                if (name.test(fontName)) {
                    font = R.fonts[fontName];
                    break;
                }
            }
        }
        var thefont;
        if (font) {
            for (var i = 0, ii = font[length]; i < ii; i++) {
                thefont = font[i];
                if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
                    break;
                }
            }
        }
        return thefont;
    };
    Paper[proto].print = function (x, y, string, font, size, origin) {
        origin = origin || "middle"; // baseline|middle
        var out = this.set(),
            letters = (string + E)[split](E),
            shift = 0,
            path = E,
            scale;
        R.is(font, string) && (font = this.getFont(font));
        if (font) {
            scale = (size || 16) / font.face["units-per-em"];
            var bb = font.face.bbox.split(separator),
                top = +bb[0],
                height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
            for (var i = 0, ii = letters[length]; i < ii; i++) {
                var prev = i && font.glyphs[letters[i - 1]] || {},
                    curr = font.glyphs[letters[i]];
                shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0;
                curr && curr.d && out[push](this.path(curr.d).attr({fill: "#000", stroke: "none", translation: [shift, 0]}));
            }
            out.scale(scale, scale, top, height).translate(x - top, y - height);
        }
        return out;
    };

    var formatrg = /\{(\d+)\}/g;
    R.format = function (token, params) {
        var args = R.is(params, array) ? [0][concat](params) : arguments;
        token && R.is(token, string) && args[length] - 1 && (token = token[rp](formatrg, function (str, i) {
            return args[++i] == null ? E : args[i];
        }));
        return token || E;
    };
    R.ninja = function () {
        oldRaphael.was ? (Raphael = oldRaphael.is) : delete Raphael;
        return R;
    };
    R.el = Element[proto];
    return R;
})();
/*

HTMLHttpRequest v1.0RC1 Preview
(c) 2001-2007 Angus Turnbull, TwinHelix Designs http://www.twinhelix.com

Licensed under the CC-GNU LGPL, version 2.1 or later:
http://creativecommons.org/licenses/LGPL/2.1/
This is distributed WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

*/



// Some common event API code I use. Syntax:
//   addEvent(object_reference, 'name_of_event', function_reference, legacy);
// 'name_of_event' is without the 'on' prefix, e.g. 'load', 'click' or 'mouseover'.
// 'legacy' disables addEventListener if true.
// You can add multiple events to one object, and in MSIE all are removed onunload.

if (typeof addEvent != 'function')
{
 var addEvent = function(o, t, f, l)
 {
  var d = 'addEventListener', n = 'on' + t;
  if (o[d] && !l) return o[d](t, f, false);
  if (!o._evts) o._evts = {};
  if (!o._evts[t])
  {
   o._evts[t] = {};
   if (o[n]) addEvent(o, t, o[n], l);
   o[n] = new Function('e',
    'var r = true, o = this, a = o._evts["' + t + '"], i; for (i in a) {' +
    'o._f = a[i]; if (o._f._i) r = o._f(e||window.event) != false && r;' +
    '} o._f = null; return r');
  }
  if (!f._i) f._i = addEvent._i++;
  o._evts[t][f._i] = f;
  if (t != 'unload') addEvent(window, 'unload', function() {
   removeEvent(o, t, f, l);
  });
 };
 addEvent._i = 1;
 var removeEvent = function(o, t, f, l)
 {
  var d = 'removeEventListener';
  if (o[d] && !l) return o[d](t, f, false);
  if (o._evts && o._evts[t] && f._i) delete o._evts[t][f._i];
 };
}

function cancelEvent(e, c)
{
 e.returnValue = false;
 if (e.preventDefault) e.preventDefault();
 if (c)
 {
  e.cancelBubble = true;
  if (e.stopPropagation) e.stopPropagation();
 }
};



var HTMLHttp = {};

// SYNTAX INSTRUCTIONS for HTMLHttp.Request:
//
// var objectName = new HTMLHttp.Request('objectName');
//
// Create an instance of an HTMLHttp object, and pass its own name as a string.
// NOTE: All requested documents must reside on the same domain as this document!
//
// Available methods are:
//
// objectName.load('file.html', callback_function);
//
// This will issue a GET request to the server to return a named file.
// Returns true if the load is successful.
//
// objectName.submit(form_reference, callback_function);
//
// This will capture a form's submission and redirect it to a background POST or GET
// request, respecting the form's 'method' attribute and its 'action' URI.
// Pass it a reference to the form's DOM node.
// Note that the form should already be in the process of submission when this is called.
// It is therefore suggested that you call it from within an ONSUBMIT handler on a form.
// It will return "true" when the capture is successful and the form submittal may
// be cancelled, or "false" when either the browser is unsupported or the IFRAME
// submittal method is used (in which case the form submit should proceed).
//
// You can/should also pass callback functions as second parameters above.
// They will be called on load/submit as methods of this object with parameters:
//  1) A reference to the loaded DOM document (which you may then parse).
//  2) The text content of the loaded document.

HTMLHttp.Request = function(myName)
{
 this.myName = myName;
 this.callback = null;
 // A loading flag, set to the requested URI when loading.
 this.loadingURI = '';

 // 'xmlhttp': Our preferred request object.
 this.xmlhttp = null;

 // Attempt to init an XMLHttpRequest object where supported.
 // Note: MSIE7 is best with the IFRAME method, so exclude IE here.
 if (window.XMLHttpRequest && !window.ActiveXObject) this.xmlhttp = new XMLHttpRequest();

 if (!this.xmlhttp && window.ActiveXObject)
 {
  try
  {
   this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch (e)
  {
   try
   {
    this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   }
   catch (e) { }
  }
 }

 // If installed, activate the IFRAME buffer setup.
 // Not required in new browsers, shipped in separate .JS file.
 if (!this.xmlhttp && this.iframeSetup) this.iframeSetup();

 // TODO: Put in further DOM3 LSParser support as a transport layer...?

 return this;
};



HTMLHttp.Request.prototype.parseForm = function(form)
{
 // Parses a form DOM reference to an escaped string suitable for GET/POSTing.

 var str = '', gE = 'getElementsByTagName', inputs = [
  (form[gE] ? form[gE]('input') : form.all ? form.all.tags('input') : []),
  (form[gE] ? form[gE]('select') : form.all ? form.all.tags('select') : []),
  (form[gE] ? form[gE]('textarea') : form.all ? form.all.tags('textarea') : [])
 ];

 // Loop through each list of tags, constructing our string.
 for (var i = 0; i < inputs.length; i++)
  for (j = 0; j < inputs[i].length; j++)
   if (inputs[i][j])
   {
    var elm = inputs[i][j];
    if ((elm.nodeName.toLowerCase() == 'input') &&
        { 'radio': 1, 'checkbox': 1 }[elm.type] && !elm.checked) continue;
    var plus = '++'.substring(0,1); // CodeTrim fix. Yeah, I know.
    str += escape(elm.name).replace(plus, '%2B') +
     '=' + escape(elm.value).replace(plus, '%2B') + '&';
   }

 // Strip trailing ampersand, because we can :)
 return str.substring(0, str.length - 1);
};



HTMLHttp.Request.prototype.xmlhttpSend = function(uri, formStr)
{
 // Use XMLHttpRequest to asynchronously open a URI, and optionally POST a provided
 // form string if any (otherwise, performs a GET).

 this.xmlhttp.open(formStr ? 'POST' : 'GET', uri, true);
 var obj = this;
 this.xmlhttp.onreadystatechange = function()
 {
  if (obj.xmlhttp.readyState == 4)
  {
   // If you are getting an error where either of these value are null, try changing
   // the MIME type returned by the server: setting it to text/xml usually works well!
   if (obj.callback) obj.callback(obj.xmlhttp.responseXML, obj.xmlhttp.responseText);
   obj.loadingURI = '';
  }
 };
 if (formStr)
  this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 // You might need to customise this.
 if (typeof this.xmlhttp.overrideMimeType == 'function')
  this.xmlhttp.overrideMimeType((/\.txt/i).test(uri) ? 'text/plain' : 'text/xml');

 this.xmlhttp.send(formStr);
 this.loadingURI = uri;
 return true;
};



// *** PUBLIC METHODS ***

HTMLHttp.Request.prototype.load = function(uri, callback)
{
 // Pass a URI and a callback function to load a plain text document.
 // Returns true if the load was successful.

 if (!uri || (!this.xmlhttp && !this.iframe)) return false;
 // Route the GET through an available transport layer.
 this.callback = callback;
 if (this.xmlhttp) return this.xmlhttpSend(uri, '');
 else if (this.iframe) return this.iframeSend(uri, null);
 else return false;
};


HTMLHttp.Request.prototype.submit = function(formRef, callback)
{
 // Pass a reference to a (submitting) form DOM node and a callback function.
 // Returns true if the load/capture was successful.

 if (!formRef || (!this.xmlhttp && !this.iframe)) return false;

 // Retrieve form information then decide what to do with it.
 var method = formRef.getAttribute('method'), uri = formRef.getAttribute('action');

 if (method && method.toUpperCase() == 'POST')
 {
  // Send the URI and either a parsed form or a form reference to the transports.
  // Note we only cancel form for XMLHTTP, as IFRAMEs still need it to submit.
  this.callback = callback;
  if (this.xmlhttp) return this.xmlhttpSend(uri, this.parseForm(formRef));
  else if (this.iframe) return this.iframeSend(uri, formRef);
  else return false;
 }
 else
 {
  // For GET requests, append ?querystring or &querystring to the GET uri and
  // forward it to the load() function (along with the callback).
  return this.load(uri + (uri.indexOf('?') == -1 ? '?' : '&') + this.parseForm(formRef),
   callback);
 }
};












// SYNTAX INSTRUCTIONS for HTMLHttp.Threader:
//
// var objectName = new HTMLHttp.Threader('objectName');
//
// This is our "Threading" layer that automatically creates, allocates and processes
// HTMLHttp.Request objects, so you can easily issue concurrent requests to a server
// and load areas of content into your page without writing complex management code.
// Pass its own name in quotes.
//
// Available public methods and properties are:
//
// objectName.loadInto('file.html', 'id-of-target', callback_function);
//
// This loads a specified file into an element with an ID="id-of-target" attribute.
//
// objectName.submitInto(form_reference, 'id-of-target', callback_function);
//
// This will capture a form's submission and load within the specified target element.
// If you are using the IFRAME transport plugin, the form should already be in the
// process of submittal, otherwise it can be called at any time.
//
// Callback functions for both the above receive the following parameters:
// 1) The loaded document DOM.
// 2) The loaded document text.
// 3) The destination ID.
//
// Note that for both loadInto() and submitInto(), subsequent requests targeted at the
// same element will cancel earlier requests if they are still loading.
// Also, all loaded files must reside on the same domain as the requesting document.

HTMLHttp.Threader = function(myName)
{
 this.myName = myName;
 this.threads = [];
 this.loadingIDs = {};
};


HTMLHttp.Threader.prototype.getThread = function(destId, callback) { with (this)
{
 // Locates a thread that's EITHER: loading into the specified destination, OR: idle.
 // If none are match that condition, create a new one.

 var thr = -1;

 for (var id in loadingIDs)
 {
  // Same destination?
  if (id == destId)
  {
   thr = loadingIDs[id];
   break;
  }
 }
 if (thr == -1) for (var t = 0; t < threads.length; t++)
 {
  // Idle?
  if (!threads[t].loadingURI)
  {
   thr = t;
   break;
  }
 }
 if (thr == -1)
 {
  // Create a new HTMLHttp.Request object.
  thr = threads.length;
  threads[thr] = new HTMLHttp.Request(myName + '.threads[' + thr + ']');
  // Record this thread as loading for this destination, so it can be aborted/reused.
  loadingIDs[destId] = thr;
 }

 return threads[thr];
}};


HTMLHttp.Threader.prototype.loadInto = function(uri, destId, callback)
{
 // Pass the file onto the load method of a selected/new thread.
 var threader = this;
 var cbFunc = function(docDOM, docText)
 {
  delete threader.loadingIDs[destId];
  callback(docDOM, docText, destId);
 };
 return this.getThread(destId).load(uri, cbFunc);
};


HTMLHttp.Threader.prototype.submitInto = function(formRef, destId, callback)
{
 // Pass the file onto the submit method of the selected thread.
 var threader = this;
 var cbFunc = function(docDOM, docText)
 {
  delete threader.loadingIDs[destId];
  callback(docDOM, docText, destId);
 };
 return this.getThread(destId).submit(formRef, cbFunc);
};





// SYNTAX INSTRUCTIONS for HTMLHttp.Capture:
//
// var objectName = new HTMLHttp.Capture('objectName');
//
// Available methods:
//
// objectName.apply(DOMNode);
//
// This will activate all click capturing within the supplied document/node.
// The below functions are then automatically called for all elements with the
// appropriate CLASS attributes, no further scripting required.
//
// objectName.loadInto(uri, destId, event, callback_function)
//
// Takes a URI and a destination ID (compulsory) and optionally an event object
// (used with active form submittal) or callback function reference (see below).
// Will then GET the specified document and insert into the given target.
//
// objectName.toggleInto(...)
//
// The same as loadInto but will collapse/expand target on subsequent clicks.
//
// objectName.submitInto(formRef, destId, event, callback_function)
//
// Called during a form submission with a reference to the form and other
// parameters as per loadInto().
//
// If you specify a custom callback function, it will be called with parameters:
// 1) Reference to loaded DOM document.
// 2) Loaded text/html document content.
// 3) The destination ID into which content should be inserted.
//
// The copyContent function is the "default" callback and takes those parameters.
// If you specify a custom callback, you must call copyContent or an equivalent
// function yourself.

HTMLHttp.Capture = function(myName, waitHTML)
{
 this.myName = myName;
 this.threader = new HTMLHttp.Threader(myName + '.threader');
 this.waitHTML = waitHTML;
};


HTMLHttp.Capture.prototype.loadInto = function(uri, destId, evt, callback)
{
 // Called to when a link with class="loadinto-IdOfTarget" is clicked.
 // Parameters: uri = address to load, destId = ID of target element,
 // evt = event object, callback = [optional] function reference.
 if (this.waitHTML) document.getElementById(destId).innerHTML = this.waitHTML;
 var ok = this.threader.loadInto(uri, destId, (callback || this.copyContent));
 if (ok && evt) cancelEvent(evt);
};


HTMLHttp.Capture.prototype.toggleInto = function(uri, destId, evt, callback)
{
 // As above, but loads only once and toggles the display of the target.
 var dest = document.getElementById(destId);
 if (!dest.contentLoaded)
  if (this.loadInto(uri, destId, evt, callback))
   dest.contentLoaded = true;
 if (evt) cancelEvent(evt);

 var src = evt.srcElement || evt.target;
 if (src.nodeType && src.nodeType != 1) src = src.parentNode;
 if (!dest.toggleState)
 {
  src.innerHTML = 'Close: ' + src.innerHTML;
  dest.style.display = 'block';
  // Add some animation in here if you want!
  dest.toggleState = 1;
 }
 else
 {
  src.innerHTML = src.innerHTML.replace(/^Close: /, '');
  dest.style.display = 'none';
  dest.toggleState = 0;
 }
};


HTMLHttp.Capture.prototype.submitInto = function(formRef, destId, evt, callback)
{
 // Called to when a link with class="submitinto-IdOfTarget" is clicked.
 // Parameters: src = reference to link, destId = ID of target element, evt = event object.
 if (this.waitHTML) document.getElementById(destId).innerHTML = this.waitHTML;
 if (this.threader.submitInto(formRef, destId, (callback || this.copyContent)))
  cancelEvent(evt);
};


HTMLHttp.Capture.prototype.apply = function(node)
{
 var obj = this;
 addEvent(node, 'click', function(evt)
 {
  // Here we capture all clicks on the document, scanning for links with a CLASS
  // attribute of "(load|toggle|submit)into-IdOfTarget" and processing them.
  evt = evt || window.event;
  // Only process left clicks.
  if (evt.which > 1 || evt.button > 1) return;
  var src = evt.target || evt.srcElement;
  if (src.nodeType && src.nodeType != 1) src = src.parentNode;
  var submitBtn = false;
  // Loop up the DOM tree scanning all elements to find a matching one.
  while (src)
  {
   var srcName = (src.nodeName||src.tagName||'').toLowerCase();
   if (srcName == 'input' && src.type.toLowerCase() == 'submit') submitBtn = true;
   if (srcName == 'form' && submitBtn &&
       src.className && src.className.match(/^submitinto-(.+)$/))
   {
    return obj.submitInto(src, RegExp.$1, evt, null);
   }
   if (srcName == 'a' && src.className && src.className.match(/^(load|toggle)into-(.+)$/))
   {
    var uri = src.href || src.getAttribute('href');
    // Call our load handlers if we have a match; they'll cancel the normal action.
    if (RegExp.$1 == 'load') return obj.loadInto(uri, RegExp.$2, evt, null);
    if (RegExp.$1 == 'toggle') return obj.toggleInto(uri, RegExp.$2, evt, null);
   }
   src = src.parentNode;
  }
 });
};


HTMLHttp.Capture.prototype.copyContent = function(docDOM, docText, destId)
{
 // This copies the <body> content of the loaded DOM document into an element in the
 // current page with a specified ID. It's suggested that you call it manually
 // from within your ONLOAD function if you're doing it yourself.

 // Retrieve references to the loaded BODY. You might want to modify this so that you
 // load content from <div id="content"> within the loaded document perhaps?
 // Note: Often fails in MSIE using XMLHTTP transport (fallbacks below).
 var src = docDOM ?
  (typeof docDOM.getElementsByTagName == 'function' ?
   docDOM.getElementsByTagName('body').item(0) :
    (docDOM.body ? docDOM.body : null) ) :
     null;
 var dest = document.getElementById ? document.getElementById(destId) :
  (document.all ? document.all[destId] : null);
 if (!dest || (!src && !docText)) return;

 // innerHTML is still a little more reliable than importNode across browsers.
 if (src && src.innerHTML) dest.innerHTML = src.innerHTML;
 else if (src && document.importNode)
 {
  while (dest.firstChild) dest.removeChild(dest.firstChild);
  for (var i = 0; i < src.childNodes.length; i++)
   dest.appendChild(document.importNode(src.childNodes.item(i), true));
 }
 else if (docText)
 {
  if (docText.match(/(<body>)(.*)(<\/body>)/i)) docText = RegExp.$2;
  // You might want to do some post-processing here if you are rendering
  // plain text in an XHTML document, for instance to keep line breaks:
  //docText = '<pre>' + docText + '</pre>';
  dest.innerHTML = docText;
 }
};

// Welcome to the HTMLHttpRequest demonstration!
//
// This script allows you to make background asynchronous GET and POST requests to a
// server in an accessible manner that is backwards-compatible with older browsers,
// mobile devices, screenreaders and search engines, just by putting CLASS names
// onto your existing links and forms. Some people call this "Hijax".
//
// The overall architecture is assembled in 3 layers:
//
// 1) A "Request" object that makes a request to the server and receives the result.
// 2) A "Threader" object that creates and allocates Request objects to let you
//    load multiple pieces of content at once into different areas of your page.
// 3) An "Capture" object that captures clicks/submissions on the document.
//
// These objects are included and documented in the external .JS files above.
// Both contain documentation if you are interested in customising the implementation.

// USAGE:
// First, we create an example object for our document click handler.
// It must be passed its own name as a parameter.
var docClickLoader = new HTMLHttp.Capture('docClickLoader');
// Optionally set waitHTML to a string to use as a "waiting..." message.
docClickLoader.waitHTML = '<img style="width: 25px; height: 25px" src="working.gif" />';
// You must apply it to the document (or an element, to apply to part of a document).
docClickLoader.apply(document);
// Now see below in the document for the CLASS names to activate the script.

// At any stage you can call docClickLoader.loadInto('file.html', 'target-id');
// to trigger a content load into an element from your script.
// The example below does this when suitable links in the document are clicked.
// See the source for more readme/options!


window.onload = function () {
            var R = Raphael("paper", 400, 400);
            var attr = {
                fill: "#c0000f",
                stroke: "#fff",
                "stroke-width": 0.8,
                "stroke-linejoin": "miter"
            };
            var canada = {};
canada.alberta = R.path("M 76,261 C 62.5,257.4 63.9,257.9 63.1,256.1 C 61.8,253 63.7,250 62.8,246.6 C 60.1,241.7 58.5,236.5 55.6,231.8 C 54.5,229.2 53.9,226.6 52.6,224.1 C 51.7,222.9 50.6,222.5 50.8,221 L 65.1,179.4 C 73.8,182.4 82.6,185 91.5,187.6 C 94.5,188.5 97.1,189.2 97.1,189.2 C 97.3,189.4 96.4,193.1 96.1,193.3 C 94.3,193.9 93,195.4 91.9,196.9 C 91.9,197.1 92.3,197.4 92.8,197.6 C 94.2,198.3 94.9,197.2 95.6,196.1 C 95.7,196.2 95.3,198.1 94.7,200.4 C 92.5,209.8 90.2,219.2 88,228.6 C 85,239.6 83.1,251.3 79.8,262 C 79.7,261.9 78,261.5 76,261 z").attr(attr);
canada.bc = R.path("M 62.3,257.3 C 50.6,253.9 39.3,249.3 27.8,244.9 C 26.2,242.1 23.9,239.5 22.3,236.4 C 21.3,231.7 17.6,228.5 15.1,224.6 C 14.2,221.1 16.2,217.9 16,214.5 C 14.4,210.2 12.6,202.1 14.6,197.6 C 18.9,195.5 23.3,190.6 21.4,185.5 C 17.6,177.9 19.4,168.2 17.5,159.5 C 16.8,152.7 11.6,155.9 7.5,157.7 C 9,154.8 6,151.4 7.4,148.8 C 16.3,154.3 25,160.1 34.2,165.2 C 39.3,168 44.4,170.6 49.6,173.1 C 54.4,175.3 59.3,177 64.1,179 C 59.2,193 54.1,206.7 49.9,220.8 C 49.4,221.6 49.7,222.7 50.6,223.3 C 53.3,225.3 53,228.6 54.4,231.3 C 56,234.1 57.5,237 58.8,240 C 58.9,240.5 59.8,242.5 60.7,244.5 C 64.2,248.2 60.8,252.6 62.4,256.6 C 62.8,257.2 62.8,257.4 62.3,257.3 z M 22.1,247.7 C 19.4,246.5 19.1,243.1 17.3,241.4 C 15.6,239.7 15,237 13.9,234.8 C 12.2,232.2 11.4,229.2 10.4,226.3 C 10,225 11.1,224.6 12.1,224.2 C 15.3,226.5 17.8,229.9 20.4,233.1 C 21.5,235.5 21.3,238.1 22.9,240.4 C 24.8,242.5 24.9,245.4 25.5,248.1 C 25.1,248.5 23,248.3 22.1,247.7 z M 4.2,209.4 C 2.8,205.4 2.3,201.1 3.2,196.9 C 3.4,196.2 3.5,195.4 4.1,195 C 4.7,194.8 5.3,195.1 5.8,195.3 C 6.9,196.1 7.8,196.9 8.6,197.9 C 8.8,198.5 8,199 7.7,199.5 C 6.7,200.7 5.5,201.7 4.6,203 C 4,203.8 4,204.8 4.3,205.8 C 4.6,207.2 5.2,208.6 5.3,210.1 C 5.4,210.8 4.7,210.5 4.6,210.1 C 4.4,209.8 4.3,209.6 4.2,209.4 z").attr(attr);
canada.manitoba = R.path("M 125.2,194.5 C 124.7,198.8 123.9,203.1 123.4,207.4 C 124.9,210.6 121.4,212.5 122,215.7 C 120.9,233.5 119.2,251.2 118.4,269 C 126.7,269.9 135,271 143.3,271.2 C 144,262.9 144.1,254.5 145.2,246.3 C 153.4,237.1 161.6,228 169.5,218.7 C 166.4,217.3 163,215.8 159.6,216.9 C 155.5,218.4 157.3,211.9 156,209.5 C 156.4,205.5 152.3,205.1 149.7,204.1 C 149.1,201.7 149.7,199.4 149.9,197 C 141.7,196.2 133.4,195.3 125.2,194.5 z M 134.6,239.5 C 137,243.1 137.1,247.6 138.5,251.6 C 139.1,254.4 140.4,257.4 139.7,260.3 C 137.6,262.4 135.5,260.9 136.9,258.3 C 137.7,256.9 138.9,253.3 136,254.8 C 137.3,252.4 135.7,250.3 133.1,250.5 C 131,248.5 131.5,243.1 127.9,243.5 C 126.6,245.5 126.3,249.1 127.8,251.2 C 131.3,253.1 130.5,257.6 132.1,260.7 C 132.7,263.5 129.1,262.7 129.7,260.3 C 129.2,257.4 129,254 126,252.5 C 122.7,250.9 126.9,247.5 124.6,245.3 C 122.2,244.3 123.2,242.4 124.3,241.2 C 122.4,237.9 127.5,238.9 128,241.4 C 129.3,243.5 129.5,237.6 131.9,238.1 C 133,237.9 134,238.6 134.6,239.5 z").attr(attr);
canada.newbrunswick = R.path("M 271.4,283.4 C 268.3,280.9 266.6,277.6 266.2,273.7 C 266.2,271.6 264.2,270.8 262.5,270.4 L 261.7,270.4 C 261.5,269.2 261.5,268.1 261.5,267 C 265.7,267.3 268.6,263.5 272.7,264.1 C 274.7,264.6 275.9,262.3 278.1,262.8 C 276.6,265.8 278,268.6 279.8,271 C 281,272.4 282.6,272.1 284.2,272.3 C 281.6,275.3 280,279.9 276.2,281.5 C 274.5,282.5 273.8,283.7 271.4,283.4 z").attr(attr);
canada.newfoundland = R.path("M 299.7,255.5 C 298.7,254.4 299.5,253 300,251.8 C 300.5,250.4 299.6,249 300,247.6 C 300.3,241.6 300.3,235.6 300.9,229.7 C 301.3,227.7 302.8,225.9 304.9,225.5 C 306.7,227.8 305.9,231 305.7,233.7 C 305.5,234.7 305.4,235.7 305.2,236.7 C 305.9,235.3 307.6,234.1 309.1,235.2 C 309.2,236.3 309.5,237.7 311,237.4 C 313.4,237.2 315.3,235.5 317.6,235.2 C 319.5,234.9 319.3,236.8 319.7,238.1 C 320.1,239.9 322.6,239.3 323.5,240.1 C 323.2,241.6 321.4,242.4 322.3,244 C 322.3,246.1 323.8,244.2 324.2,243.3 C 325.5,242.9 325.4,246 326.9,244.6 C 328.5,243.4 328.6,246.1 328.4,247.1 C 328.4,248.6 328.4,250.4 326.9,251.3 C 325.7,251.6 324.6,250.3 323.4,251 C 322.5,249.7 322.9,247.8 322.1,246.5 C 321.1,247.2 320.8,248.8 319.7,249.6 C 318.8,251.1 319.9,253.3 318,254.2 C 317.2,255 314.3,255 315.6,253.4 C 316.9,252.3 316.3,250.1 314.4,251 C 312.6,251.3 311.2,252.4 309.5,252.8 C 306.5,253.7 303.8,255.7 300.6,255.7 C 300.3,255.6 300,255.6 299.7,255.5 z M 265.7,236.5 C 262.9,236.9 260.8,234.8 260.4,232.7 C 258.6,233 256.1,232.7 257.2,230.3 C 256.1,227.6 251.7,226.3 253.3,222.6 C 254,219.8 256.5,218 259.2,219.2 C 261,218.2 266.6,217.4 263.9,220.9 C 262,221.5 259.7,225.7 263.4,224.6 C 265.2,222.5 269.5,224.1 269.6,220.7 C 269.5,218.2 264.9,221.7 266,218.4 C 268.3,215.7 266.4,212.8 264.8,210.4 C 263,207.3 261.3,203.9 261.7,200.2 C 262,196.9 256.8,196.6 258.2,193.3 C 259.1,191.4 258.3,189.1 255.9,189.8 C 254.4,188 254.2,185.4 252.8,183.5 C 252,182.5 252,179.9 253.6,181.9 C 256,184.5 258.7,186.8 261.2,189.3 C 262.5,192.4 266.6,192.7 267.5,196.1 C 268,198.6 271.4,198 270.4,200.9 C 270,204.4 274,205.1 276.5,206 C 278.7,207.7 280.8,208.4 283.6,208.3 C 286,209.5 289.1,206.7 291.1,209.2 C 290.7,211.6 287.1,213.2 285.7,215.6 C 284.8,216.5 281.8,219.3 283.9,219.8 C 287,217.8 287.4,212.9 291.2,211.7 C 293.7,212.5 296.2,213 298.6,214 C 302.2,214.8 300,219 302.9,220.7 C 305.1,222.6 302.6,224.7 301.5,226.5 C 300.4,229.3 299.5,224.4 297.2,225.2 C 294.8,225.6 292.7,226.8 290.4,227.5 C 285,229.5 279.7,231.9 274.1,233.4 C 272.5,233 269.1,231.3 270.1,234.7 C 270.3,237.2 267.4,237.6 265.7,236.5 z").attr(attr);
canada.novascotia = R.path("M 280,291.6 C 278,291.1 277.1,289 277.1,287.1 C 276.9,285.9 277.8,285 278.4,284 C 279.4,282.4 280.7,280.9 282.3,279.7 C 283.2,279 284.2,278.3 285,277.5 C 284.1,277.6 283.4,278.2 282.6,278.6 C 281.7,279.3 281,278.2 281.6,277.4 C 282.3,275.9 283.4,274.6 284.6,273.5 C 285.4,272.9 286.3,273.3 287.2,273.2 C 288.9,273 290.6,272.9 292.1,272 C 294,271.3 296.1,272.3 297.4,273.6 C 297.3,275.3 295.7,276.3 294.6,277.4 C 293.6,278.4 292.5,279.3 291.4,280 C 290.4,280.7 289.4,281.4 288.9,282.5 C 288.2,283.5 286.2,283 286.2,284.6 C 285.6,286.5 284.9,288.4 283.5,289.8 C 282.7,290.4 282.2,291.7 281,291.7 C 280.7,291.7 280.4,291.7 280,291.6 z M 297.1,272.3 C 296,271.4 295.1,270.2 294.5,269 C 295.7,266.7 296,264 297.6,262 C 298.1,262 298.6,263.1 298.7,264 C 298.5,266.3 300.8,266.4 301.7,268.2 C 301.3,270 299.9,270.9 298.4,271.9 C 297.8,272.7 297.7,272.8 297.1,272.3 z").attr(attr);
canada.nwt = R.path("M 53.9,95.1 C 51.5,95.3 48.3,95.1 48.5,98.1 C 44.9,97.6 43.8,105.1 41.9,108.2 C 39.7,111.7 48.1,112.3 45,116.7 C 41.8,120.4 48.6,124.4 43.4,127.2 C 40.8,131.8 45.9,136.7 44.7,141.4 C 44,145.1 42.4,149.4 43.7,153 C 44.9,155.4 45.6,158.1 46.5,160.6 C 43.3,165.1 50.5,166 52.4,167.3 C 53.1,169.6 50.9,173.9 54.4,174.3 C 69.1,180.3 84.4,184.7 99.7,188.9 C 107.5,190.7 115.3,192.1 123.1,193.4 C 126.3,191.8 124.3,184.9 125.6,181.4 C 126.2,174.9 126.7,168.3 127.3,161.8 C 121.4,158.6 115.5,155.4 109.6,152.3 C 108.4,150.6 107.5,148.5 106.2,147.1 C 104.4,146.7 102.5,146.4 100.7,146 C 95.2,138.4 89.5,130.9 84.2,123.2 C 84.4,118.9 89.3,114.4 86.4,110.3 C 84.9,106.3 80.5,108.7 78.4,108.5 C 80.8,106.3 78.8,101.4 76.3,105.5 C 71.5,109.8 76,98.2 71.5,98.8 C 69,100.6 68,99 67.3,97 C 63.5,94.5 56.7,100 54.6,96 L 54.3,95.5 L 53.9,95.1 L 53.9,95.1 z M 74.9,130.7 C 77.2,130.7 85,130 80.3,133.9 C 79.5,136.3 89.9,136 85,139.7 C 83.1,142.5 80.3,137.6 78.6,140.1 C 79.2,143.4 70.9,145.2 75.1,141.2 C 74.5,139.9 67.4,143.7 69.3,139.1 C 71.5,137.5 76.2,133.7 70.8,133 C 63.4,130.2 72.6,130.7 74.9,130.7 z M 86.3,166.4 C 88.6,170.3 93.4,173.4 97.4,169.7 C 101,166.8 102.3,171.1 98.2,172.4 C 94.6,175.1 90.3,176.5 86.2,178.2 C 83.1,179.5 75.5,176.1 77.4,173.5 C 81.2,174 88.4,172 84.5,167 C 83.3,165.3 83.1,162.2 85.2,165.3 L 85.8,165.9 L 86.3,166.4 L 86.3,166.4 z M 99.1,111.2 C 98.4,111.2 97,110.5 98.5,110.5 C 100.6,110.4 102.7,110.4 104.7,110.8 C 106.1,111.3 107.3,112.3 108.8,112.2 C 109.5,111.3 107.8,110.4 107.1,109.8 C 106,109.1 104.8,108.7 103.5,108.6 C 101.4,108.1 99.4,107.6 97.4,106.7 C 96.3,106 96.3,104.4 96,103.3 C 97,102.4 98.4,102.3 99.6,101.9 C 100.3,101.7 101,101.5 101.7,101.3 C 100.8,101.1 99.8,101 98.9,100.7 C 97.7,99.7 97.3,98.1 96.7,96.7 C 96.6,94.8 98.6,93.8 99,92.1 C 100.7,89.4 104,88.4 106.9,87.9 C 108.2,87.7 109.4,87.3 110.7,87.3 C 112.4,87.6 111.7,89.6 111.3,90.6 C 110.7,91.4 110.4,93.4 111.9,92.1 C 112.2,91.8 112.6,91.5 113,91.2 C 114.5,92.1 116,92.9 117.3,94.1 C 117,94.9 116.7,95.7 116.3,96.5 C 117.1,96.3 118.3,96.4 118.5,95.4 C 118.5,94.4 117.5,93.2 119,92.9 C 120.3,92.2 119.1,94.4 119.1,95 C 117.5,101.7 115.9,108.4 114.1,115.1 C 113.1,115.6 111.3,114.6 110,114.4 C 106.4,113.5 102.8,112.3 99.1,111.2 z M 85.1,95.5 C 85,93.4 83.9,91.7 82.7,90 C 81.8,88.9 82.4,87.3 83.5,86.6 C 85.2,85 86.1,82.7 87.7,80.9 C 88.7,79.5 89.8,78.3 90.8,76.9 C 91.6,75.6 91.7,74 91.6,72.5 C 92.2,71.2 93.9,71.3 95,71.8 C 96.4,72.3 97.9,72.6 99.2,73.3 C 100.3,74.2 100.7,75.5 101.8,76.4 C 102.5,77.6 103.9,77.8 105.2,77.6 C 106.9,77.6 107.3,79.5 107.8,80.7 C 108.2,82.3 109,83.9 108.9,85.6 C 108.5,86.9 106.9,87.1 105.8,87.4 C 101.3,88.7 97,91.4 94.3,95.4 C 93.8,96.9 92.3,97.7 90.8,97.9 C 89.4,98.1 87.8,98.6 86.4,98.1 C 85.4,97.7 85.2,96.5 85.1,95.5 z M 114.9,79.1 C 114.4,78.5 113.6,77.7 114,76.9 C 114.7,76.1 115.9,75.9 116.9,75.6 C 117.5,75.6 119.2,74.9 117.8,74.4 C 116.9,74.1 116,73.9 115,73.6 C 114,74.2 112.7,74.2 111.7,73.4 C 110.5,72.5 109.8,71.2 109,70 C 108.7,68.9 110.1,68.7 110.5,67.9 C 111.3,66 112.3,64 114,62.8 C 114.8,62.1 116,61.2 117.1,61.8 C 118.4,62.6 118.9,64.3 120.2,65.2 C 121.6,66.1 122,67.9 122,69.5 C 122,70.3 122.2,71.4 123.3,71.5 C 124.1,71.3 124.9,71.8 124.5,72.7 C 124.3,73.8 124.1,74.9 123.8,76.1 C 123,78.8 120.1,80.5 117.3,80.3 C 116.9,80.3 116.5,80.3 116.1,80.3 C 115.7,79.9 115.3,79.5 114.9,79.1 z M 106.4,66.7 C 106,65.4 106.5,64.8 108.5,64 C 110.2,63.3 110.7,63.2 111.1,63.7 C 111.6,64.3 111.3,64.9 110.5,65.6 C 109.5,66.3 108.6,67.2 107.6,67.9 C 106.8,67.8 106.7,67.4 106.4,66.7 z M 104.7,63.5 C 104.2,62.3 104.4,61.9 102.9,61.8 C 99.5,61.9 100.5,58.7 102.8,57.9 C 105,57.2 106.9,56.3 108.6,54.8 C 111,52.6 111.4,52.4 113.3,52.4 C 114.9,52.4 116.4,52.1 117.6,53.3 C 118.3,55.6 116.1,56.3 115.8,58.2 C 115.8,59.9 114.2,60.3 113.2,61.3 C 111.3,63 111,60.7 111.7,59.1 C 113.2,57 108.9,61.4 108.7,61.5 C 106.3,64 105.6,64.3 104.7,63.5 z M 122.9,54.7 C 122.6,53.8 122.4,53.1 121.8,52.4 C 120.4,51.5 119.9,49.1 121,49.1 C 121.5,49.1 122.3,49.9 122.3,50.4 C 122.3,50.6 122.6,50.7 123.2,50.5 C 124.2,50.3 128.6,50.1 129.1,50.2 C 129.3,50.3 129.3,50.6 129.1,51.5 C 128.7,53.2 128.6,54.9 127.7,56.4 C 125.7,57.4 123.8,56.6 122.9,54.7 z M 128.9,49.2 C 128.4,48.7 127.6,48.3 127,47.8 C 126.7,47.5 126.4,47.4 125.9,47.5 C 123.7,47.4 126.3,45.7 127.2,45.5 C 127.3,45.6 127.6,45.5 127.8,45.3 C 128.1,45.1 130.1,45.1 130.3,45.4 C 130.5,45.6 129.5,49.4 129.3,49.4 C 129.1,49.4 128.9,49.3 128.9,49.2 z").attr(attr);
canada.nunavut = R.path("M 125.2,193.3 C 126.2,182.7 127.4,172.1 128.2,161.5 C 122.7,157.8 116.3,155.3 110.6,151.8 C 108.4,150.3 108.3,146.2 105.3,146.1 C 103.1,145.5 100.4,145.8 99.7,143.1 C 95,136.2 89.2,130.1 85,122.9 C 86.6,120.4 86.7,113.3 89.5,114 C 92.5,117.3 95.7,120 99.6,121.3 C 102.8,123.7 101.9,127.3 98,127.7 C 99.1,131.8 105.8,132.3 109.5,131.4 C 113,130.4 114.6,139 115.8,138.1 C 114.8,134.3 116.9,132.8 120.1,131.4 C 118.9,131.7 113.2,132 116.1,128.6 C 119.4,126.1 124.6,126 124.8,131 C 126.9,133.5 130.1,134.7 132,137.2 C 135.3,136.2 141.7,140.8 142,135.6 C 141.7,130.9 152.2,134.9 149,138.6 C 147,141.2 151.2,144.2 149.9,139.8 C 149,135.6 157.7,135.7 154.6,130.4 C 155.7,125.3 147.4,124.8 149.1,119.3 C 149,116.7 146.8,113.5 150.2,111.6 C 151,108.7 154,104.6 156.6,109 C 159.5,112.2 159.2,117.2 161.1,121 C 158,123.1 160.6,126.8 164.1,125.7 C 168.6,127 160,127.5 164,130.3 C 165,132.5 165.4,134.6 165.9,130.8 C 167.9,124.2 174.5,133.9 171,137.1 C 171.1,142 176.2,143.9 175.9,137.8 C 177.2,133.4 180.2,129.6 177.5,125.1 C 179.1,119.8 185.8,124.9 188.4,127 C 190.3,128.9 191.1,133.2 187.5,134.3 C 189.6,138.2 192.9,142.4 189,146.5 C 188,149.8 184.3,148.4 183.6,150.2 C 181.8,151.3 176,147 177,150.5 C 179.5,153.9 172.7,157.2 175.1,160.9 C 173.5,165 170.8,169 166.3,168.9 C 166,172.3 160,169.7 163.6,173.3 C 164.3,177.9 158,175.5 158.4,179 C 155.2,182.6 152.5,186.6 151,191.2 C 149.6,193.7 151.1,197.8 146.8,196 C 139.6,195.4 132.4,194.4 125.2,193.3 z M 125.6,126.7 C 124.2,125.2 121.9,124.4 119.9,125.2 C 116.6,126.2 113.1,127.2 109.6,126.9 C 107.7,126.5 105,127.1 103.5,125.7 C 103.3,123.9 103.4,122.1 102.9,120.3 C 101.4,118.7 98.4,118.9 97.2,116.7 C 96.2,115 96.2,113.1 95.7,111.3 C 97.4,111.4 99.2,112.2 101,112.6 C 105.5,113.9 110,115.4 114.6,116.6 C 116.6,108.9 118.5,101.2 120.5,93.5 C 122.1,95.7 122.5,98.4 122.6,101 C 122.6,101.9 123.4,104.2 123.6,102 C 123.9,99 123.8,96 123.6,93 C 124.5,91.2 126.4,91.5 127.8,92 C 126.9,89.8 129.5,87.8 131.5,89.1 C 132.9,89.9 134.1,91.9 132.8,93.4 C 132.2,94.6 131.1,95.5 130.4,96.7 C 130.5,100.4 130.3,104.1 131.5,107.7 C 131,109.4 130,111.3 131.2,113 C 132.3,115.1 134.4,116.5 136.1,118.1 C 137.1,119.3 139.1,122.3 136.7,123.1 C 135.3,122.8 132.3,122.2 134.1,124.6 C 135.1,126.4 134.5,129.4 132,129.1 C 129.7,129.1 127.4,128.1 125.6,126.7 z M 201.1,242.1 C 202.8,241.7 204.6,243.8 203,244.9 C 200.9,244.8 197.2,242.6 201.1,242.1 z M 199,177.3 C 202.1,175.8 201.6,180.4 200.4,182.1 C 197.5,183.5 197.9,179 199,177.3 z M 187.3,174.9 C 188.7,174 190.9,173.6 192.1,175 C 192.4,177.5 189.6,179.3 187.4,179.7 C 184.2,180.1 186,176.1 187.3,174.9 z M 180.1,173.8 C 179.5,173.1 179.6,171.9 179.4,171 C 177.4,170.2 173.5,171.2 175.9,168.1 C 176.8,167.1 177,166.6 176.9,165.2 C 176.8,160.2 176.9,158.6 177.9,154.8 C 178.2,153.1 179.5,152.9 180.6,153.8 C 182.4,157.3 186.4,158.6 189.5,160.8 C 190.8,161.5 191.1,162.5 191.7,163.7 C 192.4,165 192.1,165.5 193.7,165.4 C 195.4,165.2 196.5,166.1 196.8,167.6 C 196.7,168.9 196.5,169.2 195.5,169.8 C 193.4,170.3 190.3,170 189.4,168 C 186.7,164.5 185.5,169.7 183.8,171.6 C 182.7,173.2 181.9,173.9 180.1,173.8 z M 141.1,129.5 C 141.1,128.9 145.1,123.5 145.6,123.5 C 148.7,125.4 150.2,128.7 151,132.2 C 148.6,136.6 143.3,131.8 141.1,129.5 z M 241,172 C 237.9,171.5 234.2,172.6 231.9,170 C 228.8,169.1 223.6,169.4 223.1,165 C 222.1,162.9 218.3,161.7 216.3,159.8 C 213.4,159.5 210.4,160.7 208.3,162.5 C 205.9,162.7 202.8,162.8 201.9,160 C 201.5,156.3 204.1,152.5 208.2,153.6 C 211.4,154.1 216.5,150.5 212.2,147.9 C 211.7,146.3 213.2,144.8 213.7,143.3 C 214.3,141.4 216.2,139.7 215,137.7 C 213.1,133.7 209.3,129.4 206,127.4 C 204.6,128.8 201.3,129 203.3,126.5 C 204.1,124 198.9,126.8 200.6,123.3 C 199.9,121.7 195.9,117.7 196.2,121.4 C 191.9,121.3 187.7,121.9 183.5,122.2 C 179.7,122.2 175.8,122.6 173.2,119.8 C 169.3,121.3 163.9,114.6 169.4,113.6 C 164.8,113.5 165.4,108.4 165.9,105.1 C 166.5,100.1 167.5,94 172.2,91.2 C 175.5,89.6 179.7,92.6 176.1,95.7 C 174.9,98.3 173.5,103.4 176,104.8 C 175.8,100.7 176.5,96.7 179.7,93.7 C 182.2,90.3 187,92.2 188,95.9 C 188.2,98.5 190.9,103.8 193,100 C 194.7,96.6 199.8,97.5 201.9,100.1 C 204.2,102.1 206.1,108.6 209.3,104.3 C 213.4,104.8 214.2,111.7 218.8,109.7 C 221.7,110.1 219.2,115.2 222.4,112.3 C 224.9,113.9 227.6,118.2 228,120.4 C 226.6,121.9 223.6,120.2 225.3,123 C 224.7,127.4 231.5,128.3 235,128.3 C 237.1,128.7 238.4,131.6 241,131.5 C 241.5,134.9 244.5,131.1 246.2,132.5 C 248.8,134.8 246.1,139.6 246.2,142.7 C 242.1,143.6 248.7,148.6 243.6,148.2 C 239.3,147.7 237.8,143.1 234.1,141.5 C 231.8,140.1 230,142.4 232.1,144.1 C 229.8,146.9 235.1,147.8 236.3,150 C 239.4,150.3 241.1,152.7 242.9,154.9 C 244,156.1 245.1,157.3 246.1,158.5 C 245.9,161.6 247.3,167.7 242.5,164.9 C 239.3,164.6 235.9,160.9 233.2,161.6 C 235.3,165.3 240,165.9 243.1,168.4 C 244.8,168.8 243.8,170.7 244,171.9 C 243.3,172.3 241.8,172 241,172 z M 203.3,169.3 C 204.9,168.4 205.7,169.9 205.5,171.4 C 204.1,171.8 203.3,170.5 203.3,169.3 z M 206.4,167.4 C 207,165.9 208.2,167 208.7,167.9 C 207.6,168.7 206.9,168.3 206.4,167.4 z M 203.6,131.7 C 208.4,130.7 209,138.5 205.5,140.3 C 200.4,141.8 201.5,134.2 203.6,131.7 z M 208.6,133.6 C 210.1,133 212.4,133.6 210.9,135.2 C 209.5,135.8 209,134.8 208.6,133.6 z M 194.5,128.6 C 195.3,126.7 195.7,124.6 196.9,123 C 197.5,125.1 196.7,128 194.5,128.6 z M 141.5,109.1 C 141.2,104.4 134.2,102.6 137.5,97.8 C 139.9,98.1 142.5,99.8 141.7,96 C 138.4,90.7 141.3,90.2 145.4,91.1 C 147.9,89.2 150.5,90.6 149.3,93.4 C 149.4,94.2 149.7,94.8 148.6,96.1 C 146.8,97.7 148.8,98.5 149.3,100.4 C 151.2,103.8 150.7,107.2 147.1,109 C 145.3,111.7 143.3,111.7 141.5,109.1 z M 153,92.9 C 153.9,88.3 157.5,88.2 161.1,89.5 C 167.9,90.7 162.4,97 160.8,101 C 157.2,101.2 156.8,101.7 156.6,105.1 C 150.3,108.2 152.1,96.1 153,92.9 z M 187.1,91.4 C 187.3,90.8 192.4,90.9 193.5,91.5 C 195.4,92.7 200.4,97 195.5,97.1 C 194.3,97 193.7,97.1 192.9,97.6 C 189.3,99.4 188,94 187.1,91.4 z M 161,82.4 C 160.4,79.4 161.1,76.2 159.9,73.3 C 159.1,71.4 157,70.5 155,70.1 C 153.5,68.7 151.7,67 152,64.7 C 152.6,63 154.9,63.7 156.3,64 C 158,64.6 158.9,66.9 161,66.8 C 162.8,66.2 164,67.6 164.6,69.1 C 166.3,69.9 165.6,71.6 165.6,73 C 166.4,74.3 167.2,76 168.9,76.1 C 170.4,76.3 171.9,76.6 173.5,76.9 C 174.9,76.1 176.6,75.7 177.9,74.6 C 180.6,73.1 184.4,73.4 186.5,75.9 C 187.9,77.5 188.6,79.8 188.1,81.9 C 187.5,84.3 184.8,85.5 182.5,84.9 C 181.1,84.2 179.7,84.5 178.3,85 C 175.2,85.8 171.7,86.5 168.8,84.9 C 167.2,84.6 165.4,85.7 163.8,85.1 C 162.4,84.9 161.3,83.8 161,82.4 z M 151.9,81.7 C 151.1,79.8 152.7,77 154.5,76.1 C 157.8,75.5 158.6,77.5 158.8,80.4 C 159.5,86.4 154.7,84.1 151.9,81.7 z M 143.6,77.3 L 145.3,75.5 L 142.9,75.6 C 140.2,75.6 139.8,75.4 139.8,73.8 C 139.8,72.6 139.5,72.1 138.1,71.2 C 136.1,70.4 137.1,69.1 138.8,68.8 C 140.2,69 140.9,69.3 140.9,69.8 C 140.9,70 141.4,70.6 142,71.3 C 143,72.3 144.2,73.2 144.7,71.6 C 144.8,70.6 144.5,70.1 143.1,69.2 C 141.2,67.9 144.5,66.7 145.6,66.3 C 147,66.4 148.3,66.6 149.7,67 L 150.3,67.4 L 150.1,72.2 C 149.7,74.4 150.8,79.3 148.1,80.3 C 146.1,80.2 144.5,79.1 143.6,77.3 z M 127.6,78.2 C 126.5,77.4 125.4,77.9 124.4,78.4 C 123.9,75.7 126,73.6 126.1,71.1 C 126.1,69.4 127.3,63.4 127.8,62.7 C 128.6,61.5 130.6,62.5 129.9,63.7 C 129.7,64 129.7,64.4 129.9,64.7 C 130.3,66.2 129.6,67.6 129.5,69.1 C 130.1,70.9 132.1,69.7 133.5,70.1 C 135,72.4 134.4,74.9 133,77 C 131.8,78.8 129.4,79.4 127.6,78.2 z M 136,75.9 C 137.8,76.3 138.1,78.3 136,78.7 C 133.7,78.8 134.4,76.5 136,75.9 z M 183.8,69.5 C 182,67.6 178.8,69.7 177,67.6 C 175.7,71.3 171.1,69.1 168.3,69.6 C 164.3,67.9 167.1,62.8 170.2,61.8 C 169.2,60.3 167,57.7 169.7,56.2 C 171.8,55.2 173.8,59.1 174.9,58.8 C 173.3,57.6 173.3,55.9 174.3,54.2 C 171.8,54.9 168.7,53.3 170.5,50.5 C 171,48.2 173.7,45.5 176.1,46.8 C 177,48.2 179.7,48 177.7,46.3 C 175,44.7 174.2,41.3 172.1,39.2 C 170.8,37.4 170.2,33.1 173.3,33.2 C 175.3,33 177.5,37 178.1,36.3 C 176,34.4 176.9,31.5 179.8,31.2 C 181.4,30.1 185.4,27 182.1,25.6 C 180.8,28.7 177.4,30.9 174,30.9 C 171.1,32.3 172.4,25.7 170.7,29 C 167.6,31 166.6,26.5 164.9,25 C 165.4,23.6 168,21.4 164.9,20.9 C 161.6,18.4 167.3,16.2 169.2,15.2 C 171.2,14.3 171.9,9.4 174.7,12 C 177.8,10.6 177.3,5.9 180.8,4.8 C 183.3,3.1 186.3,3.6 189.1,2.8 C 192.5,2.9 196,1.7 199.3,3 C 202.1,4.3 205.2,6.9 203.8,10.5 C 203.8,14.2 198.6,15 198.5,18.5 C 199.5,17.2 203,14.5 202.5,18 C 201.6,21.3 200.1,24.4 198.9,27.6 C 197,30.2 198,33.8 196.2,36.2 C 193.5,36.8 193.4,39.5 190.6,40.2 C 187.7,42 191.1,45 192.7,46.4 C 193.2,48.2 191.2,49.5 192.9,51.2 C 191.8,52.5 191.4,54.7 189,55.2 C 188.5,57 189,59.6 187.2,61 C 187.5,63.2 191.4,64.6 189,67.1 C 188.1,68.7 185.5,72.1 183.8,69.5 z M 136.1,57.6 C 137.9,55.6 138.5,59.7 137.5,61.1 C 135.6,61.1 135.8,59 136.1,57.6 z M 154.4,57.3 C 156.6,55.3 160.9,57.5 158.3,60.2 C 156.3,61.7 152.2,59.8 154.4,57.3 z M 152.9,56.1 C 152,55.8 151.6,55 151.9,54.3 C 151.2,52.7 150.3,51.6 150.3,49.7 C 151.1,46.1 153.8,48.8 155.8,49.9 C 156.2,49.9 156.6,51.3 156.6,52.9 L 156.6,54.7 L 155.4,55.6 C 154.1,56.6 154,56.6 152.9,56.1 z M 147.4,55.7 C 145.8,53.9 144.5,52 142,51.9 C 139.9,52 138.9,50.5 139.3,48.6 C 139.7,48.1 140.3,48 140.8,47.6 C 141.3,47.2 141.3,47 141.1,46.2 C 140,44.3 137.4,41.8 141.1,41 C 142.2,41 143.6,42 143.6,42.8 C 143.6,43.3 144,43.6 144.6,43.7 C 146.3,44.4 147,46.2 148,47.6 C 148.8,48.5 148.9,49 148.6,50 C 147.8,51.7 149,52.7 149.7,54 C 149.4,55.6 148.7,56.3 147.4,55.7 z M 160.7,51.4 C 159.6,49.8 158.6,48.2 158.1,46.3 C 158.5,44.9 160.1,44.4 161.1,43.5 C 161.6,42.1 159.2,42.1 158.3,42.4 C 157,42.7 155.3,41.9 155.9,40.4 C 155.6,39.2 154.3,38.3 154.9,36.9 C 154.6,35.3 157.8,35.7 156.7,34.2 C 155.9,33.4 155.1,31.8 156.6,31.3 C 157.7,31.1 159,29.9 157.7,29 C 157.4,28.6 157,28.4 156.9,28 C 157.3,27 158,26.2 158.8,25.5 C 159.4,24.6 159.9,22.6 161.4,23.4 C 162.9,24.4 163.8,26.1 164.4,27.8 C 165.1,30 167.4,31.4 167.9,33.7 C 168.5,35.2 170.1,36.2 170.3,37.9 C 170.9,39.7 172.6,40.8 173.3,42.5 C 173.7,43.8 173,45.2 172.1,46.2 C 170.3,47.8 169.7,50.6 167.6,52 C 166.5,52.2 165.7,52.7 165.1,53.7 C 163.8,54.4 162.2,53.5 161.4,52.3 C 161.2,52 161,51.7 160.7,51.4 z M 130.5,48.9 C 130.6,48 130.9,47.1 131.2,46.4 C 131.6,46.4 131.2,48.7 130.8,49.1 C 130.4,49.5 130.4,49.5 130.5,48.9 z M 149.7,34.4 C 151.1,34.9 152.1,36.4 151.3,37.7 C 149,38.7 147.4,35.4 149.7,34.4 z").attr(attr);
canada.ontario = R.path("M 201.7,316.2 C 204.2,313.9 204.2,309.7 205.8,306.6 C 204.6,302.5 209.1,298.9 205.7,295.2 C 207.4,298.6 215.2,301.1 212.2,295.2 C 208.9,290.3 202.7,290.2 197.4,289.9 C 191.6,290.1 190.3,284.9 188.6,280.9 C 186.5,278.7 182.2,278.7 182.4,275 C 181.6,272.7 176.8,274.5 174.7,272.9 C 172.1,276.3 168.5,280.3 163.7,278.4 C 158.2,278.3 154,274.2 148.6,274.3 C 143.6,270.8 144.5,264.2 145,258.7 C 145.7,253.5 143.8,247 148.7,243.4 C 156.2,235.5 163.2,227.1 170.5,219 C 173.9,221.8 176.8,224.8 181.2,226 C 184.1,227.5 186.4,229.7 190,228.8 C 192.8,228.9 198.7,228.5 196.7,233 C 197.1,237.5 197.2,242.9 200.3,246.6 C 202.7,248.8 205.2,251.8 206.4,254.4 C 210.6,252.8 209.4,257.7 210.1,260.5 C 211,267.3 211.5,274.3 212.6,281.1 C 213.9,286.7 220.1,286.8 224.4,288.4 C 226.8,289.1 227.8,292.6 230.8,291 C 233,290.1 239,287.4 236.3,292 C 232.2,295.6 229.1,301.7 223,302 C 219.5,302 212.4,306.8 218.8,308.5 C 218.4,310.4 211.9,310.2 213.1,312.8 C 208.4,310.9 206.1,315.7 202.5,317.6 C 200.9,317.6 198,318.4 201.7,316.2 z").attr(attr);
canada.pei = R.path("M 289.4,272 C 286.6,271.8 283.9,271.2 281.1,270.6 C 280.1,270.6 280,270.2 280.6,268.9 C 281,268.1 281.4,267.6 281.6,267.6 C 282.6,268.2 283.5,269.1 284.5,269.4 C 286.6,269.2 288.7,268.2 290.9,268 C 290.7,268.9 290.4,269.8 290.2,270.7 C 290.2,271.7 289.8,272.3 289.4,272 z").attr(attr);
canada.quebec = R.path("M 238.2,290.7 C 236.5,284.7 228.9,294.1 225.6,287.9 C 221.3,285.9 214.4,286.4 213.4,280.4 C 211.9,271.3 211.3,262 210,252.8 C 214.9,247.5 209.1,241.3 208.2,235.6 C 203,230.4 212.1,228.1 213.9,223.3 C 217,218.9 215.4,212.9 213,208.6 C 210.1,205.8 203.7,203 207.8,198.3 C 210.7,193.5 206.2,189.1 206.3,184.2 C 206.9,181.5 203.6,179.4 204.6,177 C 207.8,171.9 215.2,178.9 218.6,173.5 C 223.1,174.7 226.4,177.9 229.2,180.9 C 232.6,181.2 236.9,181.1 235.6,185.6 C 236.4,188.4 237,193.9 240,194.6 C 243.7,195.9 247.6,199.1 249.2,193.3 C 252.3,190.2 248.1,185.5 251.5,182.7 C 253,186.2 254.3,190.9 257.4,191.3 C 256.3,195 257.7,197.1 260.5,199.1 C 260,205.4 264.5,210.2 266.1,215.8 C 265.3,219.2 260.9,216.4 258.8,218.5 C 254.6,215.3 251,222.7 252.7,226.1 C 255.2,228.4 256.2,230.9 257.2,233.6 C 261.4,232.3 260.5,238.6 265.2,237.3 C 269.1,240.8 270.7,234.4 271.7,233.7 C 276.2,235 280.6,231.7 284.9,230.5 C 289.2,228.8 293.7,227.1 298.1,225.9 C 302.6,229.8 292.8,232.1 293.2,237.2 C 291.7,242.5 285.6,243.6 281,245.1 C 275.4,246.7 269.3,247.5 264.6,251.1 C 264.3,257 258.6,259 256.7,264 C 254.9,268.3 253.7,272.9 250.2,276.1 C 248.1,278.2 242.8,283.6 243.2,283.7 C 248.2,278.7 254.7,274.3 256.3,267 C 260.1,261.3 265.8,257 272,254.3 C 279.9,252.4 277.5,264.3 271,263 C 267.9,265.2 262.1,264.8 260.7,267.9 C 262.5,272.5 254.9,270.7 255.5,275.9 C 255.1,281.5 254.3,289.7 247.1,290.2 C 244.2,290.4 240.9,292.5 238.2,290.7 z M 279.6,251.9 C 278.5,251.5 277.5,250.9 276.3,250.6 C 273,249.7 275.7,248.2 277.6,248 C 280.4,248.1 285.5,247.8 287,250.5 C 285.9,252.4 281.9,252 279.6,251.9 z").attr(attr);
canada.saskatchewan = R.path("M 116.7,268.7 C 104.7,267.7 92.8,265.1 81.1,262.2 C 80.5,261.3 81.5,259.9 81.6,258.8 C 86.6,237.7 91.7,216.6 96.7,195.6 C 99.7,196 102.7,195.9 105.7,195.9 C 107.4,196.4 111,197 107.6,195.5 C 104.5,194.1 101,192 97.5,192.3 C 96.9,187.4 102.3,190.9 104.9,190.8 C 111.3,192.1 117.7,193.3 124.1,194.5 C 124.2,197.5 123.4,200.6 123.1,203.6 C 123.2,206.6 121.9,208.9 120,211.1 C 119.6,213 118.3,216.5 119,217.6 C 122.1,215 120.1,221 120.6,222.9 C 120,238 118.3,253 117.4,268.1 C 117.5,268.4 117.1,269.3 116.7,268.7 z").attr(attr);
canada.yukon = R.path("M 48.5,171.7 C 34.4,165 21.1,156.7 8.1,148 C 5.2,146.1 13,142.1 6.5,142.5 C 1.5,141.1 5.7,137.1 7.4,134.5 C 18.3,118.3 29.3,102.1 40.2,86 C 44.9,87.4 43.5,93.9 46.7,97 C 43.7,100.8 42.2,105.4 40.3,109.7 C 43,112.2 46.6,114.9 43.2,118.8 C 42.6,122 46.8,125.1 42.3,127.2 C 39.6,132.3 46,137.6 43.4,143 C 41,149.2 43.2,154.3 45.5,160.1 C 42.5,165.3 49.4,166.5 51.7,168.4 C 51.1,171.4 53.2,174.8 48.5,171.7 z").attr(attr);

var labels = {};
						labels.alberta = createLabel(R, "Alberta", 72, 275, 55, 1);
						labels.bc = createLabel(R, "British\nColumbia", 36, 277, 66, 2);
						labels.manitoba = createLabel(R, "Manitoba", 130, 287, 66, 1);
						labels.newbrunswick = createLabel(R, "New\nBrunswick", 296, 309, 68, 2);
						labels.newfoundland = createLabel(R, "Newfoundland\nAnd\nLabrador", 290, 158, 82, 3);
						labels.novascotia = createLabel(R, "Nova\nScotia", 270, 309, 42, 2);
						labels.nwt = createLabel(R, "Northwest\nTerritories", 66, 39, 70, 2);
						labels.nunavut = createLabel(R, "Nunavut", 246, 100, 64, 1);
						labels.ontario = createLabel(R, "Ontario", 176, 300, 54, 1);
						labels.pei = createLabel(R, "Prince\nEdward\nIsland", 300, 317, 54, 3);
						labels.quebec = createLabel(R, "Quebec", 181, 208, 50, 1);
						labels.saskatchewan = createLabel(R, "Saskatchewan", 98, 284, 96, 1);
						labels.yukon = createLabel(R, "Yukon\nTerritories", 33, 68, 68, 2);

          var current = null;
            for (var prov in canada) {
                canada[prov].color = Raphael.getColor();
                (function (st, prov, lb) {
                	
                    st[0].style.cursor = "pointer";
                    st[0].onmouseover = function () {
                    	st.animate({fill: "#ffff38", stroke: "#c0000f"}, 100);
                    	lb.attr("opacity", "1.0");
                    	R.safari();
                    };
                    
                    st[0].onmouseout = function () {
                    	lb.attr("opacity", "0");
                    	if (current != prov) {
	                    	st.animate({fill: "#c0000f", stroke: "#fff"}, 100);
	                    	R.safari();
                    	}
                    };
                    st[0].onmouseup = function () {
                        current && canada[current].animate({fill: "#c0000f", stroke: "#fff"}, 500);
                        st.animate({fill: "#ffff38", stroke: "#c0000f"}, 500);
                        //st.toFront();
                        R.safari();
                        current = prov;
                        docClickLoader.toggleInto(prov+'-job-listings.html', 'targetArea');

                    };
                })(canada[prov], prov, labels[prov]);
            }
        };
        
        function createLabel(canvas, labelText, cx, cy, boxWidth, noRow){
	        	var minHeight = 16;
	        	var perRowHeight = 16;
	        	var roundMiter = 2;
	        	var boxHeight = Math.max(perRowHeight * noRow, minHeight);
	        	var browserCorr = -1;
           	var labBoxAttr = {
                fill: "#000000",
                stroke: "#c0000f",
                "stroke-width": 1
           	}
						var labTextAttr = {
							"font-size" : "12", 
							stroke : "#ffffff"
						}
						var provSet = canvas.set();
						var labBox = canvas.rect(cx - boxWidth/2, cy - boxHeight/2 + browserCorr, boxWidth, boxHeight, roundMiter);
						var labText = canvas.text(cx, cy, labelText);
						
						labBox.attr(labBoxAttr);
						labText.attr(labTextAttr);
						provSet.push(labBox);
						provSet.push(labText);
						provSet.attr("opacity", "0");
        		
        		return provSet;
        }
