function onYouTubePlayerReady(playerId) {
	youtube.pl = document.getElementById('myytplayer');
	
	youtube.cueNewVideo(youtube.v);
	
	youtube.pl.addEventListener("onStateChange", "youtube.onytplayerStateChange");
}

var youtube = {
	pl:false,
	v:'',
	state:-1,
	playVideo:false,
	loadNewVideo: function(id){
		this.v = id
		if(this.pl){
			this.pl.loadVideoById(id, 0);
		}
	},
	cueNewVideo: function(id){
		this.v = id
		if(this.pl){
			this.pl.cueVideoById(id, 0);
		}
	},
	onytplayerStateChange: function(fState){
		/* -1) empty, 0) ended, 1) playing, 2) paused, 3) buffering, 5) cued */

		this.state = fState;

		if(fState == 1){
			$('.video_control .play_pause').removeClass('pause');
		} else {
			$('.video_control .play_pause').addClass('pause');
		}

		switch(fState){
			case 0:
			case 1:
				$('.video_control .play_pause').addClass('pause');
				break;
			case 2:
				$('.video_control .play_pause').removeClass('pause');
				break;
			case 5:
				if(this.playVideo){
					this.play();
				}
				$('.video_control .play_pause').removeClass('pause');
				$('#youtube_screen').fadeIn('normal');
				break;
			default:
				$('#youtube_screen').fadeOut('normal');
		}
	},
	play: function(){
		this.playVideo = true;
		if(this.pl){
			this.pl.playVideo();
		}
	},
	pause: function(){
		this.playVideo = false;
		if(this.pl){
			this.pl.pauseVideo();
		}
	},
	play_pause: function(){
		switch(youtube.state){
			case -1: //reload
			case 0: //reload
			case 5: //reload
				this.play();
				break;
			case 1: //play
				this.pause();
				break;
			case 2: //pause
				this.play();
				break;
		}
	},
	stop: function(){
		this.playVideo = false;
		this.pl.stopVideo();
	},
	volume: function(fVolume){
		this.pl.setVolume(fVolume);
	},
	mute: function(){
		if(this.pl){
			this.pl.mute();
		}
	},
	seekTo: function(seconds){
		this.pl.seekTo(seconds, true);
	},
	clearVideo: function(){
		this.playVideo = false;
		this.pl.clearVideo();
	}
}
