(function($) {
    // It takes a simple transparent image with 4 rounded corners and makes it simple to add them to any image or div.
    $.fn.rcorner = function(options) {
        var opts = $.extend({}, $.fn.rcorner.defaults, options);

        return this.each(function(i) {
            var $this = $(this);

            // Support for the Metadata Plugin.
            var o = $.meta ? $.extend({}, opts, $this.data()) : opts;

            //$this.wrap('<div class="writer' + i + '" style="position: relative"></div>');

            var insertCode = '';
            if (!opts.bottomOnly) {
                insertCode = '<div style="background-position: left top;height: ' + opts.radius + ';width: ' + opts.radius + '; background-image: url(' + opts.backgroundImage + ');position: absolute; top: ' + opts.positionOffset + '; left: ' + opts.positionOffset + ';"></div>';
                insertCode += '<div style="background-position: right top;height: ' + opts.radius + ';width: ' + opts.radius + '; background-image: url(' + opts.backgroundImage + ');position: absolute; top: ' + opts.positionOffset + '; right: ' + opts.positionOffset + ';"></div>';
            }
            insertCode += '<div style="background-position: left bottom;height: ' + opts.radius + ';width: ' + opts.radius + '; background-image: url(' + opts.backgroundImage + ');position: absolute; bottom: ' + opts.positionOffset + '; left: ' + opts.positionOffset + ';"></div>';
            insertCode += '<div style="background-position: right bottom;height: ' + opts.radius + ';width: ' + opts.radius + '; background-image: url(' + opts.backgroundImage + ');position: absolute; bottom: ' + opts.positionOffset + '; right: ' + opts.positionOffset + ';"></div>';

            //$('.writer' + i).append('<div class="tl"></div><div class="tl"></div><div class="bl"></div><div class="br"></div>');
            //$('.writer' + i).append(insertCode);
            $this.css('position', 'relative');
            $this.append(insertCode);
        });

        // private function for debugging
        function debug($obj) {
            if (window.console && window.console.log) {
                window.console.log($obj);
            }
        }
    };

    // default options
    $.fn.rcorner.defaults = {
        backgroundImage: '',
        radius: '10px',
        positionOffset: '0px',
        bottomOnly: false
    };

})(jQuery);