// JavaScript Document
// youtube chromless player control functions
// This script has been modifed with custom functions specialy for the requirements of kaveen.name
// (c)kaveen Perera 2010
function updateHTML(elmId,value){document.getElementById(elmId).innerHTML=value}function setytplayerState(newState){updateHTML("playerstate",newState)}function onYouTubePlayerReady(playerId){ytplayer=document.getElementById("myytplayer");setInterval(updateytplayerInfo,250);updateytplayerInfo();ytplayer.addEventListener("onStateChange","onytplayerStateChange");ytplayer.addEventListener("onError","onPlayerError")}function onytplayerStateChange(newState){setytplayerState(newState)}function onPlayerError(errorCode){if(errorCode==100){alert("Hey realx. Click one at a time")}else{void(0)}}function updateytplayerInfo(){loadProgress();getProgress();updateHTML("videoduration",getDuration());updateHTML("videotime",getCurrentTime());updateHTML("volume",getVolume());if(getPlayerState()==0){document.getElementById("play").style.backgroundImage="url(images/bt-play.png)"}}function loadNewVideo(id,title,dis,down){if(ytplayer){$("#port-dis").animate({"opacity":"0"},01);$("#port-title").animate({"opacity":"0"},01);ytplayer.loadVideoById(id,0);document.getElementById("play").style.backgroundImage="url(images/bt-pause.png)";changeTitle(title,dis,down)}}function cueNewVideo(id,startSeconds){if(ytplayer){ytplayer.cueVideoById(id,startSeconds)}}function play(){if(ytplayer){ytplayer.playVideo()}}function pause(){if(ytplayer){ytplayer.pauseVideo()}}function videoStop(){if(ytplayer){ytplayer.stopVideo();document.getElementById("play").style.backgroundImage='url(images/bt-play.png)'}}function getPlayerState(){if(ytplayer){return ytplayer.getPlayerState()}}function seekTo(seconds){myDuration=ytplayer.getDuration();totAmnt=ytplayer.getVideoBytesTotal();ldAmnt=ytplayer.getVideoBytesLoaded();a=Math.floor((totAmnt/150)*ldAmnt);mySeconds=(myDuration/150)*seconds;if(mySeconds<=a){if(ytplayer){ytplayer.seekTo(mySeconds,true)}}}function getCurrentTime(){if(ytplayer){myDuration=ytplayer.getCurrentTime();if(myDuration<=0){myMin=0;mySec=0}else{myMin=Math.floor(myDuration/60);mySec=Math.round(myDuration%60)};myDuration=myMin+":"+mySec;return myDuration}}function getDuration(){if(ytplayer){myDuration=ytplayer.getDuration();if(myDuration<=0){myMin=0;mySec=0}else{myMin=Math.floor(myDuration/60);mySec=Math.round(myDuration%60)};myDuration=myMin+":"+mySec;return myDuration}}function loadProgress(){myDuration=ytplayer.getVideoBytesTotal();myTime=ytplayer.getVideoBytesLoaded();oneStep=150/myDuration;currentStep=oneStep*myTime;function set_progress(){document.getElementById("loaded").style.width=currentStep+"px"}set_progress()}function getProgress(){myDuration=ytplayer.getDuration();myTime=ytplayer.getCurrentTime();oneStep=150/myDuration;currentStep=(oneStep*myTime);document.getElementById("cti").style.width=currentStep+"px"}function mute(){if(ytplayer){ytplayer.mute()}}function unMute(){if(ytplayer){ytplayer.unMute()}}function setVolume(newVolume){if(ytplayer){ytplayer.setVolume(newVolume)}i=1;j=newVolume/10;for(i=1;i<=j;i++){document.getElementById('vol-'+i).style.backgroundColor='#fff'};for(i=j+1;i<=10;i++){document.getElementById('vol-'+i).style.backgroundColor='#ffbacf'}}function getVolume(){if(ytplayer){return ytplayer.getVolume()}}function clearVideo(){if(ytplayer){ytplayer.clearVideo()}}
