Tuesday, December 20, 2011

jquery-ui-1.8.16.Altered.js


    _notifyChange: function(inst) {
        var onChange = this._get(inst, 'onChangeMonthYear');
        if (onChange)
            onChange.apply((inst.input ? inst.input[0] : null),
                [inst.selectedYear, inst.selectedMonth + 1, inst]);
    },

    /* Determine the number of months to show. */
    _getNumberOfMonths: function(inst) {
        var numMonths = this._get(inst, 'numberOfMonths');
        return (numMonths == null ? [1, 1] : (typeof numMonths == 'number' ? [1, numMonths] : numMonths));
    },

    /* Determine the current maximum date - ensure no time components are set. */
    _getMinMaxDate: function(inst, minMax) {
        return this._determineDate(inst, this._get(inst, minMax + 'Date'), null);
    },

    /* Find the number of days in a given month. */
    _getDaysInMonth: function(year, month) {
        return 32 - this._daylightSavingAdjust(new Date(year, month, 32)).getDate();
    },

    /* Find the day of the week of the first of a month. */
    _getFirstDayOfMonth: function(year, month) {
        return new Date(year, month, 1).getDay();
    },

    /* Determines if we should allow a "next/prev" month display change. */
    _canAdjustMonth: function(inst, offset, curYear, curMonth) {
        var numMonths = this._getNumberOfMonths(inst);
        var date = this._daylightSavingAdjust(new Date(curYear,
            curMonth + (offset < 0 ? offset : numMonths[0] * numMonths[1]), 1));
        if (offset < 0)
            date.setDate(this._getDaysInMonth(date.getFullYear(), date.getMonth()));
        return this._isInRange(inst, date);
    },

    /* Is the given date in the accepted range? */
    _isInRange: function(inst, date) {
        var minDate = this._getMinMaxDate(inst, 'min');
        var maxDate = this._getMinMaxDate(inst, 'max');
        return ((!minDate || date.getTime() >= minDate.getTime()) &&
            (!maxDate || date.getTime() <= maxDate.getTime()));
    },

    /* Provide the configuration settings for formatting/parsing. */
    _getFormatConfig: function(inst) {
        var shortYearCutoff = this._get(inst, 'shortYearCutoff');
        shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff :
            new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
        return {shortYearCutoff: shortYearCutoff,
            dayNamesShort: this._get(inst, 'dayNamesShort'), dayNames: this._get(inst, 'dayNames'),
            monthNamesShort: this._get(inst, 'monthNamesShort'), monthNames: this._get(inst, 'monthNames')};
    },

    /* Format the given date for display. */
    _formatDate: function(inst, day, month, year) {
        if (!day) {
            inst.currentDay = inst.selectedDay;
            inst.currentMonth = inst.selectedMonth;
            inst.currentYear = inst.selectedYear;
        }
        var date = (day ? (typeof day == 'object' ? day :
            this._daylightSavingAdjust(new Date(year, month, day))) :
            this._daylightSavingAdjust(new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
        return this.formatDate(this._get(inst, 'dateFormat'), date, this._getFormatConfig(inst));
    }
});

/*
 * Bind hover events for datepicker elements.
 * Done via delegate so the binding only occurs once in the lifetime of the parent div.
 * Global instActive, set by _updateDatepicker allows the handlers to find their way back to the active picker.
 */
function bindHover(dpDiv) {
    var selector = 'button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a';
    return dpDiv.bind('mouseout', function(event) {
            var elem = $( event.target ).closest( selector );
            if ( !elem.length ) {
                return;
            }
            elem.removeClass( "ui-state-hover ui-datepicker-prev-hover ui-datepicker-next-hover" );
        })
        .bind('mouseover', function(event) {
            var elem = $( event.target ).closest( selector );
            if ($.datepicker._isDisabledDatepicker( instActive.inline ? dpDiv.parent()[0] : instActive.input[0]) ||
                    !elem.length ) {
                return;
            }
            elem.parents('.ui-datepicker-calendar').find('a').removeClass('ui-state-hover');
            elem.addClass('ui-state-hover');
            if (elem.hasClass('ui-datepicker-prev')) elem.addClass('ui-datepicker-prev-hover');
            if (elem.hasClass('ui-datepicker-next')) elem.addClass('ui-datepicker-next-hover');
        });
}

/* jQuery extend now ignores nulls! */
function extendRemove(target, props) {
    $.extend(target, props);
    for (var name in props)
        if (props[name] == null || props[name] == undefined)
            target[name] = props[name];
    return target;
};

/* Determine whether an object is an array. */
function isArray(a) {
    return (a && (($.browser.safari && typeof a == 'object' && a.length) ||
        (a.constructor && a.constructor.toString().match(/\Array\(\)/))));
};

/* Invoke the datepicker functionality.
   @param  options  string - a command, optionally followed by additional parameters or
                    Object - settings for attaching new datepicker functionality
   @return  jQuery object */
$.fn.datepicker = function(options){
  
    /* Verify an empty collection wasn't passed - Fixes #6976 */
    if ( !this.length ) {
        return this;
    }
  
    /* Initialise the date picker. */
    if (!$.datepicker.initialized) {
        $(document).mousedown($.datepicker._checkExternalClick).
            find('body').append($.datepicker.dpDiv);
        $.datepicker.initialized = true;
    }

    var otherArgs = Array.prototype.slice.call(arguments, 1);
    if (typeof options == 'string' && (options == 'isDisabled' || options == 'getDate' || options == 'widget'))
        return $.datepicker['_' + options + 'Datepicker'].
            apply($.datepicker, [this[0]].concat(otherArgs));
    if (options == 'option' && arguments.length == 2 && typeof arguments[1] == 'string')
        return $.datepicker['_' + options + 'Datepicker'].
            apply($.datepicker, [this[0]].concat(otherArgs));
    return this.each(function() {
        typeof options == 'string' ?
            $.datepicker['_' + options + 'Datepicker'].
                apply($.datepicker, [this].concat(otherArgs)) :
            $.datepicker._attachDatepicker(this, options);
    });
};

$.datepicker = new Datepicker(); // singleton instance
$.datepicker.initialized = false;
$.datepicker.uuid = new Date().getTime();
$.datepicker.version = "1.8.16";

// Workaround for #4055
// Add another global to avoid noConflict issues with inline event handlers
window['DP_jQuery_' + dpuuid] = $;

})(jQuery);
/*
 * jQuery UI Dialog 1.8.16
 *
 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * http://docs.jquery.com/UI/Dialog
 *
 * Depends:
 *    jquery.ui.core.js
 *    jquery.ui.widget.js
 *  jquery.ui.button.js
 *    jquery.ui.draggable.js
 *    jquery.ui.mouse.js
 *    jquery.ui.position.js
 *    jquery.ui.resizable.js
 */
