﻿

function onYouTubePlayerReady(playerId)
{
  var ytVideoID = $("#videoID").val();
  ytplayer = document.getElementById("flashVideoContainer");
  ytplayer.cueVideoById(ytVideoID, 0);
  $("#playController").click(function(){handle_play()});
  $("#pauseController").click(function(){handle_pause()});
  $("#restartController").click(function(){handle_restart()}); 
}

function handle_play()
{
    if(ytplayer)
        ytplayer.playVideo();
        
    return false;
}

function handle_pause()
{
    if(ytplayer)
        ytplayer.pauseVideo();
        
    return false;
}

function handle_restart()
{
    if(ytplayer)
    {
        ytplayer.seekTo(0, false);
        ytplayer.playVideo();
    }
    
    return false;
}

$(document).ready(function()
{
    var flashvars = {};
    var params = { swliveconnect:"true", allowScriptAccess: "always" };
    var attributes = { id:"flashVideoContainer", name:"flashVideoContainer" };
    var ytVideoHeight = $("#videoHeight").val();
    var ytVideoWidth = $("#videoWidth").val();

    $.swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer", "videoPlayer", ytVideoWidth, ytVideoHeight, "9.0.50.0", "/flash/expressinstall.swf", flashvars, params, attributes);
});
