/*
 * Fichier JS contenant les fonctions de l'iframe de pub
 * PRE ROLL
 *
 * $Revision: 22489 $
 * $Date: 2009-05-18 08:42:59 +0200 (lun., 18 mai 2009) $
 * $Author: mika $
 */

function verif_version_swf(major,minor,revision)
{
    if(major>9)
    {
        return true;
    }
    else if(major==9)
    {
        if(minor>=0&&revision>=115)
        {
            return true;
        }
    }
    else
    {
        return false;
    }
}

function functionPartager()
{
    alert('Fonction à mettre à jour pour le partage');
}

function majCompteur(iframeRecu,passerDirect,compteurRecu,compteurRecuConteneur,idPlayerRecu)
{
    try
    {
        if(document.getElementById(compteurRecu).innerHTML>0)
        {
            document.getElementById(compteurRecu).innerHTML-=1;
            setTimeout(function()
            {
                majCompteur(iframeRecu,passerDirect,compteurRecu,compteurRecuConteneur,idPlayerRecu);
            },1000);
        }
        else
        {
            joueVideo(iframeRecu, passerDirect, compteurRecu, compteurRecuConteneur, idPlayerRecu, "PLAY");
        }
    }
    catch(e)
    {}
}

function affichePub(lienRecu,idContainerRecu,idPlayerRecu)
{
    // console.info('je suis dans le JS');
    var Conteneur = document.getElementById(idContainerRecu);
    var offConteneur = (Conteneur.offsetWidth-widthPlayer)/2;
    offConteneur += 5;

    var dIframe = document.createElement("iframe");
    dIframe.id = idContainerRecu+"iframePub";
    dIframe.src = lienRecu;
    dIframe.scrolling = "No";
    dIframe.border = "0";
    dIframe.frameBorder = "0";

    var IframeCSS="";
    IframeCSS+="position:absolute;top:12px;left:"+offConteneur+"px;border:0;overflow:hidden;background-color:#000000;";
    IframeCSS+="height:"+(heightPlayer-46)+"px; ";
    IframeCSS+="width:"+(widthPlayer-10)+"px; ";
    dIframe.setAttribute("style",IframeCSS);

    if(navigator.appName=="Microsoft Internet Explorer")
    {dIframe.style.setAttribute("cssText",IframeCSS);}
    Conteneur.appendChild(dIframe);

    var dDiv=document.createElement("div");
    dDiv.id=idContainerRecu+"compteurPubConteneur";

    if(heightPlayer<400)
    {
        dDiv.className = "player_video_placer_compteur";
        var divCSS = "width:"+((widthPlayer/2)+10)+"px;left:"+offConteneur+"px;position:absolute;top:"+Math.round(heightPlayer-30)+"px;";
    }
    else
    {
        var divCSS="height:20px;width:"+ (widthPlayer - 10) +"px;position:absolute;top:"+Math.round(heightPlayer-80)+"px;left:"+offConteneur+"px;border:0;text-align:center;color:white;font-family:Arial,Helvetica,sans-serif;";
    }

    dDiv.setAttribute("style",divCSS);

    if (navigator.appName=="Microsoft Internet Explorer")
    {
        dDiv.style.setAttribute("cssText",divCSS);
    }

    Conteneur.appendChild(dDiv);
    dDiv.innerHTML = "Début de la vidéo dans ";

    var dDiv2=document.createElement("span");
    dDiv2.id=idContainerRecu+"compteurPub";
    var divCSS2="color:red;";
    dDiv2.setAttribute("style",divCSS2);

    if(navigator.appName=="Microsoft Internet Explorer")
    {
        dDiv2.style.setAttribute("cssText",divCSS2);
    }

    dDiv.appendChild(dDiv2);
    dDiv2.innerHTML=playerVideoTempsPub;
    dDiv.innerHTML+=" secondes";

    var dDiv3 = document.createElement("a");
    dDiv3.id = idContainerRecu+"lienVoirDirectementlaVideo";
    dDiv3.name = idContainerRecu+"lienVoirDirectementlaVideo";
    dDiv3.href = "#"+idContainerRecu+"lienVoirDirectementlaVideo";
    dDiv3.onclick = function() {joueVideo(dIframe.id, dDiv3.id, dDiv2.id, dDiv.id, idPlayerRecu, "PLAY");}

    if(heightPlayer<400)
    {
        dDiv3.className = "player_video_placer_lien";
        var divCSS3 = "width:"+(((widthPlayer)/2)-20)+"px;left:"+(offConteneur+(widthPlayer/2)+10)+"px;position:absolute;top:"+Math.round(heightPlayer-30)+"px;";
    }
    else
    {
        var divCSS3="height:20px;width:"+ (widthPlayer - 10) +"px;position:absolute;top:"+Math.round(heightPlayer-60)+"px;left:"+offConteneur+"px;border:0;text-align:center;color:#0A77B8;font-family:Arial,Helvetica,sans-serif;text-decoration:underline ;";
    }

    dDiv3.setAttribute("style",divCSS3);

    if(navigator.appName=="Microsoft Internet Explorer")
    {
        dDiv3.style.setAttribute("cssText",divCSS3);
    }

    Conteneur.appendChild(dDiv3);dDiv3.innerHTML="Voir directement la vidéo";
    setTimeout(function(){majCompteur(dIframe.id,dDiv3.id,dDiv2.id,dDiv.id,idPlayerRecu);},1000);

}



function joueVideo(iframeRecu, passerDirect, compteurRecu, compteurRecuConteneur, idPlayerRecu, action)
{
    var n=document.getElementById(iframeRecu);
    removeChildContainer(n);
    n=document.getElementById(passerDirect);
    removeChildContainer(n);
    n=document.getElementById(compteurRecu);
    removeChildContainer(n);
    n=document.getElementById(compteurRecuConteneur);
    removeChildContainer(n);
    //sendEvent(idPlayerRecu,'PLAY');
    
    if(action == "PLAY")
        document.getElementById(idPlayerRecu).FinPub();
    else if(action == "HD")
        document.getElementById(idPlayerRecu).LireHD();
}

function removeChildContainer(n)
{
    if(n)
    {
        n.parentNode.removeChild(n);
    }
}

//function sendEvent(swf,typ,prm){thisMovie(swf).sendEvent(typ,prm);};
function getUpdate(typ,pr1,pr2,swf){};

function thisMovie(swf)
{
    if(navigator.appName.indexOf("Microsoft")!=-1)
    {
        return window[swf];
    }
    else
    {
        return document[swf];
    }
};
