/*
checkout1 1.0.0 - JQuery hover button. Switches a button image between three states (off, hover, mousedown).

Requires button image to be pixel perfect stacked buttons.

Copyright (c) Aydus (www.aydus.com)

Date: 7/24/2010

ChangeLog:
*/

(function($) {

    $.fn.hoverbutton = function(options) {

    var settings = {
        enableHover: true,
        enableMousedown: true
    };

    // Extend options.
    options = options || {};
    $.extend(settings, options);

    // $this = element from plugin selector
    $this = this;

    this.each(function() {
    
        // Standard button hover effect. Shift background image position to -1 x height.
        if (settings.enableHover)
        {
            $(this).hover(
                function() {
                    var height = "-" + $(this).css('height');
                    var position = "0 " + height;
                    $(this).css({ backgroundPosition: position });
                },
                function() {
                    $(this).css({ backgroundPosition: "0 0px" });
                }
            );
        }

        if (settings.enableMousedown)
        {
            // Standard button click effect. Shift background image position to -2 x height.
            $(this).mousedown(function() {
                var height = 2 * parseFloat($(this).css('height').replace('px', ''));
                position = "0 -" + height + "px";
                $(this).css({ backgroundPosition: position });
            });
        }

    });

    return this;
};

})(jQuery);
