/**
 * jQuery.absoluteToFixed
 *
 * Copyright (C) 2010 Marcos Cooper
 * Dual licensed under MIT and GPL
 *
 * @author Marcos Cooper
 * @date 2011-10-28
 * @version 0.2
 */

(function($){
    $.fn.absoluteToFixed = function() {
        if (!jQuery.browser.msie || jQuery.browser.version >= 7) {
            return this.each(function(){
                var target = $(this);
                var offset = target.offset();
                var center = Math.floor($(window).height() / 2) - Math.floor(target.height() / 2);
                $(window).scroll(function() {
                    if ($(window).scrollTop() > (offset.top - center)) {
                        target.css({'position': 'fixed', 'top': center});
                    } else {
                        target.css({'position': 'absolute', 'top': offset.top});
                    }
                });
                $(window).resize(function(){
                    center = Math.floor($(window).height() / 2) - Math.floor(target.height() / 2);
                });
            });
        }
    }
})(jQuery);
