// YouTube API Player Scripts

				var stopstart;
				var minutes;
				var totalSize;
				var totalDLSofar;
				var setSeekerAbli="";
			    var cmapvideo;
				 function onYouTubePlayerReady(setVideoID) {
					
      				cmapvideo = document.getElementById(setVideoPos);
					
					//cmapvideo.cueVideoById(videoID2);
					
					
					delayStart.startit();
				
					
    			} 
				
				var delayStart={
					startit:function(){
				        cmapvideo.addEventListener("onStateChange", "onytplayerStateChange");
					
					    minutes = Math.floor(cmapvideo.getDuration() / 60); 
						seconds = cmapvideo.getDuration() % 60; 
						if(seconds<=9){
							seconds=0+""+seconds;
							}
						//var curMinutes = Math.floor(cmapvideo.getCurrentTime() / 60);
						//var curSeconds = Math.floor(cmapvideo.getCurrentTime() % 60);
					
					$("#"+setVideoContainerID+" .timecounter").html(" / "+minutes+":"+seconds);
					$("#"+setVideoContainerID+" .timeCountCurrent").html("0:00");
					
					$("#"+setVideoContainerID+" .videoPositionBar").removeClass("hidden");
					
					totalSize=cmapvideo.getVideoBytesTotal();
					//$("#volumer").val(cmapvideo.getVolume());
					
					
					$("#"+setVideoContainerID+" .videoPositionBar").slider({animate:true,start: function(event, ui) { },
												stop: function(event, ui) {//alert(ui.value)
												
												setSeekerAbli=""; 
												//lefter=$(this).position(); 
												parentWS=$(this).parent().width(); 
												cakeulating="."+Math.floor(ui.value);
												updatedCakeulating=Math.floor(cmapvideo.getDuration()*cakeulating);
												//alert(updatedCakeulating);
												cmapvideo.seekTo(updatedCakeulating,true);
												
												},
												step: 5
												});
					
					
					$("#"+setVideoContainerID+" .volumeSliderJQ").slider({max:100,min:0,
												start: function(event, ui) { },
												stop: function(event, ui) {
													//alert(ui.value) 
													adjVolume(ui.value)
												},
												animate: true,
												step: 10,
												value: cmapvideo.getVolume()
												
												});
					}}
				
				function onytplayerStateChange(newState) {
					  /* alert("Player's new state: " + newState);
					   if(newState==1){
						   
						   }*/
						   
					switch(newState){
						case 1:
							stopstart=setTimeout("updateCurTime()",1000);
							clearTimeout(totalDLSofar);
							$("#"+setVideoContainerID+" .timeCountCurrent").removeClass("buffering");
							$("#"+setVideoContainerID+" .timeCountCurrent").removeClass("paused");
							
							$("#"+setVideoContainerID+" .videoPlayPauseButton").addClass("paused");
							$("#"+setVideoContainerID+" .videoPlayPauseButton").attr("href","javascript:pause()");
							break;
						case 2:
							clearTimeout(stopstart);
							clearTimeout(totalDLSofar);
							$("#"+setVideoContainerID+" .timeCountCurrent").removeClass("buffering");
							$("#"+setVideoContainerID+" .timeCountCurrent").addClass("paused");
							$("#"+setVideoContainerID+" .videoPlayPauseButton").removeClass("paused");
							$("#"+setVideoContainerID+" .videoPlayPauseButton").attr("href","javascript:play()");
							break;
						case 3:
							clearTimeout(stopstart);
							$("#"+setVideoContainerID+" .timeCountCurrent").addClass("buffering");
							$("#"+setVideoContainerID+" .timeCountCurrent").removeClass("paused");
							
							setTimeout("setTotaltime()",500);
							totalDLSofar=setTimeout("updateTotalDownloading()",1000);
							break;
						}
				}
				
				function updateCurTime(){
					
					var curMinutes = Math.floor(cmapvideo.getCurrentTime() / 60);
					var curSeconds = Math.floor(cmapvideo.getCurrentTime() % 60);
					if(curSeconds<10){
						curSeconds=0+""+curSeconds;
						}
					$("#"+setVideoContainerID+" .timeCountCurrent").html(curMinutes+":"+curSeconds);
					totalSize=totalSize.toString();
					if(totalSize==0){
							totalSize=cmapvideo.getVideoBytesTotal();
							totalSize=totalSize.toString();
					}
					totalDownloaded=cmapvideo.getVideoBytesLoaded();
					totalDownloaded=totalDownloaded.toString();
					totalLoaded=((totalDownloaded/totalSize)*100)-1;
					$("#"+setVideoContainerID+" .totalDownloaded").css({width:totalLoaded+"%"});//$(".totalDownloaded").html(totalLoaded)
					minutesTotalPer = ((cmapvideo.getCurrentTime() / cmapvideo.getDuration())*100)-2;
					$("#"+setVideoContainerID+" .videoPositionVis").css({width:minutesTotalPer+"%"});
					if(minutesTotalPer>0){
						if(setSeekerAbli==""){
							$("#"+setVideoContainerID+" .seeker").css({left:minutesTotalPer+"%"})
						}
					}
					stopstart=setTimeout("updateCurTime()",1000);
					}
					
				function updateTotalDownloading(){
					
					totalDownloaded=cmapvideo.getVideoBytesLoaded();
					totalDownloaded=totalDownloaded.toString();
					totalLoaded=((totalDownloaded/totalSize)*100);
					$("#"+setVideoContainerID+" .totalDownloaded").css({width:totalLoaded+"%"});
					totalDLSofar=setTimeout("updateTotalDownloading()",1000);
					}
				
				function play(){
					if(cmapvideo){
						
						//var curMinutes = Math.floor(cmapvideo.getCurrentTime() / 60);
						//var curSeconds = Math.floor(cmapvideo.getCurrentTime() % 60);
						
						$("#"+setVideoContainerID+" .videoPlayPauseButton").addClass("paused");
						$("#"+setVideoContainerID+" .videoPlayPauseButton").attr("href","javascript:pause()");
						cmapvideo.playVideo();
						
						updateCurTime();
						
					}
				}
				
				function setTotaltime(){
					minutes = Math.floor(cmapvideo.getDuration() / 60); 
					seconds = Math.floor(cmapvideo.getDuration() % 60); 
					if(seconds<10){
							seconds=0+""+seconds;
						}
					$("#"+setVideoContainerID+" .timecounter").html("&nbsp;/ "+minutes+":"+seconds);
				}
				
				function pause(){
					if(cmapvideo){
						cmapvideo.pauseVideo();
						$("#"+setVideoContainerID+" .videoPlayPauseButton").removeClass("paused");
						$("#"+setVideoContainerID+" .videoPlayPauseButton").attr("href","javascript:play()");
						
					}
				}
				
				function adjVolume(x){
					cmapvideo.setVolume(x);	
				}
				
				//var curVol=cmapvideo.getVolume();
				
				function mute(){
					testVPos=$("#"+setVideoContainerID+" .volumeSliderJQ a").position(); 
					if(cmapvideo.isMuted()==false){
						cmapvideo.mute();
						$("#"+setVideoContainerID+" .videoMuteUnmuteButton").addClass("muted");
					}else{
						cmapvideo.unMute();
						$("#"+setVideoContainerID+" .videoMuteUnmuteButton").removeClass("muted");
					}
				
				}
				
				
