// JavaScript Document
$(window).load(function() {    

        var theWindow        = $(window),
            $bg              = $("#bg"),
            aspectRatio      = $bg.width() / $bg.height();

        function resizeBg() {

                if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
                    $bg
                        .removeClass()
                        .addClass('bgheight');
                } else {
                    $bg
                        .removeClass()
                        .addClass('bgwidth');
                }
				$bg.css('display','block');
				$bg.css('margin-left',((-$bg.width()/2)+'px'));
				$bg.css('margin-top',((-$bg.height()/2)+'px'));

        }

        theWindow.resize(function() {
                resizeBg();
        }).trigger("resize");

});
