/*
 * jQuery UI Progressbar 1.7.2
 *
 * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Progressbar
 *
 * Depends:
 *   ui.core.js
 */
(function($) {

$.widget("ui.dropdownmenu", {

    _init: function() {

        var self = this;
        
        self.thisWindow = {};
        self.thisWindow.height = $(window).height();
        self.thisWindow.width = $(window).width();
        self.moveLeft = 250;
    
        this.element
            .addClass("ui-dropdownmenu"
                + " ui-widget"
                + " ui-widget-content"
                + " ui-corner-all")
            .draggable()
            .css({
                top: this.rand(0, self.thisWindow.height) - self.element.offset().top + 'px',    
                left: this.rand(0, self.thisWindow.width - self.moveLeft ) - self.element.offset().left + 'px'
            });

        this.footerDiv = $('<div class="ui-progressbar-value ui-widget-header ui-corner-left"></div>').appendTo(this.element);

        this.footerDiv.css( { height: '20px' } );

        this.footerDiv.bind('click', function(event, ui) {            
            self.moveTwice();
        });

    },

    destroy: function() {

        this.element
            .removeClass("ui-dropdownmenu"
                + " ui-widget"
                + " ui-widget-content"
                + " ui-corner-all")
            .unbind(".dropdownmenu");

        this.footerDiv.remove();

        $.widget.prototype.destroy.apply(this, arguments);

    },
    
    moveTwice: function(){
        if( this.element.css('margin-left') === this.moveLeft + 'px' ){
            this.move(0);
        }else{
            this.move(this.moveLeft);
        }

    },
    
    move: function( location ){
            if( typeof location === undefined ){
                location = '50';
            }        
            this.element.animate({ 
                    marginLeft: location + 'px'
                  }, this.rand(50, 5000) );
    },
    
    rand: function( min, max ){
        return max ? min + this.rand(max - min) : Math.random() * ++min << .5;
    }
    
    

});

$.extend($.ui.dropdownmenu, {
    version: "1.7.2",
    defaults: {
        value: 0
    }
});

})(jQuery);
