var Buttons = {

    init: function() {

    $('a.button-continue, a.button-previous, a.button, a.button-save').each( function() {
      if ($(this).find('span').length==0) $(this).wrapInner('<span></span>');
      $(this).bind("mousedown", function() {$(this).addClass('button-active');});
      $(this).bind("mouseup", function() {$(this).removeClass('button-active');});
    });
    
    $("button.button, input.button").each( function() {

            if( !$(this).data('button') ) {

                var original, classes, style, tabindex;

                if(this.tagName.toUpperCase()=="BUTTON") {

                    original = this;

                    classes = $(this).attr('class');
                    style = $(this).attr('style');
                    tabindex = $(this).attr('tabindex');  
                    var text = $(this)
                        .hide()
                        .html();
                     
                }

                else if(this.tagName.toUpperCase()=="INPUT") {

                    original = this;
                    var text = this.value;

                    classes = $(this).attr('class');
                    style = $(this).attr('style');
                    tabindex = $(this).attr('tabindex');

                    $(this).hide()

                }
                
                var a = $("<a href='#'><span class='text'>"+text+"</span></a>")
                .bind("click", function() {
                            original.click();
                            return false;
                })
                .bind("mousedown", function() {$(this).addClass('button-active');})
                .bind("mouseup", function() {$(this).removeClass('button-active');})
                .insertAfter(original);
                        
                if (style) a.attr('style',style);
                if (classes) a.addClass(classes);
                if (tabindex) {a.attr('tabindex',tabindex);$(original).removeAttr('tabindex');}
                $(this).data("button", true);
            }
        });

    }

}
