//              jQuery Background Image Re-Sizer
//                   Aquired from CSS-Tricks
//_____________________________________________________________________
//                                                                   //
//     *************** HTML *********************                    //
//                                                                   //
//   <img src="images/bg.jpg" id="bg" alt="">                        //
//                                                                   //
//                                                                   //
//      *************** CSS ****************                         //
//                                                                   //
//    #bg { position: fixed; top: 0; left: 0; z-index:-1; }          //
//    .bgwidth { width: 100%; }                                      //
//    .bgheight { height: 100%; }                                    //
//                                                                   //
//___________________________________________________________________//



$(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');
                }

        }

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

});
