/*
 * jQuery tutukivi 0.000000001 beta
 *
 * Copyright 2010, All rights left
 */
(function($) {

    $.fn.extend({
        tutukiviButton: function(options) {
            $(this).each(function() {

                var imgs = $('img', this);
                var isHover = false;
                var isDown = false;

                function refresh() {
                    imgs.eq(0).toggle(!isDown && !isHover); // normal
                    imgs.eq(1).toggle(!isDown && isHover);  // hover
                    imgs.eq(2).toggle(isDown);              // active
                }

                $(this)
                    .hover(function() {
                        isHover = true;  refresh();
                    }, function() {
                        isHover = false; refresh();
                    })
                    .mousedown(function() {
                        isDown = true;   refresh();
                    })
                    .mouseup(function() {
                        isDown = false;  refresh();
                    });

                $(document.body).mouseup(function() {
                    isDown = false; refresh();
                });

                refresh();
            });
        }
    });
})(jQuery);
