

function updateHTML(elmId, value) {
document.getElementById(elmId).innerHTML = value;
}

function onPlayerError(errorCode) {
  stopVideo();
  playVideo();
//alert("Vídeo não localizado:" + errorCode);
}

function onPlayerStateChange(newState) {
updateHTML("playerState", newState);
}

function updatePlayerInfo() {
if(ytplayer && ytplayer.getDuration) {
    updateHTML("videoDuration", ytplayer.getDuration());
    updateHTML("videoCurrentTime", ytplayer.getCurrentTime());
    updateHTML("bytesTotal", ytplayer.getVideoBytesTotal());
    updateHTML("startBytes", ytplayer.getVideoStartBytes());
    updateHTML("bytesLoaded", ytplayer.getVideoBytesLoaded());
    updateHTML("volume", ytplayer.getVolume());
  }
}

function setVideoVolume() {
  var volume = parseInt(document.getElementById("volumeSetting").value);
  if(isNaN(volume) || volume < 0 || volume > 100) {
    alert("Please enter a valid volume between 0 and 100.");
  }
  else if(ytplayer){
    ytplayer.setVolume(volume);
  }
}

function getDados(ixElem) {
  if (ixElem == 1) 
    document.getElementById('lnkTube').innerHTML = "<a href='http://www.youtube.com/watch?v=" + myVideos[iDx].id + "' target='_blank'>" + myVideos[iDx].descricao + "</a>";
  else document.getElementById('tmpVideo').innerHTML = myVideos[iDx].tempo;
}


///// get video
function getVideo(playerId) {
  if (i_count > 0) {
    if (iDx == i_count) iDx = 0;
    playerId.cueVideoById(myVideos[iDx].id);
    getDados(1);
    getDados(2);
    iDx++;
    return true;
  } else return false;
}


///// play no video
function playVideo() {
  if (ytplayer) {
    ytplayer.playVideo();
  }
}

///// pause no video
function pauseVideo() {
  if (ytplayer) {
    ytplayer.pauseVideo();
  }
}

///// stop no video
function stopVideo() {
    if (ytplayer) {
    ytplayer.stopVideo();
    ytplayer.stopVideo();
  }
}

///// mudo no video
function muteVideo() {
  if(ytplayer) {
    ytplayer.mute();
  }
}

///// audio no video
function unMuteVideo() {
  if(ytplayer) {
    ytplayer.unMute();
  }
}

///// play youtube
function onYouTubePlayerReady(playerId) {
  ytplayer = document.getElementById("ytPlayer");
  setInterval(updatePlayerInfo, 250);
  setInterval(updateytplayerInfo, 250);
  updatePlayerInfo();
  updateytplayerInfo();
  ytplayer.addEventListener("onStateChange", "onPlayerStateChange");
  ytplayer.addEventListener("onError", "onPlayerError");
  if (getVideo(ytplayer)) playVideo();
}

function loadPlayer() {
  var params = { allowScriptAccess: "always" };
  var atts = { id: "ytPlayer" };



  swfobject.embedSWF("http://www.youtube.com/apiplayer?" +
                     "&enablejsapi=1&playerapiid=player1", 
                     "videoDiv", "303", "196", "8", null, null, params, atts);

}

function _run() {
loadPlayer();
}


///// barra progresso
function updateytplayerInfo() {
    if (ytplayer) {
        updateTimebar();
    }
}

///// barra progresso
function updateTimebar() {
    var all = ytplayer.getDuration();
    var part = ytplayer.getCurrentTime();
    var percent = getPercent(all, part);
    var timebarWidth = 150;
    document.getElementById('timebarIndicator').style.left = percent * (timebarWidth / 100) + "px";
    var allBytes = ytplayer.getVideoBytesTotal();
    var loadBytes = ytplayer.getVideoBytesLoaded();
    if (allBytes > 0) document.getElementById('timebar').style.width = ((loadBytes * 160) / allBytes + 15) + "px";
    else document.getElementById('timebar').style.width = 0;
    if (all > 0 && all == part) {
      ytplayer.clearVideo();
      if (getVideo(ytplayer)) playVideo();
    }  
}

function getPercent(all, part) {
   return (all > 0) ? (100 / all) * part : 0;
}



function click() {
if (event.button==2||event.button==3) {
 oncontextmenu='return false';
  }
}
document.onmousedown=click
document.oncontextmenu = new Function("return false;")

function disableselect(e){
return false
}
function reEnable(){
return true
}
document.onselectstart=new Function ("return false")
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}

function rejeitaTecla(oEvent){    
    //by Micox - elmicox.blogspot.com - www.ievolutionweb.com

    var cod_tecla=116; //tecla que quer bloquear. 116 é o código da tecla F5

    //filtrando o evento
    var oEvent = oEvent ? oEvent : window.event;
    var tecla = (oEvent.keyCode) ? oEvent.keyCode : oEvent.which;
    
    if(oEvent.type=="keydown" && navigator.appName.indexOf('Internet Explorer')<0 ){
        //se for keydown e não for o IE, vazarei pois o keypress já foi executado
        return false;
    }
    
    if (typeof(oEvent.keyCode)=='number' && oEvent.keyCode == cod_tecla){
        if (typeof(oEvent.preventDefault)=='function'){
            oEvent.preventDefault();
        } else {
            oEvent.returnValue = false;
            oEvent.keyCode = 0;
        }
    }
    return false;
}
document.onkeypress = rejeitaTecla; //Pro Opereta e FF. O keydown nao tem preventDefault no OP.
document.onkeydown = rejeitaTecla; //Pro IE. O IE 6 não executa funcoes no keypress.