(function( $, undefined ) {

var uiDialogClasses =
        'ui-dialog ' +
        'ui-widget ' +
        'ui-widget-content ' +
        'ui-corner-all ',
    sizeRelatedOptions = {
        buttons: true,
        height: true,
        maxHeight: true,
        maxWidth: true,
        minHeight: true,
        minWidth: true,
        width: true
    },
    resizableRelatedOptions = {
        maxHeight: true,
        maxWidth: true,
        minHeight: true,
        minWidth: true
    },
    // support for jQuery 1.3.2 - handle common attrFn methods for dialog
    attrFn = $.attrFn || {
        val: true,
        css: true,
        html: true,
        text: true,
        data: true,
        width: true,
        height: true,
        offset: true,
        click: true
    };

$.widget("ui.dialog", {
    options: {
        autoOpen: true,
        buttons: {},
        closeOnEscape: true,
        closeText: 'close',
        dialogClass: '',
        draggable: true,
        hide: null,
        height: 'auto',
        maxHeight: false,
        maxWidth: false,
        minHeight: 150,
        minWidth: 150,
        modal: false,
        position: {
            my: 'center',
            at: 'center',
            collision: 'fit',
            // ensure that the titlebar is never outside the document
            using: function(pos) {
                var topOffset = $(this).css(pos).offset().top;
                if (topOffset < 0) {
                    $(this).css('top', pos.top - topOffset);
                }
            }
        },
        resizable: true,
        show: null,
        stack: true,
        title: '',
        width: 300,
        zIndex: 1000,
        appendWhere: 'body'
    },

    _create: function() {
        this.originalTitle = this.element.attr('title');
        // #5742 - .attr() might return a DOMElement
        if ( typeof this.originalTitle !== "string" ) {
            this.originalTitle = "";
        }

        this.options.title = this.options.title || this.originalTitle;
        var self = this,
            options = self.options,

            title = options.title || '&#160;',
            titleId = $.ui.dialog.getTitleId(self.element),

            uiDialog = (self.uiDialog = $('<div></div>'))
                .appendTo(this.options.appendWhere)
                .hide()
                .addClass(uiDialogClasses + options.dialogClass)
                .css({
                    zIndex: options.zIndex
                })
                // setting tabIndex makes the div focusable
                // setting outline to 0 prevents a border on focus in Mozilla
                .attr('tabIndex', -1).css('outline', 0).keydown(function(event) {
                    if (options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
                        event.keyCode === $.ui.keyCode.ESCAPE) {
                      
                        self.close(event);
                        event.preventDefault();
                    }
                })
                .attr({
                    role: 'dialog',
                    'aria-labelledby': titleId
                })
                .mousedown(function(event) {
                    self.moveToTop(false, event);
                }),

            uiDialogContent = self.element
                .show()
                .removeAttr('title')
                .addClass(
                    'ui-dialog-content ' +
                    'ui-widget-content')
                .appendTo(uiDialog),

            uiDialogTitlebar = (self.uiDialogTitlebar = $('<div></div>'))
                .addClass(
                    'ui-dialog-titlebar ' +
                    'ui-widget-header ' +
                    'ui-corner-all ' +
                    'ui-helper-clearfix'
                )
                .prependTo(uiDialog),

            uiDialogTitlebarClose = $('<a href="#"></a>')
                .addClass(
                    'ui-dialog-titlebar-close ' +
                    'ui-corner-all'
                )
                .attr('role', 'button')
                .hover(
                    function() {
                        uiDialogTitlebarClose.addClass('ui-state-hover');
                    },
                    function() {
                        uiDialogTitlebarClose.removeClass('ui-state-hover');
                    }
                )
                .focus(function() {
                    uiDialogTitlebarClose.addClass('ui-state-focus');
                })
                .blur(function() {
                    uiDialogTitlebarClose.removeClass('ui-state-focus');
                })
                .click(function(event) {
                    self.close(event);
                    return false;
                })
                .appendTo(uiDialogTitlebar),

            uiDialogTitlebarCloseText = (self.uiDialogTitlebarCloseText = $('<span></span>'))
                .addClass(
                    'ui-icon ' +
                    'ui-icon-closethick'
                )
                .text(options.closeText)
                .appendTo(uiDialogTitlebarClose),

            uiDialogTitle = $('<span></span>')
                .addClass('ui-dialog-title')
                .attr('id', titleId)
                .html(title)
                .prependTo(uiDialogTitlebar);

        //handling of deprecated beforeclose (vs beforeClose) option
        //Ticket #4669 http://dev.jqueryui.com/ticket/4669
        //TODO: remove in 1.9pre
        if ($.isFunction(options.beforeclose) && !$.isFunction(options.beforeClose)) {
            options.beforeClose = options.beforeclose;
        }

        uiDialogTitlebar.find("*").add(uiDialogTitlebar).disableSelection();

        if (options.draggable && $.fn.draggable) {
            self._makeDraggable();
        }
        if (options.resizable && $.fn.resizable) {
            self._makeResizable();
        }

        self._createButtons(options.buttons);
        self._isOpen = false;

        if ($.fn.bgiframe) {
            uiDialog.bgiframe();
        }
    },

    _init: function() {
        if ( this.options.autoOpen ) {
            this.open();
        }
    },

    destroy: function() {
        var self = this;
      
        if (self.overlay) {
            self.overlay.destroy();
        }
        self.uiDialog.hide();
        self.element
            .unbind('.dialog')
            .removeData('dialog')
            .removeClass('ui-dialog-content ui-widget-content')
            .hide().appendTo('body');
        self.uiDialog.remove();

        if (self.originalTitle) {
            self.element.attr('title', self.originalTitle);
        }

        return self;
    },

    widget: function() {
        return this.uiDialog;
    },

    close: function(event) {
        var self = this,
            maxZ, thisZ;
      
        if (false === self._trigger('beforeClose', event)) {
            return;
        }

        if (self.overlay) {
            self.overlay.destroy();
        }
        self.uiDialog.unbind('keypress.ui-dialog');

        self._isOpen = false;

        if (self.options.hide) {
            self.uiDialog.hide(self.options.hide, function() {
                self._trigger('close', event);
            });
        } else {
            self.uiDialog.hide();
            self._trigger('close', event);
        }

        $.ui.dialog.overlay.resize();

        // adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
        if (self.options.modal) {
            maxZ = 0;
            $('.ui-dialog').each(function() {
                if (this !== self.uiDialog[0]) {
                    thisZ = $(this).css('z-index');
                    if(!isNaN(thisZ)) {
                        maxZ = Math.max(maxZ, thisZ);
                    }
                }
            });
            $.ui.dialog.maxZ = maxZ;
        }

        return self;
    },

    isOpen: function() {
        return this._isOpen;
    },

    // the force parameter allows us to move modal dialogs to their correct
    // position on open
    moveToTop: function(force, event) {
        var self = this,
            options = self.options,
            saveScroll;

        if ((options.modal && !force) ||
            (!options.stack && !options.modal)) {
            return self._trigger('focus', event);
        }

        if (options.zIndex > $.ui.dialog.maxZ) {
            $.ui.dialog.maxZ = options.zIndex;
        }
        if (self.overlay) {
            $.ui.dialog.maxZ += 1;
            self.overlay.$el.css('z-index', $.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ);
        }

        //Save and then restore scroll since Opera 9.5+ resets when parent z-Index is changed.
        //  http://ui.jquery.com/bugs/ticket/3193
        saveScroll = { scrollTop: self.element.scrollTop(), scrollLeft: self.element.scrollLeft() };
        $.ui.dialog.maxZ += 1;
        self.uiDialog.css('z-index', $.ui.dialog.maxZ);
        self.element.attr(saveScroll);
        self._trigger('focus', event);

        return self;
    },

    open: function() {
        if (this._isOpen) { return; }

        var self = this,
            options = self.options,
            uiDialog = self.uiDialog;

        self.overlay = options.modal ? new $.ui.dialog.overlay(self) : null;
        self._size();
        self._position(options.position);
        uiDialog.show(options.show);
        self.moveToTop(true);

        // prevent tabbing out of modal dialogs
        if (options.modal) {
            uiDialog.bind('keypress.ui-dialog', function(event) {
                if (event.keyCode !== $.ui.keyCode.TAB) {
                    return;
                }

                var tabbables = $(':tabbable', this),
                    first = tabbables.filter(':first'),
                    last  = tabbables.filter(':last');

                if (event.target === last[0] && !event.shiftKey) {
                    first.focus(1);
                    return false;
                } else if (event.target === first[0] && event.shiftKey) {
                    last.focus(1);
                    return false;
                }
            });
        }

        // set focus to the first tabbable element in the content area or the first button
        // if there are no tabbable elements, set focus on the dialog itself
        $(self.element.find(':tabbable').get().concat(
            uiDialog.find('.ui-dialog-buttonpane :tabbable').get().concat(
                uiDialog.get()))).eq(0).focus();

        self._isOpen = true;
        self._trigger('open');

        return self;
    },

    _createButtons: function(buttons) {
        var self = this,
            hasButtons = false,
            uiDialogButtonPane = $('<div></div>')
                .addClass(
                    'ui-dialog-buttonpane ' +
                    'ui-widget-content ' +
                    'ui-helper-clearfix'
                ),
            uiButtonSet = $( "<div></div>" )
                .addClass( "ui-dialog-buttonset" )
                .appendTo( uiDialogButtonPane );

        // if we already have a button pane, remove it
        self.uiDialog.find('.ui-dialog-buttonpane').remove();

        if (typeof buttons === 'object' && buttons !== null) {
            $.each(buttons, function() {
                return !(hasButtons = true);
            });
        }
        if (hasButtons) {
            $.each(buttons, function(name, props) {
                props = $.isFunction( props ) ?
                    { click: props, text: name } :
                    props;
                var button = $('<button type="button"></button>')
                    .click(function() {
                        props.click.apply(self.element[0], arguments);
                    })
                    .appendTo(uiButtonSet);
                // can't use .attr( props, true ) with jQuery 1.3.2.
                $.each( props, function( key, value ) {
                    if ( key === "click" ) {
                        return;
                    }
                    if ( key in attrFn ) {
                        button[ key ]( value );
                    } else {
                        button.attr( key, value );
                    }
                });
                if ($.fn.button) {
                    button.button();
                }
            });
            uiDialogButtonPane.appendTo(self.uiDialog);
        }
    },

    _makeDraggable: function() {
        var self = this,
            options = self.options,
            doc = $(document),
            heightBeforeDrag;

        function filteredUi(ui) {
            return {
                position: ui.position,
                offset: ui.offset
            };
        }

        self.uiDialog.draggable({
            cancel: '.ui-dialog-content, .ui-dialog-titlebar-close',
            handle: '.ui-dialog-titlebar',
            containment: 'document',
            start: function(event, ui) {
                heightBeforeDrag = options.height === "auto" ? "auto" : $(this).height();
                $(this).height($(this).height()).addClass("ui-dialog-dragging");
                self._trigger('dragStart', event, filteredUi(ui));
            },
            drag: function(event, ui) {
                self._trigger('drag', event, filteredUi(ui));
            },
            stop: function(event, ui) {
                options.position = [ui.position.left - doc.scrollLeft(),
                    ui.position.top - doc.scrollTop()];
                $(this).removeClass("ui-dialog-dragging").height(heightBeforeDrag);
                self._trigger('dragStop', event, filteredUi(ui));
                $.ui.dialog.overlay.resize();
            }
        });
    },

    _makeResizable: function(handles) {
        handles = (handles === undefined ? this.options.resizable : handles);
        var self = this,
            options = self.options,
            // .ui-resizable has position: relative defined in the stylesheet
            // but dialogs have to use absolute or fixed positioning
            position = self.uiDialog.css('position'),
            resizeHandles = (typeof handles === 'string' ?
                handles    :
                'n,e,s,w,se,sw,ne,nw'
            );

        function filteredUi(ui) {
            return {
                originalPosition: ui.originalPosition,
                originalSize: ui.originalSize,
                position: ui.position,
                size: ui.size
            };
        }

        self.uiDialog.resizable({
            cancel: '.ui-dialog-content',
            containment: 'document',
            alsoResize: self.element,
            maxWidth: options.maxWidth,
            maxHeight: options.maxHeight,
            minWidth: options.minWidth,
            minHeight: self._minHeight(),
            handles: resizeHandles,
            start: function(event, ui) {
                $(this).addClass("ui-dialog-resizing");
                self._trigger('resizeStart', event, filteredUi(ui));
            },
            resize: function(event, ui) {
                self._trigger('resize', event, filteredUi(ui));
            },
            stop: function(event, ui) {
                $(this).removeClass("ui-dialog-resizing");
                options.height = $(this).height();
                options.width = $(this).width();
                self._trigger('resizeStop', event, filteredUi(ui));
                $.ui.dialog.overlay.resize();
            }
        })
        .css('position', position)
        .find('.ui-resizable-se').addClass('ui-icon ui-icon-grip-diagonal-se');
    },

    _minHeight: function() {
        var options = this.options;

        if (options.height === 'auto') {
            return options.minHeight;
        } else {
            return Math.min(options.minHeight, options.height);
        }
    },

    _position: function(position) {
        var myAt = [],
            offset = [0, 0],
            isVisible;

        if (position) {
            // deep extending converts arrays to objects in jQuery <= 1.3.2 :-(
    //        if (typeof position == 'string' || $.isArray(position)) {
    //            myAt = $.isArray(position) ? position : position.split(' ');

            if (typeof position === 'string' || (typeof position === 'object' && '0' in position)) {
                myAt = position.split ? position.split(' ') : [position[0], position[1]];
                if (myAt.length === 1) {
                    myAt[1] = myAt[0];
                }

                $.each(['left', 'top'], function(i, offsetPosition) {
                    if (+myAt[i] === myAt[i]) {
                        offset[i] = myAt[i];
                        myAt[i] = offsetPosition;
                    }
                });

                position = {
                    my: myAt.join(" "),
                    at: myAt.join(" "),
                    offset: offset.join(" ")
                };
            }

            position = $.extend({}, $.ui.dialog.prototype.options.position, position);
        } else {
            position = $.ui.dialog.prototype.options.position;
        }

        // need to show the dialog to get the actual offset in the position plugin
        isVisible = this.uiDialog.is(':visible');
        if (!isVisible) {
            this.uiDialog.show();
        }
        this.uiDialog
            // workaround for jQuery bug #5781 http://dev.jquery.com/ticket/5781
            .css({ top: 0, left: 0 })
            .position($.extend({ of: window }, position));
        if (!isVisible) {
            this.uiDialog.hide();
        }
    },

    _setOptions: function( options ) {
        var self = this,
            resizableOptions = {},
            resize = false;

        $.each( options, function( key, value ) {
            self._setOption( key, value );
          
            if ( key in sizeRelatedOptions ) {
                resize = true;
            }
            if ( key in resizableRelatedOptions ) {
                resizableOptions[ key ] = value;
            }
        });

        if ( resize ) {
            this._size();
        }
        if ( this.uiDialog.is( ":data(resizable)" ) ) {
            this.uiDialog.resizable( "option", resizableOptions );
        }
    },

    _setOption: function(key, value){
        var self = this,
            uiDialog = self.uiDialog;

        switch (key) {
            //handling of deprecated beforeclose (vs beforeClose) option
            //Ticket #4669 http://dev.jqueryui.com/ticket/4669
            //TODO: remove in 1.9pre
            case "beforeclose":
                key = "beforeClose";
                break;
            case "buttons":
                self._createButtons(value);
                break;
            case "closeText":
                // ensure that we always pass a string
                self.uiDialogTitlebarCloseText.text("" + value);
                break;
            case "dialogClass":
                uiDialog
                    .removeClass(self.options.dialogClass)
                    .addClass(uiDialogClasses + value);
                break;
            case "disabled":
                if (value) {
                    uiDialog.addClass('ui-dialog-disabled');
                } else {
                    uiDialog.removeClass('ui-dialog-disabled');
                }
                break;
            case "draggable":
                var isDraggable = uiDialog.is( ":data(draggable)" );
                if ( isDraggable && !value ) {
                    uiDialog.draggable( "destroy" );
                }
              
                if ( !isDraggable && value ) {
                    self._makeDraggable();
                }
                break;
            case "position":
                self._position(value);
                break;
            case "resizable":
                // currently resizable, becoming non-resizable
                var isResizable = uiDialog.is( ":data(resizable)" );
                if (isResizable && !value) {
                    uiDialog.resizable('destroy');
                }

                // currently resizable, changing handles
                if (isResizable && typeof value === 'string') {
                    uiDialog.resizable('option', 'handles', value);
                }

                // currently non-resizable, becoming resizable
                if (!isResizable && value !== false) {
                    self._makeResizable(value);
                }
                break;
            case "title":
                // convert whatever was passed in o a string, for html() to not throw up
                $(".ui-dialog-title", self.uiDialogTitlebar).html("" + (value || '&#160;'));
                break;
        }

        $.Widget.prototype._setOption.apply(self, arguments);
    },

    _size: function() {
        /* If the user has resized the dialog, the .ui-dialog and .ui-dialog-content
         * divs will both have width and height set, so we need to reset them
         */
        var options = this.options,
            nonContentHeight,
            minContentHeight,
            isVisible = this.uiDialog.is( ":visible" );

        // reset content sizing
        this.element.show().css({
            width: 'auto',
            minHeight: 0,
            height: 0
        });

        if (options.minWidth > options.width) {
            options.width = options.minWidth;
        }

        // reset wrapper sizing
        // determine the height of all the non-content elements
        nonContentHeight = this.uiDialog.css({
                height: 'auto',
                width: options.width
            })
            .height();
        minContentHeight = Math.max( 0, options.minHeight - nonContentHeight );
      
        if ( options.height === "auto" ) {
            // only needed for IE6 support
            if ( $.support.minHeight ) {
                this.element.css({
                    minHeight: minContentHeight,
                    height: "auto"
                });
            } else {
                this.uiDialog.show();
                var autoHeight = this.element.css( "height", "auto" ).height();
                if ( !isVisible ) {
                    this.uiDialog.hide();
                }
                this.element.height( Math.max( autoHeight, minContentHeight ) );
            }
        } else {
            this.element.height( Math.max( options.height - nonContentHeight, 0 ) );
        }

        if (this.uiDialog.is(':data(resizable)')) {
            this.uiDialog.resizable('option', 'minHeight', this._minHeight());
        }
    }
});

$.extend($.ui.dialog, {
    version: "1.8.16",

    uuid: 0,
    maxZ: 0,

    getTitleId: function($el) {
        var id = $el.attr('id');
        if (!id) {
            this.uuid += 1;
            id = this.uuid;
        }
        return 'ui-dialog-title-' + id;
    },

    overlay: function(dialog) {
        this.$el = $.ui.dialog.overlay.create(dialog);
    }
});

$.extend($.ui.dialog.overlay, {
    instances: [],
    // reuse old instances due to IE memory leak with alpha transparency (see #5185)
    oldInstances: [],
    maxZ: 0,
    events: $.map('focus,mousedown,mouseup,keydown,keypress,click'.split(','),
        function(event) { return event + '.dialog-overlay'; }).join(' '),
    create: function(dialog) {
        if (this.instances.length === 0) {
            // prevent use of anchors and inputs
            // we use a setTimeout in case the overlay is created from an
            // event that we're going to be cancelling (see #2804)
            setTimeout(function() {
                // handle $(el).dialog().dialog('close') (see #4065)
                if ($.ui.dialog.overlay.instances.length) {
                    $(document).bind($.ui.dialog.overlay.events, function(event) {
                        // stop events if the z-index of the target is < the z-index of the overlay
                        // we cannot return true when we don't want to cancel the event (#3523)
                        if ($(event.target).zIndex() < $.ui.dialog.overlay.maxZ) {
                            return false;
                        }
                    });
                }
            }, 1);

            // allow closing by pressing the escape key
            $(document).bind('keydown.dialog-overlay', function(event) {
                if (dialog.options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
                    event.keyCode === $.ui.keyCode.ESCAPE) {
                  
                    dialog.close(event);
                    event.preventDefault();
                }
            });

            // handle window resize
            $(window).bind('resize.dialog-overlay', $.ui.dialog.overlay.resize);
        }

        var $el = (this.oldInstances.pop() || $('<div></div>').addClass('ui-widget-overlay'))
            .appendTo(document.body)
            .css({
                width: this.width(),
                height: this.height()
            });

        if ($.fn.bgiframe) {
            $el.bgiframe();
        }

        this.instances.push($el);
        return $el;
    },

    destroy: function($el) {
        var indexOf = $.inArray($el, this.instances);
        if (indexOf != -1){
            this.oldInstances.push(this.instances.splice(indexOf, 1)[0]);
        }

        if (this.instances.length === 0) {
            $([document, window]).unbind('.dialog-overlay');
        }

        $el.remove();
      
        // adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
        var maxZ = 0;
        $.each(this.instances, function() {
            maxZ = Math.max(maxZ, this.css('z-index'));
        });
        this.maxZ = maxZ;
    },

    height: function() {
        var scrollHeight,
            offsetHeight;
        // handle IE 6
        if ($.browser.msie && $.browser.version < 7) {
            scrollHeight = Math.max(
                document.documentElement.scrollHeight,
                document.body.scrollHeight
            );
            offsetHeight = Math.max(
                document.documentElement.offsetHeight,
                document.body.offsetHeight
            );

            if (scrollHeight < offsetHeight) {
                return $(window).height() + 'px';
            } else {
                return scrollHeight + 'px';
            }
        // handle "good" browsers
        } else {
            return $(document).height() + 'px';
        }
    },

    width: function() {
        var scrollWidth,
            offsetWidth;
        // handle IE
        if ( $.browser.msie ) {
            scrollWidth = Math.max(
                document.documentElement.scrollWidth,
                document.body.scrollWidth
            );
            offsetWidth = Math.max(
                document.documentElement.offsetWidth,
                document.body.offsetWidth
            );

            if (scrollWidth < offsetWidth) {
                return $(window).width() + 'px';
            } else {
                return scrollWidth + 'px';
            }
        // handle "good" browsers
        } else {
            return $(document).width() + 'px';
        }
    },

    resize: function() {
        /* If the dialog is draggable and the user drags it past the
         * right edge of the window, the document becomes wider so we
         * need to stretch the overlay. If the user then drags the
         * dialog back to the left, the document will become narrower,
         * so we need to shrink the overlay to the appropriate size.
         * This is handled by shrinking the overlay before setting it
         * to the full document size.
         */
        var $overlays = $([]);
        $.each($.ui.dialog.overlay.instances, function() {
            $overlays = $overlays.add(this);
        });

        $overlays.css({
            width: 0,
            height: 0
        }).css({
            width: $.ui.dialog.overlay.width(),
            height: $.ui.dialog.overlay.height()
        });
    }
});

$.extend($.ui.dialog.overlay.prototype, {
    destroy: function() {
        $.ui.dialog.overlay.destroy(this.$el);
    }
});

}(jQuery));
/*
 * jQuery UI Position 1.8.16
 *
 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * http://docs.jquery.com/UI/Position
 */
