(function($) {
    $.fn.preetyButtons = function(settings) {
        var options = {
            buttonsClass : 'button',
            wrapperClass : 'wrapper',
            textClass    : 'text',
            defaultSize  : 'f16',
            nextClass    : 'next',
            prevClass    : 'prev'
        };

        if (settings) {$.extend(options, settings);}

        this.each(function(){
            var $button = $(this),
                $prev = '',
                $next = '',
                $html,
                $class;

            $class = $button.attr('class');

            // apply all existing and default classes to the link
            $class += (/f\d{1,2}/.test($class)) ? ' '+options.buttonsClass : ' '+options.defaultSize+' '+options.buttonsClass;

            // for input get the [value], for button innerHTML
            $html = (/input/.test($button[0].tagName.toLowerCase())) ? $button.val() : $button.html();

            // next and previous buttons have additional decorations 
            if ($class.indexOf(options.prevClass)!=-1) 
                $prev = '<span class="'+options.prevClass+'"></span>';
            if ($class.indexOf(options.nextClass)!=-1) 
                $next = '<span class="'+options.nextClass+'"></span>';

            $html = [
                '<span class="',options.wrapperClass,'">',
                    $prev,
                    '<span class="',options.textClass,'">',$html,'</span>',
                    $next,
                '</span>'
            ].join('') 

            $button
                .addClass('hidden')
                .after(['<a id="',$button[0].id,'" href="#" class="',$class,'"></a>'].join(''))
                .next()
                .html($html)
                .click(function(e) {
                    e.preventDefault();
                    $button.click();
                });
            
        });

        return this;
    };
})(jQuery);

