(function($) {
    // Places matched elements at the center of the window.
    // Uses top and left CSS properties (options can skew them).
    $.fn.centerScreen = function(options) {
        var opt = $.extend({ top: 0, left: 0 }, options || {});
        var jw = $(window);
        return this.each(function() {
            var current = $(this);
            var pos = {
                top: (jw.height() / 2) - (current.height() / 2) + jw.scrollTop() + opt.top,
                left: (jw.width() / 2) - (current.width() / 2) + jw.scrollLeft() + opt.left
            };
            pos.top = (pos.top < 0) ? 0 : pos.top;
            pos.left = (pos.left < 0) ? 0 : pos.left;
            current.css(pos);
        });
    };
    
    // Places matched elements off screen.
    $.fn.offScreen = function() {
        var pos = { top: -9999, left: -9999 };
        return this.each(function() {
            $(this).css(pos);
        });
    };
    
})(jQuery);

(function($) {
    
    $.fn.serializeObject = function() {
        var array = this.serializeArray();
        var data = {};
        $.each(array, function() {
            if (this.name in data) {
                if (!$.isArray(data[this.name])) {
                    var val = data[this.name];
                    data[this.name] = [val];
                }
                data[this.name].push(this.value);
            }
            else if (this.name.substr(this.name.length - 2, 2) == "[]") {
                data[this.name] = [this.value];
            }
            else {
                data[this.name] = this.value;
            }
        });
        return data;
    };
    
})(jQuery);

(function($) {
    if ($.datepick)
        $.datepick.setDefaults({
            firstDay: 1,
            dateFormat: "yy-mm-dd",
            closeAtTop: false
        });
})(jQuery);