(function( $, undefined ) {

$.ui = $.ui || {};

var horizontalPositions = /left|center|right/,
    verticalPositions = /top|center|bottom/,
    center = "center",
    _position = $.fn.position,
    _offset = $.fn.offset;

$.fn.position = function( options ) {
    if ( !options || !options.of ) {
        return _position.apply( this, arguments );
    }

    // make a copy, we don't want to modify arguments
    options = $.extend( {}, options );

    var target = $( options.of ),
        targetElem = target[0],
        collision = ( options.collision || "flip" ).split( " " ),
        offset = options.offset ? options.offset.split( " " ) : [ 0, 0 ],
        targetWidth,
        targetHeight,
        basePosition;

    if ( targetElem.nodeType === 9 ) {
        targetWidth = target.width();
        targetHeight = target.height();
        basePosition = { top: 0, left: 0 };
    // TODO: use $.isWindow() in 1.9
    } else if ( targetElem.setTimeout ) {
        targetWidth = target.width();
        targetHeight = target.height();
        basePosition = { top: target.scrollTop(), left: target.scrollLeft() };
    } else if ( targetElem.preventDefault ) {
        // force left top to allow flipping
        options.at = "left top";
        targetWidth = targetHeight = 0;
        basePosition = { top: options.of.pageY, left: options.of.pageX };
    } else {
        targetWidth = target.outerWidth();
        targetHeight = target.outerHeight();
        basePosition = target.offset();
    }

    // force my and at to have valid horizontal and veritcal positions
    // if a value is missing or invalid, it will be converted to center
    $.each( [ "my", "at" ], function() {
        var pos = ( options[this] || "" ).split( " " );
        if ( pos.length === 1) {
            pos = horizontalPositions.test( pos[0] ) ?
                pos.concat( [center] ) :
                verticalPositions.test( pos[0] ) ?
                    [ center ].concat( pos ) :
                    [ center, center ];
        }
        pos[ 0 ] = horizontalPositions.test( pos[0] ) ? pos[ 0 ] : center;
        pos[ 1 ] = verticalPositions.test( pos[1] ) ? pos[ 1 ] : center;
        options[ this ] = pos;
    });

    // normalize collision option
    if ( collision.length === 1 ) {
        collision[ 1 ] = collision[ 0 ];
    }

    // normalize offset option
    offset[ 0 ] = parseInt( offset[0], 10 ) || 0;
    if ( offset.length === 1 ) {
        offset[ 1 ] = offset[ 0 ];
    }
    offset[ 1 ] = parseInt( offset[1], 10 ) || 0;

    if ( options.at[0] === "right" ) {
        basePosition.left += targetWidth;
    } else if ( options.at[0] === center ) {
        basePosition.left += targetWidth / 2;
    }

    if ( options.at[1] === "bottom" ) {
        basePosition.top += targetHeight;
    } else if ( options.at[1] === center ) {
        basePosition.top += targetHeight / 2;
    }

    basePosition.left += offset[ 0 ];
    basePosition.top += offset[ 1 ];

    return this.each(function() {
        var elem = $( this ),
            elemWidth = elem.outerWidth(),
            elemHeight = elem.outerHeight(),
            marginLeft = parseInt( $.curCSS( this, "marginLeft", true ) ) || 0,
            marginTop = parseInt( $.curCSS( this, "marginTop", true ) ) || 0,
            collisionWidth = elemWidth + marginLeft +
                ( parseInt( $.curCSS( this, "marginRight", true ) ) || 0 ),
            collisionHeight = elemHeight + marginTop +
                ( parseInt( $.curCSS( this, "marginBottom", true ) ) || 0 ),
            position = $.extend( {}, basePosition ),
            collisionPosition;

        if ( options.my[0] === "right" ) {
            position.left -= elemWidth;
        } else if ( options.my[0] === center ) {
            position.left -= elemWidth / 2;
        }

        if ( options.my[1] === "bottom" ) {
            position.top -= elemHeight;
        } else if ( options.my[1] === center ) {
            position.top -= elemHeight / 2;
        }

        // prevent fractions (see #5280)
        position.left = Math.round( position.left );
        position.top = Math.round( position.top );

        collisionPosition = {
            left: position.left - marginLeft,
            top: position.top - marginTop
        };

        $.each( [ "left", "top" ], function( i, dir ) {
            if ( $.ui.position[ collision[i] ] ) {
                $.ui.position[ collision[i] ][ dir ]( position, {
                    targetWidth: targetWidth,
                    targetHeight: targetHeight,
                    elemWidth: elemWidth,
                    elemHeight: elemHeight,
                    collisionPosition: collisionPosition,
                    collisionWidth: collisionWidth,
                    collisionHeight: collisionHeight,
                    offset: offset,
                    my: options.my,
                    at: options.at
                });
            }
        });

        if ( $.fn.bgiframe ) {
            elem.bgiframe();
        }
        elem.offset( $.extend( position, { using: options.using } ) );
    });
};

$.ui.position = {
    fit: {
        left: function( position, data ) {
            var win = $( window ),
                over = data.collisionPosition.left + data.collisionWidth - win.width() - win.scrollLeft();
            position.left = over > 0 ? position.left - over : Math.max( position.left - data.collisionPosition.left, position.left );
        },
        top: function( position, data ) {
            var win = $( window ),
                over = data.collisionPosition.top + data.collisionHeight - win.height() - win.scrollTop();
            position.top = over > 0 ? position.top - over : Math.max( position.top - data.collisionPosition.top, position.top );
        }
    },

    flip: {
        left: function( position, data ) {
            if ( data.at[0] === center ) {
                return;
            }
            var win = $( window ),
                over = data.collisionPosition.left + data.collisionWidth - win.width() - win.scrollLeft(),
                myOffset = data.my[ 0 ] === "left" ?
                    -data.elemWidth :
                    data.my[ 0 ] === "right" ?
                        data.elemWidth :
                        0,
                atOffset = data.at[ 0 ] === "left" ?
                    data.targetWidth :
                    -data.targetWidth,
                offset = -2 * data.offset[ 0 ];
            position.left += data.collisionPosition.left < 0 ?
                myOffset + atOffset + offset :
                over > 0 ?
                    myOffset + atOffset + offset :
                    0;
        },
        top: function( position, data ) {
            if ( data.at[1] === center ) {
                return;
            }
            var win = $( window ),
                over = data.collisionPosition.top + data.collisionHeight - win.height() - win.scrollTop(),
                myOffset = data.my[ 1 ] === "top" ?
                    -data.elemHeight :
                    data.my[ 1 ] === "bottom" ?
                        data.elemHeight :
                        0,
                atOffset = data.at[ 1 ] === "top" ?
                    data.targetHeight :
                    -data.targetHeight,
                offset = -2 * data.offset[ 1 ];
            position.top += data.collisionPosition.top < 0 ?
                myOffset + atOffset + offset :
                over > 0 ?
                    myOffset + atOffset + offset :
                    0;
        }
    }
};

// offset setter from jQuery 1.4
if ( !$.offset.setOffset ) {
    $.offset.setOffset = function( elem, options ) {
        // set position first, in-case top/left are set even on static elem
        if ( /static/.test( $.curCSS( elem, "position" ) ) ) {
            elem.style.position = "relative";
        }
        var curElem   = $( elem ),
            curOffset = curElem.offset(),
            curTop    = parseInt( $.curCSS( elem, "top",  true ), 10 ) || 0,
            curLeft   = parseInt( $.curCSS( elem, "left", true ), 10)  || 0,
            props     = {
                top:  (options.top  - curOffset.top)  + curTop,
                left: (options.left - curOffset.left) + curLeft
            };
      
        if ( 'using' in options ) {
            options.using.call( elem, props );
        } else {
            curElem.css( props );
        }
    };

    $.fn.offset = function( options ) {
        var elem = this[ 0 ];
        if ( !elem || !elem.ownerDocument ) { return null; }
        if ( options ) {
            return this.each(function() {
                $.offset.setOffset( this, options );
            });
        }
        return _offset.call( this );
    };
}

}( jQuery ));
/*
 * jQuery UI Progressbar 1.8.16
 *
 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * http://docs.jquery.com/UI/Progressbar
 *
 * Depends:
 *   jquery.ui.core.js
 *   jquery.ui.widget.js
 */
