function onYouTubePlayerReady(playerId) {
	ytplayer = document.getElementById("myytplayer");
	ytplayer.addEventListener("onError", "onPlayerError");
	//first_video = $('#list-videos ul li:first').attr('id');
	cueNewVideo(first_video);
}
function onPlayerError(errorCode) {
          alert("An error occured: " + errorCode);
  }

function loadNewVideo(id) {
  if (ytplayer) {
    ytplayer.loadVideoById(id, 0);
  }
}

function cueNewVideo(id) {
  if (ytplayer) {
    ytplayer.cueVideoById(id, 0);
  }
}

function play() {
  if (ytplayer) {
    ytplayer.playVideo();
  }
}

(function($){
	$.fn.init_viewer = function(){
				
	$('#list-videos ul li').each(function(){
		$(this).click(function(){
			loadNewVideo($(this).attr('id'));
			})
		});
	
	
	var params = { allowScriptAccess: "always", bgcolor: "#cccccc" };
    var atts = { id: "myytplayer" };    
    //http://www.youtube.com/apiplayer
    first_video = $('#list-videos ul li:first').attr('id');
	/*
    swfobject.embedSWF("http://www.youtube.com/v/"+first_video+"?enablejsapi=1&playerapiid=ytplayer=ytplayer",
                         "viewer", "500", "344", "8", null, null, params, atts);  
	*/				             
    swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer=ytplayer",
                         "viewer", "500", "344", "8", null, null, params, atts); 
	$('#stopvideo').click(function(){
							ytplayer.stopVideo();
							return false;								   
				   });
	$('#playvideo').click(function(){
							ytplayer.playVideo();
							return false;								   
				   });  	
	
}	
	
})(jQuery); 