  var videoended = false;  var updatetimeout;  function updateHTML(elmId, value) {        // these elements are removed from this page    return false;    document.getElementById(elmId).innerHTML = value;  }  function setytplayerState(newState) {    updateHTML("playerstate", newState);  }  function onYouTubePlayerReady(playerId) {    ytplayer = document.getElementById("myytplayer");    updatetimeout = setInterval(updateytplayerInfo, 250);    updateytplayerInfo();    ytplayer.addEventListener("onStateChange", "onytplayerStateChange");    ytplayer.addEventListener("onError", "onPlayerError");  }  function onytplayerStateChange(newState) {    setytplayerState(newState);  }  function onPlayerError(errorCode) {    // movie does not exist    if (errorCode==100)    {      if (moviecodes.length>1)        nextMovie();    }        //alert("An error occurred: "+ errorCode);  }  function updateytplayerInfo()   {    updateHTML("bytesloaded", getBytesLoaded());    updateHTML("bytestotal", getBytesTotal());    updateHTML("videoduration", getDuration());    updateHTML("videotime", getCurrentTime());    updateHTML("startbytes", getStartBytes());    if (getDuration()>0 && getCurrentTime()>0 && getCurrentTime()>=getDuration() && !videoended)    {      videoended = true;      // show next movie      nextMovie()         }  }  // functions for the api calls  function play() {    if (ytplayer) {      ytplayer.playVideo();      $('option_play').hide();      $('option_pause').show();    }  }  function pause() {    if (ytplayer) {      ytplayer.pauseVideo();            $('option_pause').hide();      $('option_play').show();    }  }  function stop() {    if (ytplayer) {      ytplayer.stopVideo();    }  }  function getPlayerState() {    if (ytplayer) {      return ytplayer.getState();    }  }  function seekTo(seconds) {    if (ytplayer) {      ytplayer.seekTo(seconds, true);    }  }  function getBytesLoaded() {    if (ytplayer) {      return ytplayer.getVideoBytesLoaded();    }  }  function getBytesTotal() {    if (ytplayer) {      return ytplayer.getVideoBytesTotal();    }  }  function getCurrentTime() {    if (ytplayer) {      return ytplayer.getCurrentTime();    }  }  function getDuration() {    if (ytplayer) {      return ytplayer.getDuration();    }  }  function getStartBytes() {    if (ytplayer) {      return ytplayer.getVideoStartBytes();    }  }  function mute() {    if (ytplayer) {      ytplayer.mute();    }  }  function unMute() {    if (ytplayer) {      ytplayer.unMute();    }  }    var videoloaded = false;   var activemovie = 0;  function doMovie(code,title)  {    if (videoloaded)    {      clearTimeout(updatetimeout);      document.getElementById('ytapiplayer_container').innerHTML = '<div id="ytapiplayer" style="height:480px"></div>';    }        // allowScriptAccess must be set to allow the Javascript from one domain to access the swf on the youtube domain    var params = { allowScriptAccess: "always" };    // this sets the id of the object or embed tag to 'myytplayer'. You then use this id to access the swf and make calls to the player's API    var atts = { id: "myytplayer" };        swfobject.embedSWF("http://www.youtube.com/v/"+code+"&amp;rel=0&amp;autoplay=1&amp;border=0&amp;enablejsapi=1&amp;playerapiid=ytplayer",                        "ytapiplayer", "650", "480", "8", null, null, params, atts);       // display title of the movie    $('movietitle').innerHTML = title;       videoloaded = true;    videoended = false;                         // count movie view    // get title by ajax request    new Ajax.Request('/meandyou_stats.php?action=updatemoviecounter&id='+channelid+'&h='+moviehash,       {         method: 'GET'    	}    );           }  function nextMovie()  {    // calculate next movie code    var nextmovie = activemovie + 1;    if (nextmovie>moviecodes.length-1)    {      nextmovie = 0;    }         activemovie = nextmovie;        // show the movie    doMovie(moviecodes[nextmovie], movietitles[nextmovie]);  }