$(document).ready(function() {
    if (!$.cookie('disableSplash'))
    {
        $('#splashContainer').css(
            'display', 'block'
        );        
        $.cookie('disableSplash', '1', {
            path: "/"
        });
        
        
        doResize();
        
        $('#splashContainer').click(function() {
            $('#splashContainer').css(
                'display', 'none'
            );
        });        
    }
    
    $(window).resize(function(){
        doResize();
    });    
});



function doResize()
{
    $('#backgroundBox').css({
        'width': '0px',
        'height': '0px'
    });

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY || window.scrollMaxX)
	{
        if (window.scrollMaxY)
        {
            scrollBarWidth = getScrollbarWidth();
        }
        else
        {
            scrollBarWidth = 0;
        }
		xScroll = window.innerWidth + window.scrollMaxX - scrollBarWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth)
	{ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight)
	{	// all except Explorer
		if(document.documentElement.clientWidth)
		{
			windowWidth = document.documentElement.clientWidth;
		}
		else
		{
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if (yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	}
	else
	{
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if (xScroll < windowWidth)
	{
		pageWidth = windowWidth;
	}
	else
	{
		// pageWidth = windowWidth;
		pageWidth = xScroll;
	}

    $('#backgroundBox').css({
        'width': pageWidth + 'px',
        'height': pageHeight + 'px'
    });
}

function getScrollbarWidth()
{
    // look for cached version
    if (typeof window.scrollbarWidth == 'number')
    {
        return window.scrollbarWidth;
    }

    // create test container and inner overflow box
    var outerBox = document.createElement('div');
    outerBox.style.position = 'absolute';
    outerBox.style.top      = '100px';
    outerBox.style.left     = '100px';
    outerBox.style.width    = '200px';
    outerBox.style.height   = '200px';
    outerBox.style.overflow = 'hidden';

    var innerBox = document.createElement('div');
    innerBox.style.width    = '100%';
    innerBox.style.height   = '400px'; // cause overflow

    outerBox.appendChild(innerBox);
    document.body.appendChild(outerBox);

    // measure inner box size with overflow hidden
    var sizeWithNoScrollbar = innerBox.offsetWidth;

    // measure width with overflow scroll
    outerBox.style.overflow = 'auto';
    var sizeWithScrollbar = innerBox.offsetWidth;
    outerBox.parentNode.removeChild(outerBox);

    window.scrollbarWidth = sizeWithNoScrollbar - sizeWithScrollbar;

    return window.scrollbarWidth;
}

