/*
 * jQuery UI Optionpicker 1.7.2
 *
 * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Optionpicker
 *
 * Depends:
 *	ui.core.js
 */

(function($) { // hide the namespace

    $.extend($.ui, { optionpicker: { version: "1.7.2"} });

    var PROP_NAME = 'optionpicker';

    /* Date picker manager.
    Use the singleton instance of this class, $.optionpicker, to interact with the option picker.
    Settings for (groups of) option pickers are maintained in an instance object,
    allowing multiple different settings on the same page. */

    function Optionpicker() {
        this.debug = false; // Change this to true to start debugging
        this._curInst = null; // The current instance in use
        this._keyEvent = false; // If the last event was a key event
        this._disabledInputs = []; // List of option picker inputs that have been disabled
        this._optionpickerShowing = false; // True if the popup picker is showing , false if not
        this._inDialog = false; // True if showing within a "dialog", false if not
        this._mainDivId = 'ui-optionpicker-div'; // The ID of the main optionpicker division
        this._inlineClass = 'ui-optionpicker-inline'; // The name of the inline marker class
        this._appendClass = 'ui-optionpicker-append'; // The name of the append marker class
        this._triggerClass = 'ui-optionpicker-trigger'; // The name of the trigger marker class
        this._dialogClass = 'ui-optionpicker-dialog'; // The name of the dialog marker class
        this._disableClass = 'ui-optionpicker-disabled'; // The name of the disabled covering marker class
        this._unselectableClass = 'ui-optionpicker-unselectable'; // The name of the unselectable cell marker class
        this._currentClass = 'ui-optionpicker-current-day'; // The name of the current day marker class
        this._dayOverClass = 'ui-optionpicker-days-cell-over'; // The name of the day hover marker class
        this.regional = []; // Available regional settings, indexed by language code
        this.regional[''] = { // Default regional settings
            optionItems: ['Default 1', 'Default 2', 'Default 3'] // For formatting
        };
        this._defaults = { // Global defaults for all the option picker instances
            showOn: 'focus', // 'focus' for popup on focus,
            showAnim: 'show', // Name of jQuery animation for popup
            showOptions: {}, // Options for enhanced animations
            appendText: '', // Display text following the input box, e.g. showing the format
            duration: 'normal', // Duration of display/closure
            beforeShow: null, // Function that takes an input field and
            onSelect: null, // Define a callback function when a option is selected
            onClose: null // Define a callback function when the optionpicker is closed
        };
        $.extend(this._defaults, this.regional['']);
        this.dpDiv = $('<div id="' + this._mainDivId + '" class="ui-optionpicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all ui-helper-hidden-accessible"></div>');
    }

    $.extend(Optionpicker.prototype, {
        /* Class name added to elements to indicate already configured with a option picker. */
        markerClassName: 'hasOptionpicker',

        /* Debug logging (if enabled). */
        log: function() {
            if (this.debug)
                console.log.apply('', arguments);
        },

        /* Override the default settings for all instances of the option picker.
        @param  settings  object - the new settings to use as defaults (anonymous object)
        @return the manager object */
        setDefaults: function(settings) {
            extendRemove(this._defaults, settings || {});
            return this;
        },

        /* Attach the option picker to a jQuery selection.
        @param  target    element - the target input field or division or span
        @param  settings  object - the new settings to use for this option picker instance (anonymous) */
        _attachOptionpicker: function(target, settings) {
            // check for settings on the control itself - in namespace 'option:'
            var inlineSettings = null;
            for (var attrName in this._defaults) {
                var attrValue = target.getAttribute('option:' + attrName);
                if (attrValue) {
                    inlineSettings = inlineSettings || {};
                    try {
                        inlineSettings[attrName] = eval(attrValue);
                    } catch (err) {
                        inlineSettings[attrName] = attrValue;
                    }
                }
            }
            var nodeName = target.nodeName.toLowerCase();
            var inline = (nodeName == 'div' || nodeName == 'span');
            if (!target.id)
                target.id = 'dp' + (++this.uuid);
            var inst = this._newInst($(target), inline);
            inst.settings = $.extend({}, settings || {}, inlineSettings || {});
            if (nodeName == 'input') {
                this._connectOptionpicker(target, inst);
            } else if (inline) {
                this._inlineOptionpicker(target, inst);
            }
        },

        /* Create a new instance object. */
        _newInst: function(target, inline) {
            var id = target[0].id.replace(/([:\[\]\.])/g, '\\\\$1'); // escape jQuery meta chars
            return { id: id, input: target, // associated target
                inline: inline, // is optionpicker inline or not
                dpDiv: (!inline ? this.dpDiv : // presentation div
			$('<div class="' + this._inlineClass + ' ui-optionpicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>'))
            };
        },

        /* Attach the option picker to an input field. */
        _connectOptionpicker: function(target, inst) {
            var input = $(target);
            inst.append = $([]);
            inst.trigger = $([]);
            if (input.hasClass(this.markerClassName))
                return;
            var appendText = this._get(inst, 'appendText');
            var isRTL = this._get(inst, 'isRTL');
            if (appendText) {
                inst.append = $('<span class="' + this._appendClass + '">' + appendText + '</span>');
                input[isRTL ? 'before' : 'after'](inst.append);
            }
            var showOn = this._get(inst, 'showOn');
            if (showOn == 'focus' || showOn == 'both') // pop-up option picker when in the marked field
                input.focus(this._showOptionpicker);
            input.addClass(this.markerClassName).keydown(this._doKeyDown).
			bind("setData.optionpicker", function(event, key, value) {
			    inst.settings[key] = value;
			}).bind("getData.optionpicker", function(event, key) {
			    return this._get(inst, key);
			});
            $.data(target, PROP_NAME, inst);
        },

        /* Attach an inline option picker to a div. */
        _inlineOptionpicker: function(target, inst) {
            var divSpan = $(target);
            if (divSpan.hasClass(this.markerClassName))
                return;
            divSpan.addClass(this.markerClassName).append(inst.dpDiv).
			bind("setData.optionpicker", function(event, key, value) {
			    inst.settings[key] = value;
			}).bind("getData.optionpicker", function(event, key) {
			    return this._get(inst, key);
			});
            $.data(target, PROP_NAME, inst);
            this._updateOptionpicker(inst);
        },

        /* Pop-up the option picker in a "dialog" box.
        @param  input     element - ignored
        @param  optionText  string - the initial option to display (in the current format)
        @param  onSelect  function - the function(optionText) to call when a option is selected
        @param  settings  object - update the dialog option picker instance's settings (anonymous object)
        @param  pos       int[2] - coordinates for the dialog's position within the screen or
        event - with x/y coordinates or
        leave empty for default (screen centre)
        @return the manager object */
        _dialogOptionpicker: function(input, optionText, onSelect, settings, pos) {
            var inst = this._dialogInst; // internal instance
            if (!inst) {
                var id = 'dp' + (++this.uuid);
                this._dialogInput = $('<input type="text" id="' + id +
				'" size="1" style="position: absolute; top: -100px;"/>');
                this._dialogInput.keydown(this._doKeyDown);
                $('body').append(this._dialogInput);
                inst = this._dialogInst = this._newInst(this._dialogInput, false);
                inst.settings = {};
                $.data(this._dialogInput[0], PROP_NAME, inst);
            }
            extendRemove(inst.settings, settings || {});
            this._dialogInput.val(optionText);

            this._pos = (pos ? (pos.length ? pos : [pos.pageX, pos.pageY]) : null);
            if (!this._pos) {
                var browserWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
                var browserHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
                var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
                var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
                this._pos = // should use actual width/height below
				[(browserWidth / 2) - 100 + scrollX, (browserHeight / 2) - 150 + scrollY];
            }

            // move input on screen for focus, but hidden behind dialog
            this._dialogInput.css('left', this._pos[0] + 'px').css('top', this._pos[1] + 'px');
            inst.settings.onSelect = onSelect;
            this._inDialog = true;
            this.dpDiv.addClass(this._dialogClass);
            this._showOptionpicker(this._dialogInput[0]);
            if ($.blockUI)
                $.blockUI(this.dpDiv);
            $.data(this._dialogInput[0], PROP_NAME, inst);
            return this;
        },

        /* Detach a optionpicker from its control.
        @param  target    element - the target input field or division or span */
        _destroyOptionpicker: function(target) {
            var $target = $(target);
            var inst = $.data(target, PROP_NAME);
            if (!$target.hasClass(this.markerClassName)) {
                return;
            }
            var nodeName = target.nodeName.toLowerCase();
            $.removeData(target, PROP_NAME);
            if (nodeName == 'input') {
                inst.append.remove();
                inst.trigger.remove();
                $target.removeClass(this.markerClassName).
				unbind('focus', this._showOptionpicker).
				unbind('keydown', this._doKeyDown);
            } else if (nodeName == 'div' || nodeName == 'span')
                $target.removeClass(this.markerClassName).empty();
        },

        /* Enable the option picker to a jQuery selection.
        @param  target    element - the target input field or division or span */
        _enableOptionpicker: function(target) {
            var $target = $(target);
            var inst = $.data(target, PROP_NAME);
            if (!$target.hasClass(this.markerClassName)) {
                return;
            }
            var nodeName = target.nodeName.toLowerCase();
            if (nodeName == 'input') {
                target.disabled = false;
            }
            else if (nodeName == 'div' || nodeName == 'span') {
                var inline = $target.children('.' + this._inlineClass);
                inline.children().removeClass('ui-state-disabled');
            }
            this._disabledInputs = $.map(this._disabledInputs,
			function(value) { return (value == target ? null : value); }); // delete entry
        },

        /* Disable the option picker to a jQuery selection.
        @param  target    element - the target input field or division or span */
        _disableOptionpicker: function(target) {
            var $target = $(target);
            var inst = $.data(target, PROP_NAME);
            if (!$target.hasClass(this.markerClassName)) {
                return;
            }
            var nodeName = target.nodeName.toLowerCase();
            if (nodeName == 'input') {
                target.disabled = true;
            }
            else if (nodeName == 'div' || nodeName == 'span') {
                var inline = $target.children('.' + this._inlineClass);
                inline.children().addClass('ui-state-disabled');
            }
            this._disabledInputs = $.map(this._disabledInputs,
			function(value) { return (value == target ? null : value); }); // delete entry
            this._disabledInputs[this._disabledInputs.length] = target;
        },

        /* Is the first field in a jQuery collection disabled as a optionpicker?
        @param  target    element - the target input field or division or span
        @return boolean - true if disabled, false if enabled */
        _isDisabledOptionpicker: function(target) {
            if (!target) {
                return false;
            }
            for (var i = 0; i < this._disabledInputs.length; i++) {
                if (this._disabledInputs[i] == target)
                    return true;
            }
            return false;
        },

        /* Retrieve the instance data for the target control.
        @param  target  element - the target input field or division or span
        @return  object - the associated instance data
        @throws  error if a jQuery problem getting data */
        _getInst: function(target) {
            try {
                return $.data(target, PROP_NAME);
            }
            catch (err) {
                throw 'Missing instance data for this optionpicker';
            }
        },

        /* Update or retrieve the settings for a option picker attached to an input field or division.
        @param  target  element - the target input field or division or span
        @param  name    object - the new settings to update or
        string - the name of the setting to change or retrieve,
        when retrieving also 'all' for all instance settings or
        'defaults' for all global defaults
        @param  value   any - the new value for the setting
        (omit if above is an object or to retrieve a value) */
        _optionOptionpicker: function(target, name, value) {
            var inst = this._getInst(target);
            if (arguments.length == 2 && typeof name == 'string') {
                return (name == 'defaults' ? $.extend({}, $.optionpicker._defaults) :
				(inst ? (name == 'all' ? $.extend({}, inst.settings) :
				this._get(inst, name)) : null));
            }
            var settings = name || {};
            if (typeof name == 'string') {
                settings = {};
                settings[name] = value;
            }
            if (inst) {
                if (this._curInst == inst) {
                    this._hideOptionpicker(null);
                }
                extendRemove(inst.settings, settings);
                this._updateOptionpicker(inst);
            }
        },

        // change method deprecated
        _changeOptionpicker: function(target, name, value) {
            this._optionOptionpicker(target, name, value);
        },

        /* Redraw the option picker attached to an input field or division.
        @param  target  element - the target input field or division or span */
        _refreshOptionpicker: function(target) {
            var inst = this._getInst(target);
            if (inst) {
                this._updateOptionpicker(inst);
            }
        },

        /* Handle keystrokes. */
        _doKeyDown: function(event) {
            var inst = $.optionpicker._getInst(event.target);
            var handled = true;
            var isRTL = inst.dpDiv.is('.ui-optionpicker-rtl');
            inst._keyEvent = true;
            if ($.optionpicker._optionpickerShowing)
                switch (event.keyCode) {
                case 9: $.optionpicker._hideOptionpicker(null, '');
                    break; // hide on tab out
                case 27: $.optionpicker._hideOptionpicker(null, $.optionpicker._get(inst, 'duration'));
                    break; // hide on escape
                default: handled = false;
            }
            else if (event.keyCode == 36 && event.ctrlKey) // display the option picker on ctrl+home
                $.optionpicker._showOptionpicker(this);
            else {
                handled = false;
            }
            if (handled) {
                event.preventDefault();
                event.stopPropagation();
            }
        },

        /* Pop-up the option picker for a given input field.
        @param  input  element - the input field attached to the option picker or
        event - if triggered by focus */
        _showOptionpicker: function(input) {
            input = input.target || input;
            if ($.optionpicker._isDisabledOptionpicker(input) || $.optionpicker._lastInput == input) // already here
                return;
            var inst = $.optionpicker._getInst(input);
            var beforeShow = $.optionpicker._get(inst, 'beforeShow');
            extendRemove(inst.settings, (beforeShow ? beforeShow.apply(input, [input, inst]) : {}));
            $.optionpicker._hideOptionpicker(null, '');
            $.optionpicker._lastInput = input;
            if ($.optionpicker._inDialog) // hide cursor
                input.value = '';
            if (!$.optionpicker._pos) { // position below input
                $.optionpicker._pos = $.optionpicker._findPos(input);
                $.optionpicker._pos[1] += input.offsetHeight; // add the height
            }
            var isFixed = false;
            $(input).parents().each(function() {
                isFixed |= $(this).css('position') == 'fixed';
                return !isFixed;
            });
            if (isFixed && $.browser.opera) { // correction for Opera when fixed and scrolled
                $.optionpicker._pos[0] -= document.documentElement.scrollLeft;
                $.optionpicker._pos[1] -= document.documentElement.scrollTop;
            }
            var offset = { left: $.optionpicker._pos[0], top: $.optionpicker._pos[1] };
            $.optionpicker._pos = null;
            inst.rangeStart = null;
            // determine sizing offscreen
            inst.dpDiv.css({ position: 'absolute', display: 'block', top: '-1000px' });
            $.optionpicker._updateOptionpicker(inst);
            // fix width for dynamic number of option pickers
            // and adjust position before showing
            //offset = $.optionpicker._checkOffset(inst, offset, isFixed);
            inst.dpDiv.css({ position: ($.optionpicker._inDialog && $.blockUI ?
			'static' : (isFixed ? 'fixed' : 'absolute')), display: 'none',
                left: offset.left + 'px', top: offset.top + 'px'
            });
            if (!inst.inline) {
                var showAnim = $.optionpicker._get(inst, 'showAnim') || 'show';
                var duration = $.optionpicker._get(inst, 'duration');
                var postProcess = function() {
                    $.optionpicker._optionpickerShowing = true;
                    if ($.browser.msie && parseInt($.browser.version, 10) < 7) // fix IE < 7 select problems
                        $('iframe.ui-optionpicker-cover').css({ width: inst.dpDiv.width() + 4,
                            height: inst.dpDiv.height() + 4
                        });
                };
                if ($.effects && $.effects[showAnim])
                    inst.dpDiv.show(showAnim, $.optionpicker._get(inst, 'showOptions'), duration, postProcess);
                else
                    inst.dpDiv[showAnim](duration, postProcess);
                if (duration == '')
                    postProcess();
                if (inst.input[0].type != 'hidden')
                    inst.input[0].focus();
                $.optionpicker._curInst = inst;
            }
        },

        /* Generate the option picker content. */
        _updateOptionpicker: function(inst) {
            var dims = { width: inst.dpDiv.width() + 4,
                height: inst.dpDiv.height() + 4
            };
            var self = this;
            inst.dpDiv.empty().append(this._generateHTML(inst))
			.find('iframe.ui-optionpicker-cover').
				css({ width: dims.width, height: dims.height })
			.end()
			.find('.' + this._dayOverClass + ' a')
				.trigger('mouseover')
			.end();
            var width = 17;
            if (inst.input && inst.input[0].type != 'hidden' && inst == $.optionpicker._curInst)
                $(inst.input[0]).focus();
        },

        /* Check positioning to remain on screen. */
        _checkOffset: function(inst, offset, isFixed) {
            var dpWidth = inst.dpDiv.outerWidth();
            var dpHeight = inst.dpDiv.outerHeight();
            var inputWidth = inst.input ? inst.input.outerWidth() : 0;
            var inputHeight = inst.input ? inst.input.outerHeight() : 0;
            var viewWidth = (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) + $(document).scrollLeft();
            var viewHeight = (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) + $(document).scrollTop();

            offset.left -= (this._get(inst, 'isRTL') ? (dpWidth - inputWidth) : 0);
            offset.left -= (isFixed && offset.left == inst.input.offset().left) ? $(document).scrollLeft() : 0;
            offset.top -= (isFixed && offset.top == (inst.input.offset().top + inputHeight)) ? $(document).scrollTop() : 0;

            // now check if optionpicker is showing outside window viewport - move to a better place if so.
            offset.left -= (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ? Math.abs(offset.left + dpWidth - viewWidth) : 0;
            offset.top -= (offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ? Math.abs(offset.top + dpHeight + inputHeight * 2 - viewHeight) : 0;

            return offset;
        },

        /* Find an object's position on the screen. */
        _findPos: function(obj) {
            while (obj && (obj.type == 'hidden' || obj.nodeType != 1)) {
                obj = obj.nextSibling;
            }
            var position = $(obj).offset();
            return [position.left, position.top];
        },

        /* Hide the option picker from view.
        @param  input  element - the input field attached to the option picker
        @param  duration  string - the duration over which to close the option picker */
        _hideOptionpicker: function(input, duration) {
            var inst = this._curInst;
            if (!inst || (input && inst != $.data(input, PROP_NAME)))
                return;
            inst.stayOpen = false;
            if (this._optionpickerShowing) {
                duration = (duration != null ? duration : this._get(inst, 'duration'));
                var showAnim = this._get(inst, 'showAnim');
                var postProcess = function() {
                    $.optionpicker._tidyDialog(inst);
                };
                if (duration != '' && $.effects && $.effects[showAnim])
                    inst.dpDiv.hide(showAnim, $.optionpicker._get(inst, 'showOptions'),
					duration, postProcess);
                else
                    inst.dpDiv[(duration == '' ? 'hide' : (showAnim == 'slideDown' ? 'slideUp' :
					(showAnim == 'fadeIn' ? 'fadeOut' : 'hide')))](duration, postProcess);
                if (duration == '')
                    this._tidyDialog(inst);
                var onClose = this._get(inst, 'onClose');
                if (onClose)
                    onClose.apply((inst.input ? inst.input[0] : null),
					[(inst.input ? inst.input.val() : ''), inst]);  // trigger custom callback
                this._optionpickerShowing = false;
                this._lastInput = null;
                if (this._inDialog) {
                    this._dialogInput.css({ position: 'absolute', left: '0', top: '-100px' });
                    if ($.blockUI) {
                        $.unblockUI();
                        $('body').append(this.dpDiv);
                    }
                }
                this._inDialog = false;
            }
            this._curInst = null;
        },

        /* Tidy up after a dialog display. */
        _tidyDialog: function(inst) {
            inst.dpDiv.removeClass(this._dialogClass).unbind('.ui-optionpicker-calendar');
        },

        /* Close option picker if clicked elsewhere. */
        _checkExternalClick: function(event) {
            if (!$.optionpicker._curInst)
                return;
            var $target = $(event.target);
            if (($target.parents('#' + $.optionpicker._mainDivId).length == 0) &&
				!$target.hasClass($.optionpicker.markerClassName) &&
				!$target.hasClass($.optionpicker._triggerClass) &&
				$.optionpicker._optionpickerShowing && !($.optionpicker._inDialog && $.blockUI))
                $.optionpicker._hideOptionpicker(null, '');
        },

        /* Update the input field with the selected option. */
        _selectOption: function(id, text) {
            var target = $(id);
            var inst = this._getInst(target[0]);
            if (inst.input)
                inst.input.val(text);
            var onSelect = this._get(inst, 'onSelect');
            if (onSelect)
                onSelect.apply((inst.input ? inst.input[0] : null), [text, inst]);  // trigger custom callback
            else if (inst.input)
                inst.input.trigger('change'); // fire the change event
            if (inst.inline)
                this._updateOptionpicker(inst);
            else if (!inst.stayOpen) {
                this._hideOptionpicker(null, this._get(inst, 'duration'));
                this._lastInput = inst.input[0];
                if (typeof (inst.input[0]) != 'object')
                    inst.input[0].focus(); // restore focus
                this._lastInput = null;
            }
        },

        /* Get a setting value, defaulting if necessary. */
        _get: function(inst, name) {
            return inst.settings[name] !== undefined ?
			inst.settings[name] : this._defaults[name];
        },

        /* Generate the HTML for the current state of the option picker. */
        _generateHTML: function(inst) {
        var html = '<div class="suggestionresults"><span class="category">Choose one of these</span>';
        var optionItems = this._get(inst, 'optionItems');
            for (var i = 0; i < optionItems.length; i++) {
                html += '<a href="#" class="suggestion" onclick="DP_jQuery.optionpicker._selectOption(\'#' + inst.id + '\',\'' + optionItems[i] + '\');return false;">' + optionItems[i] + '</a>';
            }
            html += '<span class="category">Or type something else</span></div>'
            html += ($.browser.msie && parseInt($.browser.version, 10) < 7 && !inst.inline ?
			'<iframe src="javascript:false;" class="ui-optionpicker-cover" frameborder="0"></iframe>' : '');
            inst._keyEvent = false;
            return html;
        }
    });

    /* 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 optionpicker functionality.
    @param  options  string - a command, optionally followed by additional parameters or
    Object - settings for attaching new optionpicker functionality
    @return  jQuery object */
    $.fn.optionpicker = function(options) {

        /* Initialise the option picker. */
        if (!$.optionpicker.initialized) {
            $(document).mousedown($.optionpicker._checkExternalClick).
			find('body').append($.optionpicker.dpDiv);
            $.optionpicker.initialized = true;
        }

        var otherArgs = Array.prototype.slice.call(arguments, 1);
        if (typeof options == 'string' && (options == 'isDisabled' || options == 'getDate'))
            return $.optionpicker['_' + options + 'Optionpicker'].
			apply($.optionpicker, [this[0]].concat(otherArgs));
        if (options == 'option' && arguments.length == 2 && typeof arguments[1] == 'string')
            return $.optionpicker['_' + options + 'Optionpicker'].
			apply($.optionpicker, [this[0]].concat(otherArgs));
        return this.each(function() {
            typeof options == 'string' ?
			$.optionpicker['_' + options + 'Optionpicker'].
				apply($.optionpicker, [this].concat(otherArgs)) :
			$.optionpicker._attachOptionpicker(this, options);
        });
    };

    $.optionpicker = new Optionpicker(); // singleton instance
    $.optionpicker.initialized = false;
    $.optionpicker.uuid = new Date().getTime();
    $.optionpicker.version = "1.7.2";

    // Workaround for #4055
    // Add another global to avoid noConflict issues with inline event handlers
    window.DP_jQuery = $;

})(jQuery);
