google.load("swfobject", "2.1");

/*
 * Change out the video that is playing
 */

// Update a particular HTML element with a new value
function updateHTML(elmId, value) {
  document.getElementById(elmId).innerHTML = value;
}

// Loads the selected video into the player.
function loadVideo(videoID) {
   // Get the cookie for language
  var currentLanguage = getCookie(_soulmateLanguage);
   // If a language is not defined yet (no argument and no cookie), use the browser language
    if(currentLanguage == _frLang)
    {
       if(ytplayerFR == null) {
         onYouTubePlayerReady(null);
       }
       ytplayerFR.loadVideoById(videoID);
    }
    else
    {
        // Default is the english version
        if(ytplayerEN == null) {
          onYouTubePlayerReady(null);
        }
        ytplayerEN.loadVideoById(videoID);
    }
}

// This function is called when an error is thrown by the player
function onPlayerError(errorCode) {
  alert("An error occured of type:" + errorCode);
}

// This function is automatically called by the player once it loads
function onYouTubePlayerReady(playerId) {
  ytplayerFR = document.getElementById("soulmateVideoPlayerFR");
  ytplayerFR.addEventListener("onError", "onPlayerError");
  ytplayerEN = document.getElementById("soulmateVideoPlayerEN");
  ytplayerEN.addEventListener("onError", "onPlayerError");
}

// The "main method" of this sample. Called when someone clicks "Run".
function loadPlayer() {
  // The video to load
  var videoID = "0j3rWYSoW-o"
  // Lets Flash from another domain call JavaScript
  var params = { allowScriptAccess: "always", allowFullScreen: "true" };
  // The element id of the Flash embed
  var attsFR = { id: "soulmateVideoPlayerFR" };
  var attsEN = { id: "soulmateVideoPlayerEN" };

  // All of the magic handled by SWFObject (http://code.google.com/p/swfobject/)
  swfobject.embedSWF("http://www.youtube.com/v/" + videoID +
                     "&enablejsapi=1&playerapiid=player1",
                     "soulmate-videoFrDiv", "480", "295", "8", null, null, params, attsFR);

  swfobject.embedSWF("http://www.youtube.com/v/" + videoID +
                     "&enablejsapi=1&playerapiid=player1",
                     "soulmate-videoEnDiv", "480", "295", "8", null, null, params, attsEN);
}


google.setOnLoadCallback(loadPlayer);
