Raphael.fn.pieChart = function (cx, cy, r, values, labels, stroke) {
    var paper = this,
        rad = Math.PI / 180;
    function sector(cx, cy, r, startAngle, endAngle, params) {
        var x1 = cx + r * Math.cos(-startAngle * rad),
            x2 = cx + r * Math.cos(-endAngle * rad),
            y1 = cy + r * Math.sin(-startAngle * rad),
            y2 = cy + r * Math.sin(-endAngle * rad);
        return paper.path(params).moveTo(cx, cy).lineTo(x1, y1).arcTo(r, r, (endAngle - startAngle > 180 ? 1 : 0), 0, x2, y2).andClose();
    }
    var angle = 0,
        total = 0;
        process = function (j) {
            var value = values[j],
                angleplus = 360 * value / total,
                popangle = angle + (angleplus / 2),
                color = Raphael.getColor(.7),
                ms = 200,
                delta = 5,
                p = sector(cx, cy, r, angle, angle + angleplus, {fill: color, stroke: stroke}),
                bcolor = Raphael.rgb2hsb(color);
            bcolor = Raphael.hsb2rgb(bcolor.h, bcolor.s, 1).hex;
            //var txt = paper.text(cx + (r + delta + 0) * Math.cos(-popangle * rad), cy + (r + delta + 0) * Math.sin(-popangle * rad), labels[j]).attr({fill: "white", stroke: "none", opacity: 0, "font-family": '"Arial"', "font-size": "20px", "font-weight" : "bold"});
            var txt = paper.text(130, 20, labels[j]).attr({fill: bcolor, stroke: "none", opacity: 0, "font-family": '"Arial"', "font-size": "20px", "font-weight" : "bold"});
            p.mouseover(function () {
                var dt = (new Date()).getTime(),
                    x = 0,
                    y = 0,
                    x1 = delta * Math.cos(-popangle * rad),
                    y1 = delta * Math.sin(-popangle * rad);
                p.animate({translation: [x1, y1].join(" "), fill: bcolor}, ms);
                txt.animate({opacity: 1}, ms);
            }).mouseout(function () {
                var dt = (new Date()).getTime(),
                    x = 0,
                    y = 0,
                    tr = p.attr("translation");
                p.animate({translation: [-tr.x, -tr.y].join(" "), fill: color}, ms);
                txt.animate({opacity: 0}, ms);
            });
            angle += angleplus;
        };
    for (var i = 0, ii = values.length; i < ii; i++) {
        total += values[i];
    }
    for (var i = 0; i < ii; i++) {
        process(i);
    }
};
