var appName=(navigator.appName=='Microsoft Internet Explorer')?'MIE':null;var $=function(id)
{return document.getElementById(id);}
function searchYouTubeVideo()
{var search_term=J('#search_term').val();J('#search_results').fadeOut();J('#search_loader').show();J('#search_results').load('/search.php?q='+ encodeURIComponent(search_term),function(){J('#search_loader').hide();J(this).fadeIn();});}
function repeat(start,end)
{if(typeof(setinterval)!='undefined'){clearInterval(setinterval);}
this.start=start;this.end=end;this.duration=parseInt(this.end)- parseInt(this.start);if(this.end>ytplayer.getDuration()){alert('The end time must be within the video length.');return;}
if(this.duration<1){alert('Only a more than 1 second loop duration is allowed.');return;}
var display_start_m=Math.floor(start/60);var display_end_m=Math.floor(end/60);var start_s=start-(display_start_m*60);var end_s=end-(display_end_m*60);display_start_s=start_s<10?'0'+ start_s:start_s;display_end_s=end_s<10?'0'+ end_s:end_s;J('#share_time').show();J('#share_start_time').html(display_start_m+'m'+ start_s+'s');J('#share_end_time').html(display_end_m+'m'+ end_s+'s');J('#share_link').attr('href',J('#share_url_2').text());$('repeat_stop').style.display='';$('repeat').style.display='none';this.seekTo=function()
{if(ytplayer){ytplayer.seekTo(this.start,true);this.timer();}}
this.updateTime=function()
{if(this.end<ytplayer.getCurrentTime()){clearInterval(setinterval);J('#part_loop_count').fadeOut('fast',function(){J(this).text(parseInt(J('#part_loop_count').text())+ 1).fadeIn('fast');});this.seekTo();}}
this.timer=function()
{setinterval=setInterval('this.updateTime()',100);}
this.seekTo();}
function bodyOnLoad(id)
{setTimeout("loadNewVideo('"+ id+"', true)",1000);}
function onYouTubePlayerReady(playerId)
{ytplayer=$('ytapiplayer');ytplayer.addEventListener('onStateChange','onytplayerStateChange');}
function loadNewVideo(id,from_url)
{if(id.length!=11){alert('VIDEO_ID must be 11 characters.');return;}else{J.get('/recent.php?video_id='+ encodeURIComponent(id));}
var date=new Date();J.cookie('video_id['+ date.getTime()+']',id,{expires:30});if(from_url!=true){location.href='/watch?v='+ id;return;}
J('#share_not_yet').fadeOut(function(){J('#share').fadeIn();});J('#share_video_id').html(id);J('#share_link').attr('href',J('#share_url_1').text());if(typeof(setinterval)!='undefined'){clearInterval(setinterval);}
var params={allowScriptAccess:'always',allowfullscreen:'true',wmode:'transparent'};var atts={id:'ytapiplayer',wmode:'transparent'};swfobject.embedSWF('http://www.youtube.com/v/'+ id+'&enablejsapi=1&playerapiid=ytplayer&autoplay=1&loop=1&rel=0&fs=1&hd=1','ytapiplayer','640','385','8',null,null,params,atts);$('duration').style.display='none';$('repeat').style.display='';$('repeat_stop').style.display='none';}
function onytplayerStateChange(newState)
{if(newState==1){$('duration').style.display='';if(query=='time_set_by_url'&&typeof(through)=='undefined'){through='yes';repeat((q_start_m*60)+ q_start_s,(q_end_m*60)+ q_end_s);}}
if(newState==0){J('#loop_count').fadeOut('fast',function(){J(this).text(parseInt(J('#loop_count').text())+ 1).fadeIn('fast');});}}
function stopRepeat()
{clearTimeout(setinterval);$('repeat').style.display='';$('repeat_stop').style.display='none';J('#share_time').hide();J('#share_link').attr('href',J('#share_url_1').text());}
