﻿function onYouTubePlayerReady(playerId) {
	if (playerId && playerId != 'undefined') {
		var ytswf = document.getElementById('myytplayer');
		var isPlaying;
		
		 function play() {
			ytswf.playVideo();
		 }
		  
		  function pause() {
			ytswf.pauseVideo();
		 }
		  
		  function stop() {
			ytswf.stopVideo();
		 }
		ytswf.cueVideoById($("#videoThumbs .active a").attr("rel"), 1); 
  		
  		$('#videoPlayer img, #videoContent').click(function() {
  			if (isPlaying)
  			{
  				pause();
  				isPlaying = false;
  			}
  			else
  			{
				$(this).addClass('hideThis');
				play();
  				isPlaying = true;
  			}			  				
  		});
		
		$("#videoThumbs a").click(function() {
		    $('#videoThumbs li').removeClass('active');
		    $('#videoPlayer img').removeClass('active');
		    $(this).parent().addClass('active');
		    $('#videoPlayer img:eq(' + ($("#videoThumbs li").index($(this).parent())) + ')').removeClass('hideThis');
		    $('#videoPlayer img:eq(' + ($("#videoThumbs li").index($(this).parent())) + ')').addClass('active');
		    ytswf.cueVideoById($(this).attr("rel"), 1);
		    isPlaying = false;
		    return false;
		});
	}
}