(function( $, undefined ) {

$.widget( "ui.progressbar", {
    options: {
        value: 0,
        max: 100
    },

    min: 0,

    _create: function() {
        this.element
            .addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
            .attr({
                role: "progressbar",
                "aria-valuemin": this.min,
                "aria-valuemax": this.options.max,
                "aria-valuenow": this._value()
            });

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

        this.oldValue = this._value();
        this._refreshValue();
    },

    destroy: function() {
        this.element
            .removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
            .removeAttr( "role" )
            .removeAttr( "aria-valuemin" )
            .removeAttr( "aria-valuemax" )
            .removeAttr( "aria-valuenow" );

        this.valueDiv.remove();

        $.Widget.prototype.destroy.apply( this, arguments );
    },

    value: function( newValue ) {
        if ( newValue === undefined ) {
            return this._value();
        }

        this._setOption( "value", newValue );
        return this;
    },

    _setOption: function( key, value ) {
        if ( key === "value" ) {
            this.options.value = value;
            this._refreshValue();
            if ( this._value() === this.options.max ) {
                this._trigger( "complete" );
            }
        }

        $.Widget.prototype._setOption.apply( this, arguments );
    },

    _value: function() {
        var val = this.options.value;
        // normalize invalid value
        if ( typeof val !== "number" ) {
            val = 0;
        }
        return Math.min( this.options.max, Math.max( this.min, val ) );
    },

    _percentage: function() {
        return 100 * this._value() / this.options.max;
    },

    _refreshValue: function() {
        var value = this.value();
        var percentage = this._percentage();

        if ( this.oldValue !== value ) {
            this.oldValue = value;
            this._trigger( "change" );
        }

        this.valueDiv
            .toggle( value > this.min )
            .toggleClass( "ui-corner-right", value === this.options.max )
            .width( percentage.toFixed(0) + "%" );
        this.element.attr( "aria-valuenow", value );
    }
});

$.extend( $.ui.progressbar, {
    version: "1.8.16"
});

})( jQuery );
/*
 * jQuery UI Slider 1.8.16
 *
 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * http://docs.jquery.com/UI/Slider
 *
 * Depends:
 *    jquery.ui.core.js
 *    jquery.ui.mouse.js
 *    jquery.ui.widget.js
 */
