	
	function openVideo(key) { 
	    
		jQuery.blockUI({ 
				message: $('#videoBox'),
				css: {  
				        padding:        '0', 
				        margin:         0, 
				        width:          '520px',  
				        top:            '100px',  
				        left:           '30%',  
				        textAlign:      'center',  
				        color:          '#000',  
				        border:         '0', 
				        backgroundColor:'#ffffff', 
				        cursor:         'auto' 
				    }
				}
		);
		$('.blockUI').bind('click', function() { $.unblockUI(); }); 
		$('.blockMsg').unbind('click');
		
		current_video = key;
		setVideo(key); 
		
	}
	
	



    function onYouTubePlayerReady(playerId) {
      //alert('go');
	  ytplayer = document.getElementById("myytplayer");
      ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
      ytplayer.addEventListener("onError", "onPlayerError");
	  ytplayer.unMute();
	  setVideoId(video_id);	
		
    }

    function onPlayerError(errorCode) {
      alert("An error occurred: "+ errorCode);
    }


    // functions for the api calls
    
	function playNext() {
		current_video++;
		if (current_video == 4) {
			current_video = 0
		}
		setVideo(current_video);
		onYouTubePlayerReady();
	}
	
	function playPrev() {
		current_video--;
		if (current_video == -1) {
			current_video = 3
		}
		setVideo(current_video);
		onYouTubePlayerReady();
		
	}
	
	
	
    

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

    function pause() {
      if (ytplayer) {
        ytplayer.pauseVideo();
      }
    }

    function stop() {
      if (ytplayer) {
        ytplayer.stopVideo();
      }
    }

    function mute() {
      
		if (ytplayer) {
		
			if (is_mute == 0) {
		    	ytplayer.mute();
				is_mute = 1;
	  		} else {
		    	ytplayer.unMute();
				is_mute = 0;
			}
      }
    }

    
	function setVideo(key) {
	      
		id = videos[key].video_id;
	
		var params	= { allowScriptAccess: "always" };
	    var atts		= { id: "myytplayer" };
	 	var swf		= 'http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer';
		
		swfobject.embedSWF(swf, "ytapiplayer", "480", "360", "8", null, null, params, atts);
		$('#videoTitle').text(videos[key].name);
	
		window.video_id = id;
	}
	
	function setVideoId(id) {
	      
		 if (ytplayer) {
            ytplayer.loadVideoById(id,0);
         }
	}
	
	
