/* jQuery timeslider
 * Shows a slider for selecting a time
 *
 * Copyright (c) 2009 Alex Barrett (spleenboy.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Usage:
 * $('input.time').timeslider({ hide: true|false, step: 30 });
 * @hide indicates whether the slider is hidden when it is initialized
 * @step indicates the number of minutes between steps in the slider
 */

/**
 * Enhanced .offset()
 * Abstracts offset().right and offset().bottom into a built-in getter, and adds .offset(top, left) as a setter.
 *
 * @version 1.0
 * @example $('#tester').offset().bottom
 * @example $('#tester').offset().right
 * @example $('#tester').offset(10, 20);
 * @example $('#tester').offset(10, 20, 'fast');
 * @example $('#tester').offset('+=10', '+=20');
 * @example $('#tester').offset('+=5', '-=30');
 * @author Brian Schweitzer (BrianFreud)
 * @author Charles Phillips, first half of the return conditional ( http://groups.google.com/group/jquery-dev/browse_thread/thread/10fa400d3f9d9521/ )
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
(function($) {
    var offsetMethod = $.fn.offset;
    $.fn.offset = function () {
        var offset = offsetMethod.call(this),
            bottom = offset.top + this.outerHeight(),
            right = offset.left + this.outerWidth(),
            a = arguments;
        return (a.length) ? this.animate({
                                         top  : a[0].top  || a[0],
                                         left : a[0].left || a[1]
                                         }, (a[0].top ? a[1] : a[2]) || 1)
                          : $.extend(offset, {
                                             bottom: bottom,
                                             right: right
                                             });
    };
})(jQuery);

(function($) {
    var positionMethod = $.fn.position;
    $.fn.position = function () {
        var position = positionMethod.call(this),
            bottom = position.top + this.outerHeight(),
            right = position.left + this.outerWidth(),
            a = arguments;
        return (a.length) ? this.animate({
                                         top  : a[0].top  || a[0],
                                         left : a[0].left || a[1]
                                         }, (a[0].top ? a[1] : a[2]) || 1)
                          : $.extend(position, {
                                             bottom: bottom,
                                             right: right
                                             });
    };
})(jQuery);

$.fn.insertAtCaret = function (myValue) {
        return this.each(function(){
                //IE support
                if (document.selection) {
                        this.focus();
                        sel = document.selection.createRange();
                        sel.text = myValue;
                        this.focus();
                }
                //MOZILLA/NETSCAPE support
                else if (this.selectionStart || this.selectionStart == '0') {
                        var startPos = this.selectionStart;
                        var endPos = this.selectionEnd;
                        var scrollTop = this.scrollTop;
                        this.value = this.value.substring(0, startPos)
                                      + myValue
                              + this.value.substring(endPos,
this.value.length);
                        this.focus();
                        this.selectionStart = startPos + myValue.length;
                        this.selectionEnd = startPos + myValue.length;
                        this.scrollTop = scrollTop;
                } else {
                        this.value += myValue;
                        this.focus();
                }
        });

};