(function( $, undefined ) {

// number of pages in a slider
// (how many times can you page up/down to go through the whole range)
var numPages = 5;

$.widget( "ui.slider", $.ui.mouse, {

    widgetEventPrefix: "slide",

    options: {
        animate: false,
        distance: 0,
        max: 100,
        min: 0,
        orientation: "horizontal",
        range: false,
        step: 1,
        value: 0,
        values: null
    },

    _create: function() {
        var self = this,
            o = this.options,
            existingHandles = this.element.find( ".ui-slider-handle" ).addClass( "ui-state-default ui-corner-all" ),
            handle = "<a class='ui-slider-handle ui-state-default ui-corner-all' href='#'></a>",
            handleCount = ( o.values && o.values.length ) || 1,
            handles = [];

        this._keySliding = false;
        this._mouseSliding = false;
        this._animateOff = true;
        this._handleIndex = null;
        this._detectOrientation();
        this._mouseInit();

        this.element
            .addClass( "ui-slider" +
                " ui-slider-" + this.orientation +
                " ui-widget" +
                " ui-widget-content" +
                " ui-corner-all" +
                ( o.disabled ? " ui-slider-disabled ui-disabled" : "" ) );

        this.range = $([]);

        if ( o.range ) {
            if ( o.range === true ) {
                if ( !o.values ) {
                    o.values = [ this._valueMin(), this._valueMin() ];
                }
                if ( o.values.length && o.values.length !== 2 ) {
                    o.values = [ o.values[0], o.values[0] ];
                }
            }

            this.range = $( "<div></div>" )
                .appendTo( this.element )
                .addClass( "ui-slider-range" +
                // note: this isn't the most fittingly semantic framework class for this element,
                // but worked best visually with a variety of themes
                " ui-widget-header" +
                ( ( o.range === "min" || o.range === "max" ) ? " ui-slider-range-" + o.range : "" ) );
        }

        for ( var i = existingHandles.length; i < handleCount; i += 1 ) {
            handles.push( handle );
        }

        this.handles = existingHandles.add( $( handles.join( "" ) ).appendTo( self.element ) );

        this.handle = this.handles.eq( 0 );

        this.handles.add( this.range ).filter( "a" )
            .click(function( event ) {
                event.preventDefault();
            })
            .hover(function() {
                if ( !o.disabled ) {
                    $( this ).addClass( "ui-state-hover" );
                }
            }, function() {
                $( this ).removeClass( "ui-state-hover" );
            })
            .focus(function() {
                if ( !o.disabled ) {
                    $( ".ui-slider .ui-state-focus" ).removeClass( "ui-state-focus" );
                    $( this ).addClass( "ui-state-focus" );
                } else {
                    $( this ).blur();
                }
            })
            .blur(function() {
                $( this ).removeClass( "ui-state-focus" );
            });

        this.handles.each(function( i ) {
            $( this ).data( "index.ui-slider-handle", i );
        });

        this.handles
            .keydown(function( event ) {
                var ret = true,
                    index = $( this ).data( "index.ui-slider-handle" ),
                    allowed,
                    curVal,
                    newVal,
                    step;
  
                if ( self.options.disabled ) {
                    return;
                }
  
                switch ( event.keyCode ) {
                    case $.ui.keyCode.HOME:
                    case $.ui.keyCode.END:
                    case $.ui.keyCode.PAGE_UP:
                    case $.ui.keyCode.PAGE_DOWN:
                    case $.ui.keyCode.UP:
                    case $.ui.keyCode.RIGHT:
                    case $.ui.keyCode.DOWN:
                    case $.ui.keyCode.LEFT:
                        ret = false;
                        if ( !self._keySliding ) {
                            self._keySliding = true;
                            $( this ).addClass( "ui-state-active" );
                            allowed = self._start( event, index );
                            if ( allowed === false ) {
                                return;
                            }
                        }
                        break;
                }
  
                step = self.options.step;
                if ( self.options.values && self.options.values.length ) {
                    curVal = newVal = self.values( index );
                } else {
                    curVal = newVal = self.value();
                }
  
                switch ( event.keyCode ) {
                    case $.ui.keyCode.HOME:
                        newVal = self._valueMin();
                        break;
                    case $.ui.keyCode.END:
                        newVal = self._valueMax();
                        break;
                    case $.ui.keyCode.PAGE_UP:
                        newVal = self._trimAlignValue( curVal + ( (self._valueMax() - self._valueMin()) / numPages ) );
                        break;
                    case $.ui.keyCode.PAGE_DOWN:
                        newVal = self._trimAlignValue( curVal - ( (self._valueMax() - self._valueMin()) / numPages ) );
                        break;
                    case $.ui.keyCode.UP:
                    case $.ui.keyCode.RIGHT:
                        if ( curVal === self._valueMax() ) {
                            return;
                        }
                        newVal = self._trimAlignValue( curVal + step );
                        break;
                    case $.ui.keyCode.DOWN:
                    case $.ui.keyCode.LEFT:
                        if ( curVal === self._valueMin() ) {
                            return;
                        }
                        newVal = self._trimAlignValue( curVal - step );
                        break;
                }
  
                self._slide( event, index, newVal );
  
                return ret;
  
            })
            .keyup(function( event ) {
                var index = $( this ).data( "index.ui-slider-handle" );
  
                if ( self._keySliding ) {
                    self._keySliding = false;
                    self._stop( event, index );
                    self._change( event, index );
                    $( this ).removeClass( "ui-state-active" );
                }
  
            });

        this._refreshValue();

        this._animateOff = false;
    },

    destroy: function() {
        this.handles.remove();
        this.range.remove();

        this.element
            .removeClass( "ui-slider" +
                " ui-slider-horizontal" +
                " ui-slider-vertical" +
                " ui-slider-disabled" +
                " ui-widget" +
                " ui-widget-content" +
                " ui-corner-all" )
            .removeData( "slider" )
            .unbind( ".slider" );

        this._mouseDestroy();

        return this;
    },

    _mouseCapture: function( event ) {
        var o = this.options,
            position,
            normValue,
            distance,
            closestHandle,
            self,
            index,
            allowed,
            offset,
            mouseOverHandle;

        if ( o.disabled ) {
            return false;
        }

        this.elementSize = {
            width: this.element.outerWidth(),
            height: this.element.outerHeight()
        };
        this.elementOffset = this.element.offset();

        position = { x: event.pageX, y: event.pageY };
        normValue = this._normValueFromMouse( position );
        distance = this._valueMax() - this._valueMin() + 1;
        self = this;
        this.handles.each(function( i ) {
            var thisDistance = Math.abs( normValue - self.values(i) );
            if ( distance > thisDistance ) {
                distance = thisDistance;
                closestHandle = $( this );
                index = i;
            }
        });

        // workaround for bug #3736 (if both handles of a range are at 0,
        // the first is always used as the one with least distance,
        // and moving it is obviously prevented by preventing negative ranges)
        if( o.range === true && this.values(1) === o.min ) {
            index += 1;
            closestHandle = $( this.handles[index] );
        }

        allowed = this._start( event, index );
        if ( allowed === false ) {
            return false;
        }
        this._mouseSliding = true;

        self._handleIndex = index;

        closestHandle
            .addClass( "ui-state-active" )
            .focus();
      
        offset = closestHandle.offset();
        mouseOverHandle = !$( event.target ).parents().andSelf().is( ".ui-slider-handle" );
        this._clickOffset = mouseOverHandle ? { left: 0, top: 0 } : {
            left: event.pageX - offset.left - ( closestHandle.width() / 2 ),
            top: event.pageY - offset.top -
                ( closestHandle.height() / 2 ) -
                ( parseInt( closestHandle.css("borderTopWidth"), 10 ) || 0 ) -
                ( parseInt( closestHandle.css("borderBottomWidth"), 10 ) || 0) +
                ( parseInt( closestHandle.css("marginTop"), 10 ) || 0)
        };

        if ( !this.handles.hasClass( "ui-state-hover" ) ) {
            this._slide( event, index, normValue );
        }
        this._animateOff = true;
        return true;
    },

    _mouseStart: function( event ) {
        return true;
    },

    _mouseDrag: function( event ) {
        var position = { x: event.pageX, y: event.pageY },
            normValue = this._normValueFromMouse( position );
      
        this._slide( event, this._handleIndex, normValue );

        return false;
    },

    _mouseStop: function( event ) {
        this.handles.removeClass( "ui-state-active" );
        this._mouseSliding = false;

        this._stop( event, this._handleIndex );
        this._change( event, this._handleIndex );

        this._handleIndex = null;
        this._clickOffset = null;
        this._animateOff = false;

        return false;
    },
  
    _detectOrientation: function() {
        this.orientation = ( this.options.orientation === "vertical" ) ? "vertical" : "horizontal";
    },

    _normValueFromMouse: function( position ) {
        var pixelTotal,
            pixelMouse,
            percentMouse,
            valueTotal,
            valueMouse;

        if ( this.orientation === "horizontal" ) {
            pixelTotal = this.elementSize.width;
            pixelMouse = position.x - this.elementOffset.left - ( this._clickOffset ? this._clickOffset.left : 0 );
        } else {
            pixelTotal = this.elementSize.height;
            pixelMouse = position.y - this.elementOffset.top - ( this._clickOffset ? this._clickOffset.top : 0 );
        }

        percentMouse = ( pixelMouse / pixelTotal );
        if ( percentMouse > 1 ) {
            percentMouse = 1;
        }
        if ( percentMouse < 0 ) {
            percentMouse = 0;
        }
        if ( this.orientation === "vertical" ) {
            percentMouse = 1 - percentMouse;
        }

        valueTotal = this._valueMax() - this._valueMin();
        valueMouse = this._valueMin() + percentMouse * valueTotal;

        return this._trimAlignValue( valueMouse );
    },

    _start: function( event, index ) {
        var uiHash = {
            handle: this.handles[ index ],
            value: this.value()
        };
        if ( this.options.values && this.options.values.length ) {
            uiHash.value = this.values( index );
            uiHash.values = this.values();
        }
        return this._trigger( "start", event, uiHash );
    },

    _slide: function( event, index, newVal ) {
        var otherVal,
            newValues,
            allowed;

        if ( this.options.values && this.options.values.length ) {
            otherVal = this.values( index ? 0 : 1 );

            if ( ( this.options.values.length === 2 && this.options.range === true ) &&
                    ( ( index === 0 && newVal > otherVal) || ( index === 1 && newVal < otherVal ) )
                ) {
                newVal = otherVal;
            }

            if ( newVal !== this.values( index ) ) {
                newValues = this.values();
                newValues[ index ] = newVal;
                // A slide can be canceled by returning false from the slide callback
                allowed = this._trigger( "slide", event, {
                    handle: this.handles[ index ],
                    value: newVal,
                    values: newValues
                } );
                otherVal = this.values( index ? 0 : 1 );
                if ( allowed !== false ) {
                    this.values( index, newVal, true );
                }
            }
        } else {
            if ( newVal !== this.value() ) {
                // A slide can be canceled by returning false from the slide callback
                allowed = this._trigger( "slide", event, {
                    handle: this.handles[ index ],
                    value: newVal
                } );
                if ( allowed !== false ) {
                    this.value( newVal );
                }
            }
        }
    },

    _stop: function( event, index ) {
        var uiHash = {
            handle: this.handles[ index ],
            value: this.value()
        };
        if ( this.options.values && this.options.values.length ) {
            uiHash.value = this.values( index );
            uiHash.values = this.values();
        }

        this._trigger( "stop", event, uiHash );
    },

    _change: function( event, index ) {
        if ( !this._keySliding && !this._mouseSliding ) {
            var uiHash = {
                handle: this.handles[ index ],
                value: this.value()
            };
            if ( this.options.values && this.options.values.length ) {
                uiHash.value = this.values( index );
                uiHash.values = this.values();
            }

            this._trigger( "change", event, uiHash );
        }
    },

    value: function( newValue ) {
        if ( arguments.length ) {
            this.options.value = this._trimAlignValue( newValue );
            this._refreshValue();
            this._change( null, 0 );
            return;
        }

        return this._value();
    },

    values: function( index, newValue ) {
        var vals,
            newValues,
            i;

        if ( arguments.length > 1 ) {
            this.options.values[ index ] = this._trimAlignValue( newValue );
            this._refreshValue();
            this._change( null, index );
            return;
        }

        if ( arguments.length ) {
            if ( $.isArray( arguments[ 0 ] ) ) {
                vals = this.options.values;
                newValues = arguments[ 0 ];
                for ( i = 0; i < vals.length; i += 1 ) {
                    vals[ i ] = this._trimAlignValue( newValues[ i ] );
                    this._change( null, i );
                }
                this._refreshValue();
            } else {
                if ( this.options.values && this.options.values.length ) {
                    return this._values( index );
                } else {
                    return this.value();
                }
            }
        } else {
            return this._values();
        }
    },

    _setOption: function( key, value ) {
        var i,
            valsLength = 0;

        if ( $.isArray( this.options.values ) ) {
            valsLength = this.options.values.length;
        }

        $.Widget.prototype._setOption.apply( this, arguments );

        switch ( key ) {
            case "disabled":
                if ( value ) {
                    this.handles.filter( ".ui-state-focus" ).blur();
                    this.handles.removeClass( "ui-state-hover" );
                    this.handles.propAttr( "disabled", true );
                    this.element.addClass( "ui-disabled" );
                } else {
                    this.handles.propAttr( "disabled", false );
                    this.element.removeClass( "ui-disabled" );
                }
                break;
            case "orientation":
                this._detectOrientation();
                this.element
                    .removeClass( "ui-slider-horizontal ui-slider-vertical" )
                    .addClass( "ui-slider-" + this.orientation );
                this._refreshValue();
                break;
            case "value":
                this._animateOff = true;
                this._refreshValue();
                this._change( null, 0 );
                this._animateOff = false;
                break;
            case "values":
                this._animateOff = true;
                this._refreshValue();
                for ( i = 0; i < valsLength; i += 1 ) {
                    this._change( null, i );
                }
                this._animateOff = false;
                break;
        }
    },

    //internal value getter
    // _value() returns value trimmed by min and max, aligned by step
    _value: function() {
        var val = this.options.value;
        val = this._trimAlignValue( val );

        return val;
    },

    //internal values getter
    // _values() returns array of values trimmed by min and max, aligned by step
    // _values( index ) returns single value trimmed by min and max, aligned by step
    _values: function( index ) {
        var val,
            vals,
            i;

        if ( arguments.length ) {
            val = this.options.values[ index ];
            val = this._trimAlignValue( val );

            return val;
        } else {
            // .slice() creates a copy of the array
            // this copy gets trimmed by min and max and then returned
            vals = this.options.values.slice();
            for ( i = 0; i < vals.length; i+= 1) {
                vals[ i ] = this._trimAlignValue( vals[ i ] );
            }

            return vals;
        }
    },
  
    // returns the step-aligned value that val is closest to, between (inclusive) min and max
    _trimAlignValue: function( val ) {
        if ( val <= this._valueMin() ) {
            return this._valueMin();
        }
        if ( val >= this._valueMax() ) {
            return this._valueMax();
        }
        var step = ( this.options.step > 0 ) ? this.options.step : 1,
            valModStep = (val - this._valueMin()) % step,
            alignValue = val - valModStep;

        if ( Math.abs(valModStep) * 2 >= step ) {
            alignValue += ( valModStep > 0 ) ? step : ( -step );
        }

        // Since JavaScript has problems with large floats, round
        // the final value to 5 digits after the decimal point (see #4124)
        return parseFloat( alignValue.toFixed(5) );
    },

    _valueMin: function() {
        return this.options.min;
    },

    _valueMax: function() {
        return this.options.max;
    },
  
    _refreshValue: function() {
        var oRange = this.options.range,
            o = this.options,
            self = this,
            animate = ( !this._animateOff ) ? o.animate : false,
            valPercent,
            _set = {},
            lastValPercent,
            value,
            valueMin,
            valueMax;

        if ( this.options.values && this.options.values.length ) {
            this.handles.each(function( i, j ) {
                valPercent = ( self.values(i) - self._valueMin() ) / ( self._valueMax() - self._valueMin() ) * 100;
                _set[ self.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
                $( this ).stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
                if ( self.options.range === true ) {
                    if ( self.orientation === "horizontal" ) {
                        if ( i === 0 ) {
                            self.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { left: valPercent + "%" }, o.animate );
                        }
                        if ( i === 1 ) {
                            self.range[ animate ? "animate" : "css" ]( { width: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
                        }
                    } else {
                        if ( i === 0 ) {
                            self.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { bottom: ( valPercent ) + "%" }, o.animate );
                        }
                        if ( i === 1 ) {
                            self.range[ animate ? "animate" : "css" ]( { height: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
                        }
                    }
                }
                lastValPercent = valPercent;
            });
        } else {
            value = this.value();
            valueMin = this._valueMin();
            valueMax = this._valueMax();
            valPercent = ( valueMax !== valueMin ) ?
                    ( value - valueMin ) / ( valueMax - valueMin ) * 100 :
                    0;
            _set[ self.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
            this.handle.stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );

            if ( oRange === "min" && this.orientation === "horizontal" ) {
                this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { width: valPercent + "%" }, o.animate );
            }
            if ( oRange === "max" && this.orientation === "horizontal" ) {
                this.range[ animate ? "animate" : "css" ]( { width: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
            }
            if ( oRange === "min" && this.orientation === "vertical" ) {
                this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { height: valPercent + "%" }, o.animate );
            }
            if ( oRange === "max" && this.orientation === "vertical" ) {
                this.range[ animate ? "animate" : "css" ]( { height: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
            }
        }
    }

});

$.extend( $.ui.slider, {
    version: "1.8.16"
});

}(jQuery));
/*
 * jQuery UI Tabs 1.8.16
 *
 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * http://docs.jquery.com/UI/Tabs
 *
 * Depends:
 *    jquery.ui.core.js
 *    jquery.ui.widget.js
 */
(function( $, undefined ) {

var tabId = 0,
    listId = 0;

function getNextTabId() {
    return ++tabId;
}

function getNextListId() {
    return ++listId;
}

$.widget( "ui.tabs", {
    options: {
        add: null,
        ajaxOptions: null,
        cache: false,
        cookie: null, // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
        collapsible: false,
        disable: null,
        disabled: [],
        enable: null,
        event: "click",
        fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 }
        idPrefix: "ui-tabs-",
        load: null,
        panelTemplate: "<div></div>",
        remove: null,
        select: null,
        show: null,
        spinner: "<em>Loading&#8230;</em>",
        tabTemplate: "<li><a href='#{href}'><span>#{label}</span></a></li>"
    },

    _create: function() {
        this._tabify( true );
    },

    _setOption: function( key, value ) {
        if ( key == "selected" ) {
            if (this.options.collapsible && value == this.options.selected ) {
                return;
            }
            this.select( value );
        } else {
            this.options[ key ] = value;
            this._tabify();
        }
    },

    _tabId: function( a ) {
        return a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF-]/g, "" ) ||
            this.options.idPrefix + getNextTabId();
    },

    _sanitizeSelector: function( hash ) {
        // we need this because an id may contain a ":"
        return hash.replace( /:/g, "\\:" );
    },

    _cookie: function() {
        var cookie = this.cookie ||
            ( this.cookie = this.options.cookie.name || "ui-tabs-" + getNextListId() );
        return $.cookie.apply( null, [ cookie ].concat( $.makeArray( arguments ) ) );
    },

    _ui: function( tab, panel ) {
        return {
            tab: tab,
            panel: panel,
            index: this.anchors.index( tab )
        };
    },

    _cleanup: function() {
        // restore all former loading tabs labels
        this.lis.filter( ".ui-state-processing" )
            .removeClass( "ui-state-processing" )
            .find( "span:data(label.tabs)" )
                .each(function() {
                    var el = $( this );
                    el.html( el.data( "label.tabs" ) ).removeData( "label.tabs" );
                });
    },

    _tabify: function( init ) {
        var self = this,
            o = this.options,
            fragmentId = /^#.+/; // Safari 2 reports '#' for an empty hash

        this.list = this.element.find( "ol,ul" ).eq( 0 );
        this.lis = $( " > li:has(a[href])", this.list );
        this.anchors = this.lis.map(function() {
            return $( "a", this )[ 0 ];
        });
        this.panels = $( [] );

        this.anchors.each(function( i, a ) {
            var href = $( a ).attr( "href" );
            // For dynamically created HTML that contains a hash as href IE < 8 expands
            // such href to the full page url with hash and then misinterprets tab as ajax.
            // Same consideration applies for an added tab with a fragment identifier
            // since a[href=#fragment-identifier] does unexpectedly not match.
            // Thus normalize href attribute...
            var hrefBase = href.split( "#" )[ 0 ],
                baseEl;
            if ( hrefBase && ( hrefBase === location.toString().split( "#" )[ 0 ] ||
                    ( baseEl = $( "base" )[ 0 ]) && hrefBase === baseEl.href ) ) {
                href = a.hash;
                a.href = href;
            }

            // inline tab
            if ( fragmentId.test( href ) ) {
                self.panels = self.panels.add( self.element.find( self._sanitizeSelector( href ) ) );
            // remote tab
            // prevent loading the page itself if href is just "#"
            } else if ( href && href !== "#" ) {
                // required for restore on destroy
                $.data( a, "href.tabs", href );

                // TODO until #3808 is fixed strip fragment identifier from url
                // (IE fails to load from such url)
                $.data( a, "load.tabs", href.replace( /#.*$/, "" ) );

                var id = self._tabId( a );
                a.href = "#" + id;
                var $panel = self.element.find( "#" + id );
                if ( !$panel.length ) {
                    $panel = $( o.panelTemplate )
                        .attr( "id", id )
                        .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
                        .insertAfter( self.panels[ i - 1 ] || self.list );
                    $panel.data( "destroy.tabs", true );
                }
                self.panels = self.panels.add( $panel );
            // invalid tab href
            } else {
                o.disabled.push( i );
            }
        });

        // initialization from scratch
        if ( init ) {
            // attach necessary classes for styling
            this.element.addClass( "ui-tabs ui-widget ui-widget-content ui-corner-all" );
            this.list.addClass( "ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" );
            this.lis.addClass( "ui-state-default ui-corner-top" );
            this.panels.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" );

            // Selected tab
            // use "selected" option or try to retrieve:
            // 1. from fragment identifier in url
            // 2. from cookie
            // 3. from selected class attribute on <li>
            if ( o.selected === undefined ) {
                if ( location.hash ) {
                    this.anchors.each(function( i, a ) {
                        if ( a.hash == location.hash ) {
                            o.selected = i;
                            return false;
                        }
                    });
                }
                if ( typeof o.selected !== "number" && o.cookie ) {
                    o.selected = parseInt( self._cookie(), 10 );
                }
                if ( typeof o.selected !== "number" && this.lis.filter( ".ui-tabs-selected" ).length ) {
                    o.selected = this.lis.index( this.lis.filter( ".ui-tabs-selected" ) );
                }
                o.selected = o.selected || ( this.lis.length ? 0 : -1 );
            } else if ( o.selected === null ) { // usage of null is deprecated, TODO remove in next release
                o.selected = -1;
            }

            // sanity check - default to first tab...
            o.selected = ( ( o.selected >= 0 && this.anchors[ o.selected ] ) || o.selected < 0 )
                ? o.selected
                : 0;

            // Take disabling tabs via class attribute from HTML
            // into account and update option properly.
            // A selected tab cannot become disabled.
            o.disabled = $.unique( o.disabled.concat(
                $.map( this.lis.filter( ".ui-state-disabled" ), function( n, i ) {
                    return self.lis.index( n );
                })
            ) ).sort();

            if ( $.inArray( o.selected, o.disabled ) != -1 ) {
                o.disabled.splice( $.inArray( o.selected, o.disabled ), 1 );
            }

            // highlight selected tab
            this.panels.addClass( "ui-tabs-hide" );
            this.lis.removeClass( "ui-tabs-selected ui-state-active" );
            // check for length avoids error when initializing empty list
            if ( o.selected >= 0 && this.anchors.length ) {
                self.element.find( self._sanitizeSelector( self.anchors[ o.selected ].hash ) ).removeClass( "ui-tabs-hide" );
                this.lis.eq( o.selected ).addClass( "ui-tabs-selected ui-state-active" );

                // seems to be expected behavior that the show callback is fired
                self.element.queue( "tabs", function() {
                    self._trigger( "show", null,
                        self._ui( self.anchors[ o.selected ], self.element.find( self._sanitizeSelector( self.anchors[ o.selected ].hash ) )[ 0 ] ) );
                });

                this.load( o.selected );
            }

            // clean up to avoid memory leaks in certain versions of IE 6
            // TODO: namespace this event
            $( window ).bind( "unload", function() {
                self.lis.add( self.anchors ).unbind( ".tabs" );
                self.lis = self.anchors = self.panels = null;
            });
        // update selected after add/remove
        } else {
            o.selected = this.lis.index( this.lis.filter( ".ui-tabs-selected" ) );
        }

        // update collapsible
        // TODO: use .toggleClass()
        this.element[ o.collapsible ? "addClass" : "removeClass" ]( "ui-tabs-collapsible" );

        // set or update cookie after init and add/remove respectively
        if ( o.cookie ) {
            this._cookie( o.selected, o.cookie );
        }

        // disable tabs
        for ( var i = 0, li; ( li = this.lis[ i ] ); i++ ) {
            $( li )[ $.inArray( i, o.disabled ) != -1 &&
                // TODO: use .toggleClass()
                !$( li ).hasClass( "ui-tabs-selected" ) ? "addClass" : "removeClass" ]( "ui-state-disabled" );
        }

        // reset cache if switching from cached to not cached
        if ( o.cache === false ) {
            this.anchors.removeData( "cache.tabs" );
        }

        // remove all handlers before, tabify may run on existing tabs after add or option change
        this.lis.add( this.anchors ).unbind( ".tabs" );

        if ( o.event !== "mouseover" ) {
            var addState = function( state, el ) {
                if ( el.is( ":not(.ui-state-disabled)" ) ) {
                    el.addClass( "ui-state-" + state );
                }
            };
            var removeState = function( state, el ) {
                el.removeClass( "ui-state-" + state );
            };
            this.lis.bind( "mouseover.tabs" , function() {
                addState( "hover", $( this ) );
            });
            this.lis.bind( "mouseout.tabs", function() {
                removeState( "hover", $( this ) );
            });
            this.anchors.bind( "focus.tabs", function() {
                addState( "focus", $( this ).closest( "li" ) );
            });
            this.anchors.bind( "blur.tabs", function() {
                removeState( "focus", $( this ).closest( "li" ) );
            });
        }

        // set up animations
        var hideFx, showFx;
        if ( o.fx ) {
            if ( $.isArray( o.fx ) ) {
                hideFx = o.fx[ 0 ];
                showFx = o.fx[ 1 ];
            } else {
                hideFx = showFx = o.fx;
            }
        }

        // Reset certain styles left over from animation
        // and prevent IE's ClearType bug...
        function resetStyle( $el, fx ) {
            $el.css( "display", "" );
            if ( !$.support.opacity && fx.opacity ) {
                $el[ 0 ].style.removeAttribute( "filter" );
            }
        }

        // Show a tab...
        var showTab = showFx
            ? function( clicked, $show ) {
                $( clicked ).closest( "li" ).addClass( "ui-tabs-selected ui-state-active" );
                $show.hide().removeClass( "ui-tabs-hide" ) // avoid flicker that way
                    .animate( showFx, showFx.duration || "normal", function() {
                        resetStyle( $show, showFx );
                        self._trigger( "show", null, self._ui( clicked, $show[ 0 ] ) );
                    });
            }
            : function( clicked, $show ) {
                $( clicked ).closest( "li" ).addClass( "ui-tabs-selected ui-state-active" );
                $show.removeClass( "ui-tabs-hide" );
                self._trigger( "show", null, self._ui( clicked, $show[ 0 ] ) );
            };

        // Hide a tab, $show is optional...
        var hideTab = hideFx
            ? function( clicked, $hide ) {
                $hide.animate( hideFx, hideFx.duration || "normal", function() {
                    self.lis.removeClass( "ui-tabs-selected ui-state-active" );
                    $hide.addClass( "ui-tabs-hide" );
                    resetStyle( $hide, hideFx );
                    self.element.dequeue( "tabs" );
                });
            }
            : function( clicked, $hide, $show ) {
                self.lis.removeClass( "ui-tabs-selected ui-state-active" );
                $hide.addClass( "ui-tabs-hide" );
                self.element.dequeue( "tabs" );
            };

        // attach tab event handler, unbind to avoid duplicates from former tabifying...
        this.anchors.bind( o.event + ".tabs", function() {
            var el = this,
                $li = $(el).closest( "li" ),
                $hide = self.panels.filter( ":not(.ui-tabs-hide)" ),
                $show = self.element.find( self._sanitizeSelector( el.hash ) );

            // If tab is already selected and not collapsible or tab disabled or
            // or is already loading or click callback returns false stop here.
            // Check if click handler returns false last so that it is not executed
            // for a disabled or loading tab!
            if ( ( $li.hasClass( "ui-tabs-selected" ) && !o.collapsible) ||
                $li.hasClass( "ui-state-disabled" ) ||
                $li.hasClass( "ui-state-processing" ) ||
                self.panels.filter( ":animated" ).length ||
                self._trigger( "select", null, self._ui( this, $show[ 0 ] ) ) === false ) {
                this.blur();
                return false;
            }

            o.selected = self.anchors.index( this );

            self.abort();

            // if tab may be closed
            if ( o.collapsible ) {
                if ( $li.hasClass( "ui-tabs-selected" ) ) {
                    o.selected = -1;

                    if ( o.cookie ) {
                        self._cookie( o.selected, o.cookie );
                    }

                    self.element.queue( "tabs", function() {
                        hideTab( el, $hide );
                    }).dequeue( "tabs" );

                    this.blur();
                    return false;
                } else if ( !$hide.length ) {
                    if ( o.cookie ) {
                        self._cookie( o.selected, o.cookie );
                    }

                    self.element.queue( "tabs", function() {
                        showTab( el, $show );
                    });

                    // TODO make passing in node possible, see also http://dev.jqueryui.com/ticket/3171
                    self.load( self.anchors.index( this ) );

                    this.blur();
                    return false;
                }
            }

            if ( o.cookie ) {
                self._cookie( o.selected, o.cookie );
            }

            // show new tab
            if ( $show.length ) {
                if ( $hide.length ) {
                    self.element.queue( "tabs", function() {
                        hideTab( el, $hide );
                    });
                }
                self.element.queue( "tabs", function() {
                    showTab( el, $show );
                });

                self.load( self.anchors.index( this ) );
            } else {
                throw "jQuery UI Tabs: Mismatching fragment identifier.";
            }

            // Prevent IE from keeping other link focussed when using the back button
            // and remove dotted border from clicked link. This is controlled via CSS
            // in modern browsers; blur() removes focus from address bar in Firefox
            // which can become a usability and annoying problem with tabs('rotate').
            if ( $.browser.msie ) {
                this.blur();
            }
        });

        // disable click in any case
        this.anchors.bind( "click.tabs", function(){
            return false;
        });
    },

    _getIndex: function( index ) {
        // meta-function to give users option to provide a href string instead of a numerical index.
        // also sanitizes numerical indexes to valid values.
        if ( typeof index == "string" ) {
            index = this.anchors.index( this.anchors.filter( "[href$=" + index + "]" ) );
        }

        return index;
    },

    destroy: function() {
        var o = this.options;

        this.abort();

        this.element
            .unbind( ".tabs" )
            .removeClass( "ui-tabs ui-widget ui-widget-content ui-corner-all ui-tabs-collapsible" )
            .removeData( "tabs" );

        this.list.removeClass( "ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" );

        this.anchors.each(function() {
            var href = $.data( this, "href.tabs" );
            if ( href ) {
                this.href = href;
            }
            var $this = $( this ).unbind( ".tabs" );
            $.each( [ "href", "load", "cache" ], function( i, prefix ) {
                $this.removeData( prefix + ".tabs" );
            });
        });

        this.lis.unbind( ".tabs" ).add( this.panels ).each(function() {
            if ( $.data( this, "destroy.tabs" ) ) {
                $( this ).remove();
            } else {
                $( this ).removeClass([
                    "ui-state-default",
                    "ui-corner-top",
                    "ui-tabs-selected",
                    "ui-state-active",
                    "ui-state-hover",
                    "ui-state-focus",
                    "ui-state-disabled",
                    "ui-tabs-panel",
                    "ui-widget-content",
                    "ui-corner-bottom",
                    "ui-tabs-hide"
                ].join( " " ) );
            }
        });

        if ( o.cookie ) {
            this._cookie( null, o.cookie );
        }

        return this;
    },

    add: function( url, label, index ) {
        if ( index === undefined ) {
            index = this.anchors.length;
        }

        var self = this,
            o = this.options,
            $li = $( o.tabTemplate.replace( /#\{href\}/g, url ).replace( /#\{label\}/g, label ) ),
            id = !url.indexOf( "#" ) ? url.replace( "#", "" ) : this._tabId( $( "a", $li )[ 0 ] );

        $li.addClass( "ui-state-default ui-corner-top" ).data( "destroy.tabs", true );

        // try to find an existing element before creating a new one
        var $panel = self.element.find( "#" + id );
        if ( !$panel.length ) {
            $panel = $( o.panelTemplate )
                .attr( "id", id )
                .data( "destroy.tabs", true );
        }
        $panel.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" );

        if ( index >= this.lis.length ) {
            $li.appendTo( this.list );
            $panel.appendTo( this.list[ 0 ].parentNode );
        } else {
            $li.insertBefore( this.lis[ index ] );
            $panel.insertBefore( this.panels[ index ] );
        }

        o.disabled = $.map( o.disabled, function( n, i ) {
            return n >= index ? ++n : n;
        });

        this._tabify();

        if ( this.anchors.length == 1 ) {
            o.selected = 0;
            $li.addClass( "ui-tabs-selected ui-state-active" );
            $panel.removeClass( "ui-tabs-hide" );
            this.element.queue( "tabs", function() {
                self._trigger( "show", null, self._ui( self.anchors[ 0 ], self.panels[ 0 ] ) );
            });

            this.load( 0 );
        }

        this._trigger( "add", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
        return this;
    },

    remove: function( index ) {
        index = this._getIndex( index );
        var o = this.options,
            $li = this.lis.eq( index ).remove(),
            $panel = this.panels.eq( index ).remove();

        // If selected tab was removed focus tab to the right or
        // in case the last tab was removed the tab to the left.
        if ( $li.hasClass( "ui-tabs-selected" ) && this.anchors.length > 1) {
            this.select( index + ( index + 1 < this.anchors.length ? 1 : -1 ) );
        }

        o.disabled = $.map(
            $.grep( o.disabled, function(n, i) {
                return n != index;
            }),
            function( n, i ) {
                return n >= index ? --n : n;
            });

        this._tabify();

        this._trigger( "remove", null, this._ui( $li.find( "a" )[ 0 ], $panel[ 0 ] ) );
        return this;
    },

    enable: function( index ) {
        index = this._getIndex( index );
        var o = this.options;
        if ( $.inArray( index, o.disabled ) == -1 ) {
            return;
        }

        this.lis.eq( index ).removeClass( "ui-state-disabled" );
        o.disabled = $.grep( o.disabled, function( n, i ) {
            return n != index;
        });

        this._trigger( "enable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
        return this;
    },

    disable: function( index ) {
        index = this._getIndex( index );
        var self = this, o = this.options;
        // cannot disable already selected tab
        if ( index != o.selected ) {
            this.lis.eq( index ).addClass( "ui-state-disabled" );

            o.disabled.push( index );
            o.disabled.sort();

            this._trigger( "disable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
        }

        return this;
    },

    select: function( index ) {
        index = this._getIndex( index );
        if ( index == -1 ) {
            if ( this.options.collapsible && this.options.selected != -1 ) {
                index = this.options.selected;
            } else {
                return this;
            }
        }
        this.anchors.eq( index ).trigger( this.options.event + ".tabs" );
        return this;
    },

    load: function( index ) {
        index = this._getIndex( index );
        var self = this,
            o = this.options,
            a = this.anchors.eq( index )[ 0 ],
            url = $.data( a, "load.tabs" );

        this.abort();

        // not remote or from cache
        if ( !url || this.element.queue( "tabs" ).length !== 0 && $.data( a, "cache.tabs" ) ) {
            this.element.dequeue( "tabs" );
            return;
        }

        // load remote from here on
        this.lis.eq( index ).addClass( "ui-state-processing" );

        if ( o.spinner ) {
            var span = $( "span", a );
            span.data( "label.tabs", span.html() ).html( o.spinner );
        }

        this.xhr = $.ajax( $.extend( {}, o.ajaxOptions, {
            url: url,
            success: function( r, s ) {
                self.element.find( self._sanitizeSelector( a.hash ) ).html( r );

                // take care of tab labels
                self._cleanup();

                if ( o.cache ) {
                    $.data( a, "cache.tabs", true );
                }

                self._trigger( "load", null, self._ui( self.anchors[ index ], self.panels[ index ] ) );
                try {
                    o.ajaxOptions.success( r, s );
                }
                catch ( e ) {}
            },
            error: function( xhr, s, e ) {
                // take care of tab labels
                self._cleanup();

                self._trigger( "load", null, self._ui( self.anchors[ index ], self.panels[ index ] ) );
                try {
                    // Passing index avoid a race condition when this method is
                    // called after the user has selected another tab.
                    // Pass the anchor that initiated this request allows
                    // loadError to manipulate the tab content panel via $(a.hash)
                    o.ajaxOptions.error( xhr, s, index, a );
                }
                catch ( e ) {}
            }
        } ) );

        // last, so that load event is fired before show...
        self.element.dequeue( "tabs" );

        return this;
    },

    abort: function() {
        // stop possibly running animations
        this.element.queue( [] );
        this.panels.stop( false, true );

        // "tabs" queue must not contain more than two elements,
        // which are the callbacks for the latest clicked tab...
        this.element.queue( "tabs", this.element.queue( "tabs" ).splice( -2, 2 ) );

        // terminate pending requests from other tabs
        if ( this.xhr ) {
            this.xhr.abort();
            delete this.xhr;
        }

        // take care of tab labels
        this._cleanup();
        return this;
    },

    url: function( index, url ) {
        this.anchors.eq( index ).removeData( "cache.tabs" ).data( "load.tabs", url );
        return this;
    },

    length: function() {
        return this.anchors.length;
    }
});

$.extend( $.ui.tabs, {
    version: "1.8.16"
});

/*
 * Tabs Extensions
 */

/*
 * Rotate
 */
$.extend( $.ui.tabs.prototype, {
    rotation: null,
    rotate: function( ms, continuing ) {
        var self = this,
            o = this.options;

        var rotate = self._rotate || ( self._rotate = function( e ) {
            clearTimeout( self.rotation );
            self.rotation = setTimeout(function() {
                var t = o.selected;
                self.select( ++t < self.anchors.length ? t : 0 );
            }, ms );
          
            if ( e ) {
                e.stopPropagation();
            }
        });

        var stop = self._unrotate || ( self._unrotate = !continuing
            ? function(e) {
                if (e.clientX) { // in case of a true click
                    self.rotate(null);
                }
            }
            : function( e ) {
                t = o.selected;
                rotate();
            });

        // start rotation
        if ( ms ) {
            this.element.bind( "tabsshow", rotate );
            this.anchors.bind( o.event + ".tabs", stop );
            rotate();
        // stop rotation
        } else {
            clearTimeout( self.rotation );
            this.element.unbind( "tabsshow", rotate );
            this.anchors.unbind( o.event + ".tabs", stop );
            delete this._rotate;
            delete this._unrotate;
        }

        return this;
    }
});

})( jQuery );