$(document).ready(function () {
    var vH = $(window).height();
    var vW = $(window).width() + 32;
    var vT = $('body').offset().top;
    var vL = $('body').offset().left;

    $('html').mousemove(function (e) {

        var ypos = e.pageY - vT;
        var xpos = e.pageX - vL;
        var y = Math.round(ypos / vH * 100);
        var x = Math.round(xpos / vW * 100);

        $('body').stop().animate({ backgroundPosition: x + '% ' + y + '%' }, { duration: 200 }, 'easeOutQuint');

    });

    $(".b").hover(
              function () {
                  $(this).stop().animate({ width: '260px', height: '112px' }, { duration: 300 }, 'easeOutQuint');
              },
              function () {
                  $(this).stop().animate({ width: '250px', height: '106px' }, { duration: 300 }, 'easeOutQuint');
              }
            );


    //            var opts = {
    //                start_index: 0, //The first image to anim to
    //                duration: 2000, //Animation duration
    //                delay: 5000,    //Delay between animations
    //                easing: 'easeOutQuint'  //jQuery easing
    //            }

    //            $('body').fadeSimple([
    //                { src: 'css/bg.jpg' },
    //                { src: 'css/bg2.jpg' }
    //            ], opts);

});

var resizeTimer;
$(window).resize(function () {
    clearTimeout(resizeTimer);
    resizeTimer = setTimeout(initbg, 100);
});


//        var bgTimer;
//        function switchbg() {
//            clearTimeout(bgTimer);

//            if ($("body").css("background-image").indexOf("bg2.jpg") > 0)  {
//                $("body").css("background", "url('css/bg.jpg')");

//            } else {
//                $("body").css("background", "url('css/bg2.jpg')");

//            }


//            bgTimer = setTimeout(switchbg, 4000);
//        }

function initbg() {

    vH = $(window).height();
    vW = $(window).width() + 32;
    vT = $('body').offset().top;
    vL = $('body').offset().left;

    $('body').stop().css({ backgroundPosition: '50% 50%' });
};

initbg();
//switchbg();
