
function initVideoBg()
{    
    if (isIPhone) enableImageBg();
    else
    {        
        if (!isIPad)
        {
            $('#video-bg-preloader').css('display', 'none');
            $('#wrapper').addClass('first-preloader');
        }
        else enableVideoBg();

        $('#video-bg').css('display', 'block');
        RPVideoBg();
    }
}

function enableImageBg()
{
    var img = new Image();

    $('#video-bg-preloader').width($(window).width());
    $('#video-bg-preloader').height($(window).height());

    $(img).load(function()
    {
        $('#video-bg').html(this);
        $('#video-bg').css('display', 'block');
        $('#video-bg-preloader').css('display', 'none');
        RPVideoBg();
        $('#video-bg').stop(true, true).animate({'opacity':'0'}, 0, function(){$('#video-bg').stop(true, true).animate({'opacity':'1'}, 600);});
    }).attr('src', DB_SETTINGS_BG_IMAGE);
}

function enableVideoBg()
{    
    videoPlayer = document.getElementById('video-bg-player');

    if (!isFirefox)
    {
        setTimeout(function()
        {
            videoPlayer.load();
            if (!isIPad)
            {
                videoPlayer.muted = true;
                videoPlayer.volume = 0;
            }
            setTimeout(function()
            {
                videoPlayer.play();
            }, 1000);
        }, 1000);
    }

    if (!isIPad)
    {
        videoPlayer.muted = true;
        videoPlayer.volume = 0;
    }
    
    videoPlayer.addEventListener('play', function(e)
    {    
        $('#video-bg-preloader').css('display', 'none');
        $('#video-bg').stop(true, true).animate({'opacity':'0'}, 0, function(){$('#video-bg').stop(true, true).animate({'opacity':'1'}, 600);});
	}, true);
    videoPlayer.addEventListener('ended', function(e)
    {
        videoPlayer.play();
	}, true);
}

function RPVideoBg()
{    
    if (isIPad)
    {
        PrototypesObject.ResizeItem2('#video-bg', $(window).width(), $(window).height(), DB_SETTINGS_BG_VIDEO_WIDTH, DB_SETTINGS_BG_VIDEO_HEIGHT, 'center');
        $('#video-bg-preloader').width($(window).width());
        $('#video-bg-preloader').height($(window).height());
        $('#video-bg-over').width($(window).width());
        $('#video-bg-over').height($(window).height());
    }
    else
    {
        $('#video-bg').width($(window).width());
        $('#video-bg').height($(window).height());
        $('object', '#video-bg').width($(window).width());
        $('object', '#video-bg').height($(window).height());
        $('#video-bg-over').width($(window).width());
        $('#video-bg-over').height($(window).height());
    }
}
