﻿
(function ($) {
    $.fn.extend({
        circle: function (options) {

            // Set the default values
            var defaults = {
                backColor: '#ffffff'
            };

            var options = $.extend(defaults, options);

            // Iterate over the current set of matched elements
            return this.each(function () {
                var $this = $(this);
                var o = options;
                var width = $this.width();
                var height = $this.height();
                var canvas = document.createElement("canvas");

                $this.get(0).appendChild(canvas);

                canvas.width = width;
                canvas.height = height;

                if (!canvas.getContext && G_vmlCanvasManager != undefined) {
                    // try to fallback to excanvas
                    G_vmlCanvasManager.initElement(canvas);
                }

                if (canvas.getContext) {

                    var ctx = canvas.getContext("2d");

                    ctx.fillStyle = o.backColor;

                    ctx.beginPath();
                    ctx.arc(width / 2, height / 2, width / 2, 0, Math.PI * 2);
                    ctx.closePath();
                    ctx.fill();
                }
                else {
                    alert("No canvas support detected");
                }
            });
        }
    });
})(jQuery);
