﻿// JScript File


var VideoAdEngine = function(videoAd)
{
    this.prototype = this;
    //alert("");
    this.videoAd = videoAd;
    this.isRun = isRun;
    this.getAd =getAd;
    this.setAd =setAd;
    this.getPlayer =getPlayer;
    this.setPlayer =setPlayer;
    this.registerAd =registerAd;
    this.updateProgressBar =updateProgressBar;
    this.setRunAdEventListener =setRunAdEventListener;
    this.runAdEventFunction = null;
    this.setStopAdEventListener =setStopAdEventListener;
    this.stopAdEventFunction = null;
}
function setRunAdEventListener(runAdEventFunction)
{
    this.runAdEventFunction = runAdEventFunction;
}

function setStopAdEventListener(stopAdEventFunction)
{
    this.stopAdEventFunction = stopAdEventFunction;
}

function isRun()
{
    var status = this.videoAd.getStatus();
    return (status == 1);
}

function setAd(videoAd)
{
    this.videoAd = videoAd;
}

function getAd()
{
    return this.videoAd;
}

function setPlayer(player)
{
    this.player = player;
}

function getPlayer()
{
    return this.player;
}

function registerAd()
{
    //if(this.player.)
}
var i=0;
function updateProgressBar()
{
    
    if(this.player.playState ==3 && this.videoAd != null)
    {
        var posInPrec = (this.player.controls.currentPosition*100) / this.player.currentMedia.duration;
        var progressStr = this.player.currentMedia.durationString+" / "+this.player.controls.currentPositionString;
        //$("#label").html(progressStr);
        
        
        if(this.player.controls.currentPosition > this.videoAd.getStartTime()/1000 && this.videoAd.getStatus() == 0)
        {
            this.runAdEventFunction();
            this.videoAd.setStatus(1);
            
        }
        if(this.player.controls.currentPosition >( this.videoAd.getStartTime()+this.videoAd.getDuration())/1000 && this.videoAd.getStatus() == 1)
        {
            this.stopAdEventFunction();
            this.videoAd.setStatus(2);
            
        }
    }
   //alert(( this.videoAd.getStartTime()+this.videoAd.getDuration())/1000);
   // window.setTimeout('testVideoAdProvider.getVideoAdProvider().updateProgressBar();', 500);
    var selfobject = this;
    window.setTimeout(function(){selfobject.updateProgressBar();}, 500);
        //alert("#2");
    
    
}





