﻿// jQuery.support.positionFixed
// does the browser support `position:fixed`
$(document).ready(function() {
	$.support.positionFixed = (function() {
	    if ($.cookie){
		    var cookie = $.cookie("$.support.positionFixed");
		    if (cookie) {
			    switch (cookie) {
				    case "true": return true;
				    case "false": return true;
			    }
		    }
		}

		var body = $("body");
		var bodyStyle = body.attr("style");
		if (body.height() < $(window).height())
			body.css("height", ($(window).height() + 1) + "px");

		var initScrollTop = $(window).scrollTop();
		$(window).scrollTop(1);
		if ($(window).scrollTop() != 1)
			return false;

		var elem = $('<div>', {
			css: {
				position: 'fixed',
				top: '42px',
				visibility: 'hidden',
			}
		}).appendTo(document.body || document.documentElement),

		// also account for page scroll
            support = parseInt(elem.offset().top, 10) === 43;
		elem.remove();
		
		$.cookie("$.support.positionFixed", support ? "true" : "false", { expires: 90 });
		
		$(window).scrollTop(initScrollTop);
		if (bodyStyle)
    		body.attr("style", bodyStyle);
    	else
    	    body.removeAttr("style");
    	    
		return support;
	})();
});
