
(function($) {

    $.fn.objectRePos = function(options, callback) {
        var defaultSettings = {
            minWidth: 1024,
            minHeight: 768,
            minWidthPos: '0',
            regularWidthPos: '0',
            minHeightPos: '0',
            regularHeightPos: '0',
            xorientation: 'left',
            yorientation: 'top',
            h: 0
        },
        container = this,
        settings = container.data("settings") || defaultSettings, // If this has been called once before, use the old settings as the default
        existingSettings = container.data('settings'),
        rootElement = ("onorientationchange" in window) ? $(document) : $(window), // hack to acccount for iOS position:fixed shortcomings
        xposition, yposition;
                
        // Extend the settings with those the user has provided
        if(options && typeof options == "object") $.extend(settings, options);
        
        // Just in case the user passed in a function without options
        if(options && typeof options == "function") callback = options;
    
        // Initialize
        $(document).ready(_init);
  
        // For chaining
        return this;
    
        function _init() {
            
            container.data("settings", settings);
            _adjustPosition();
            $(window).resize(_adjustPosition);
        }
            
        function _adjustPosition(fn) {
            try {
               container.css('height', settings.h+'px');
               yposition = (rootElement.height() - container.height()) / 2;
                
               
               container.css('top', yposition+'px');
                
            } catch(err) {
                // IE7 seems to trigger _adjustBG before the image is loaded.
                // This try/catch block is a hack to let it fail gracefully.
            }
      
            // Executed the passed in function, if necessary
            if (typeof fn == "function") fn();
        }
    };
  
})(jQuery);
