﻿//Controlling Youtube Embed Player.
// needs: swfobject, player.js .... and maybe google jsapi

      // Update a particular HTML element with a new value
      function updateHTML(elmId, value) {
        document.getElementById(elmId).innerHTML = value;
      }
      
      // This function is called when an error is thrown by the player
      function onYTPlayerError(errorCode) {
          //alert("An error occured of type:" + errorCode);
          
      }
        
      // This function is called when the player changes state
      function onYTPlayerStateChange(newState) {
          //alert("playerState: " + newState);
          if (newState == 0) Play_Next(); //Parça sonuna ulaşıldıysa, sonrakine geçilsin
      }
      
      // This function is automatically called by the player once it loads
      function onYouTubePlayerReady(playerId) {
        ytplayer = document.getElementById("ytPlayer"); //id swfobject ile yüklemede belirleniyor
        ytplayer.addEventListener("onError", "onYTPlayerError");
        ytplayer.addEventListener("onStateChange", "onYTPlayerStateChange");
      }
      
      // The "main method" of this sample. Called when someone clicks "Run".
      function loadYTPlayer(pIDVideo, pIDElm) {
        // Lets Flash from another domain call JavaScript
        var params = { allowScriptAccess: "always", allowfullscreen: "true", wmode: "opaque"};

        // The element id of the Flash embed
        var atts = { id: "ytPlayer" };
        swfobject.embedSWF("http://www.youtube.com/v/" + pIDVideo + "?version=3&enablejsapi=1&playerapiid=player1&showinfo=0&autohide=1&autoplay=1&iv_load_policy=3&fs=1", 
                            pIDElm, mbPlayer.width, mbPlayer.height, "9", null, null, params, atts);
    }

    // Loads the selected video into the player.
    function changeVideo(pIDVideo) {
        if (window.ytplayer) {
            ytplayer.loadVideoById(pIDVideo);
        } else {
            loadPlayer(pIDVideo, "divPlayerBody");
        }

    }
      
    //  function _run() { loadPlayer();  }
   //   google.setOnLoadCallback(_run);
   
