var imgExt='gif';

var UT_RATING_IMG='icn_star_full_20x20'+imgExt;
var UT_RATING_IMG_HOVER='http://static.youtube.com/yt/img/star_hover-vfl2056.gif';
var UT_RATING_IMG_HALF='icn_star_half_20x20'+imgExt;
var UT_RATING_IMG_BG='icn_star_empty_20x20'+imgExt;
var UT_RATING_IMG_REMOVED='http://static.youtube.com/yt/img/star_removed-vfl2028.gif';

function UTRating(ratingElementId,maxStars,objectName,formName,ratingMessageId,componentSuffix,size,messages,starCount,callback)
{
	this.ratingElementId=ratingElementId;
	this.maxStars=maxStars;
	this.objectName=objectName;
	this.formName=formName;
	this.ratingMessageId=ratingMessageId
	this.componentSuffix=componentSuffix
	this.messages=messages;
	this.callback=callback;
	this.starTimer=null;
	this.starCount=0;
	if(starCount) {
		this.starCount=starCount;
		that=this;
		onLoadFunctionList.push(function(){that.drawStars(that.starCount,true);});
	}
	if(size=='S'){
		UT_RATING_IMG='icn_star_full_11x11gif'
		UT_RATING_IMG_HALF='icn_star_half_11x11gif'
		UT_RATING_IMG_BG='icn_star_empty_11x11gif'
	}
	
	function showStars(starNum,skipMessageUpdate){
		this.clearStarTimer();
		this.greyStars();
		this.colorStars(starNum);
		if(!skipMessageUpdate)
		this.setMessage(starNum,messages);
	}
	function setMessage(starNum){
		if(starNum>0){
			if(!this.savedMessage){
				this.savedMessage=document.getElementById(this.ratingMessageId).innerHTML;
			}
			document.getElementById(this.ratingMessageId).innerHTML=this.messages[starNum-1];
		}else if(this.savedMessage){
			document.getElementById(this.ratingMessageId).innerHTML=this.savedMessage;
		}
	}
	function colorStars(starNum){
		for(var i=0;i<starNum;i++){
			removeClass(document.getElementById('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG_HALF);
			removeClass(document.getElementById('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG_BG);
			addClass(document.getElementById('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG);
		}
	}
	function greyStars(){
		for(var i=0;i<this.maxStars;i++)
			if(i<=this.starCount){
				removeClass(document.getElementById('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG);
				removeClass(document.getElementById('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG_HALF);
				addClass(document.getElementById('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG_BG);
			}
			else
			{
				removeClass(document.getElementById('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG);
				removeClass(document.getElementById('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG_HALF);
				addClass(document.getElementById('star_'+this.componentSuffix+"_"+(i+1)),UT_RATING_IMG_BG);
			}
	}
	function setStars(starNum){
		this.starCount=starNum;
		this.drawStars(starNum);
		document.forms[this.formName]['rating'].value=this.starCount;
		var ratingElementId=this.ratingElementId;
		that=this;
		postForm(this.formName,this.ratingElementId,false);
	}
	function drawStars(starNum,skipMessageUpdate){
		this.starCount=starNum;
		this.showStars(starNum,skipMessageUpdate);
	}
	function clearStars(){
		this.starTimer=setTimeout(this.objectName+".resetStars()",300);
	}
	function resetStars(){
		this.clearStarTimer();
		if(this.starCount)
			this.drawStars(this.starCount);
		else
			this.greyStars();
		this.setMessage(0);
	}
	
	function clearStarTimer(){
		if(this.starTimer){
			clearTimeout(this.starTimer);
			this.starTimer=null;
		}
	}
	this.clearStars=clearStars;
	this.clearStarTimer=clearStarTimer;
	this.greyStars=greyStars;
	this.colorStars=colorStars;
	this.resetStars=resetStars;
	this.setStars=setStars;
	this.drawStars=drawStars;
	this.showStars=showStars;
	this.setMessage=setMessage;
}


function postForm(formName,successElement, loading)
{
	var form=document.forms[formName];
	return postFormByForm(form,successElement,loading);
}

function postFormByForm(form,successElement,loading){
	var formVars=new Array();
	for(var i=0;i<form.elements.length;i++)
	{
		var formElement=form.elements[i];
		if(formElement.type=='checkbox'&&!formElement.checked){
			continue;
		}
		var v=new Object;
		v.name=formElement.name;
		v.value=formElement.value;
		formVars.push(v);
	}
	
	var myAjax = new Ajax.Updater(
		{success: successElement}, 
		form.action, 
		{
			method: 'post', 
			parameters: urlEncodeDict(formVars),
			evalScripts: true
		});
}

function urlEncodeDict(dict)
{
	var result="";
	for(var i=0;i<dict.length;i++){
		result+="&"+encodeURIComponent(dict[i].name)+"="+encodeURIComponent(dict[i].value);
	}
	return result;
}
/*
ratingHoverTimers=[]
function ratingHoverOver(componentSuffix){
if(componentSuffix==""){
componentSuffix=="reserved"
}
_clearHoverTimer(componentSuffix);
hideDiv('defaultRatingMessage'+componentSuffix);
showDiv('hoverMessage'+componentSuffix);
}
function ratingHoverOut(componentSuffix){
if(componentSuffix==""){
componentSuffix=="reserved"
}
ratingHoverTimers[componentSuffix]=setTimeout(function(){_ratingHoverClear(componentSuffix);},300);
}
function _ratingHoverClear(componentSuffix){
if(componentSuffix==""){
componentSuffix=="reserved"
}
_clearHoverTimer();
hideDiv('hoverMessage');
showDiv('defaultRatingMessage');
}
function _clearHoverTimer(componentSuffix){
if(componentSuffix==""){
componentSuffix=="reserved"
}
if(ratingHoverTimers[componentSuffix]){
clearTimeout(ratingHoverTimers[componentSuffix]);
ratingHoverTimers[componentSuffix]=null;
}
}
function approveComment(comment_id,comment_type,entity_id,token)
{
if(CheckLogin()==false)
return false;
postUrlXMLResponse("/comment_servlet","&field_approve_comment=1&comment_id="+comment_id+"&comment_type="+comment_type+"&entity_id="+entity_id+"&"+token,self.commentApproved);
return false;
}
function removeComment(div_id,deleter_user_id,comment_id,comment_type,entity_id,token)
{
self.div_id=div_id
self.commentRemoved=commentRemoved
if(CheckLogin()==false)
return;
postUrlXMLResponse("/comment_servlet","deleter_user_id="+deleter_user_id+"&remove_comment&comment_id="+comment_id+"&comment_type="+comment_type+"&entity_id="+entity_id+"&"+token,self.commentRemoved);
return false;
}
function commentRemoved(xmlHttpRequest)
{
toggleVisibility(self.div_id,false);
return;
}
function hideCommentReplyForm(form_id){
var div_id="div_"+form_id;
var reply_id="reply_"+form_id;
toggleVisibility(reply_id,true);
toggleVisibility(div_id,false);
}
function handleStateChange(xmlHttpReq){
document.getElementById("all_comments_content").innerHTML=getNodeValue(xmlHttpReq.responseXML,"html_content");
style2=document.getElementById("recent_comments").style;
style2.display="none";
var style2=document.getElementById("all_comments").style;
style2.display="";
}
function showAjaxDivLoggedIn(divName,url){
getUrlXMLResponse(url,showAjaxDivResponseLater(divName));
}
function showAjaxPostDivLoggedIn(divName,url,data,callback){
postUrlXMLResponse(url,data,showAjaxDivResponseLater(divName,callback));
}
function showAjaxDiv(divName,url){
if(isLoggedIn){
showAjaxDivLoggedIn(divName,url)
}else{
alert(MSG_Login);
}
}
function showAjaxPostDiv(divName,url,data){
if(isLoggedIn){
showAjaxPostDivLoggedIn(divName,url,data)
}else{
alert(MSG_Login);
}
}
function showAjaxDivResponseLater(divName,callback){
return function(req){
_gel(divName).innerHTML=getNodeValue(req.responseXML,"html_content");
if(callback){
callback();
}
};
}
function showAjaxDivResponse(req,divName){
_gel(divName).innerHTML=getNodeValue(req.responseXML,"html_content");
openDiv(divName);
}
function postAjaxForm(divName,formName,successCallback){
postFormXMLResponse(formName,closeAjaxDivLater(divName,successCallback));
}
function closeAjaxDivLater(divName,successCallback){
return function(req){
closeDiv(divName);
if(successCallback){
successCallback();
}
}
}
var first_time=1;
function changeBanner(img_url,ref_url,is_flash){
var e=_gel("gad_leaderboardAd");
if(first_time)
{
e.style.height="90px";
first_time=0;
}
var url="";
if(is_flash=="true")
{
url+="<object width='72"+"8' height='9"+"0'>";
url+="<"+"param value='clickTAG="+encodeURIComponent(ref_url)+"' /"+">";
url+="<"+"embed src='"+img_url+"'";
url+=" type='application/x-shockwave-flash' wmode='transparent'";
url+=" flashvars='clickTAG="+encodeURIComponent(ref_url)+"'";
url+=" width='72"+"8' height='9"+"0' /"+">";
url+="</object>";
}
else
{
url="<"+"a href='"+ref_url+"' target='_blank'>";
url+="<img src='"+img_url+"'>";
url+="</a>";
}
e.innerHTML=url;
}
function actionOver(div){
div.className='actionOver';
}
function actionOut(div){
div.className='actionRow';
}
function actionClick(div){
div.className='actionClicked';
}
function actionOverBottom(div){
div.className='actionOverBottom';
}
function actionOutBottom(div){
div.className='actionRowBottom';
}
function actionClickBottom(div){
div.className='actionClickedBottom';
}
function closeDisplay(div){
if(_gel(div)){
_gel(div).style.display="none";
}
}
function shareVideoFromFlash(){
shareVideo(pageVideoId);
smoothScrollIntoView(_gel("shareVideoDiv"),20);
}
function closeAll(except){
var divs=['addToFavesDiv','addToPlaylistDiv','shareVideoDiv','inappropriateVidDiv','customizeEmbedDiv','shareVideoEmailDiv','loginPleaseDiv','reportConcernResult1','reportConcernResult2','reportConcernResult3','reportConcernResult4','reportConcernResult5'];
for(var i=0;i<divs.length;i++){
if((divs[i]!=except)&&(_gel(divs[i]))){
var theDiv=_gel(divs[i]);
if(theDiv){
theDiv.style.display="none";
}
}
}
}
function postResponse(){
if(isLoggedIn){
closeAll('postResponseDiv');
toggleDisplay('postResponseDiv');
}
else
{
alert(MSG_LoginPostResponse);
}
}
function closeAfter(divName,delay){
setTimeout(function(){
closeDisplay(divName)
},delay);
}
function postResponseClose(){
toggleDisplay('postResponseDiv');
toggleDisplay('postResponseResult');
closeAfter('postResponseResult',3000);
}
function customizeEmbed(){
closeAll('customizeEmbedDiv');
toggleDisplay('customizeEmbedDiv');
}
function loginPlease(){
closeAll('loginPleaseDiv');
toggleDisplay('loginPleaseDiv');
if(_gel('loginPleaseDiv').style.display=="block"){
_gel('loginPleaseUser').focus();
}
}
function addToFaves(formName){
if(isLoggedIn){
closeAll('addToFavesResult');
toggleDisplay('addToFavesResult');
postAjaxForm('addToFavesDiv',formName);
_hbLink('Save+To+Favorites','Watch3');
setTimeout("closeDisplay('addToFavesResult')",3000);
}
else{
loginPlease();
}
}
var gWatchLoading='';
function addToPlaylist(videoId){
if(isLoggedIn){
if(!gWatchLoading){
gWatchLoading=_gel('addToPlaylistDiv').innerHTML;
}else{
_gel('addToPlaylistDiv').innerHTML=gWatchLoading;
}
closeAll('addToPlaylistDiv');
if(toggleDisplay('addToPlaylistDiv')){
showAjaxDivLoggedIn('addToPlaylistDiv','/watch_ajax?video_id='+videoId+'&action_get_new_playlists_component=1',true);
_hbLink('Add+To+Playlists','Watch3');
}
}
else{
loginPlease();
}
}
function submitToBlog(self){
_gel('submitToBlogBtn').disabled=true;
postAjaxForm('shareVideoDiv',self.name,addToBlogClose);
}
function addToBlogClose(){
toggleDisplay('addToBlogResult');
closeAfter('addToBlogResult',3000);
_gel('submitToBlogBtn').disabled=false;
}
function submitToPlaylist(self){
if(!self.form.playlist_id.value){
return;
}
self.disabled=true;
postAjaxForm('addToPlaylistDiv',self.form.name,addToPlaylistClose);
}
function addToPlaylistClose(){
toggleDisplay('addToPlaylistResult');
closeAfter('addToPlaylistResult',3000);
}
function reportConcern(videoId){
if(isLoggedIn){
closeAll('inappropriateVidDiv');
if(toggleDisplay('inappropriateVidDiv')){
if(_gel('inappropriateVidDiv').innerHTML.indexOf('<div')!=-1){
return;
}
showAjaxDivLoggedIn('inappropriateVidDiv','/watch_ajax?video_id='+videoId+'&action_get_flag_video_component=1',true);
_hbLink('Flag+Inappropriate','Watch3');
}
}
else{
loginPlease();
}
}
function reportConcernClose(){
toggleDisplay('inappropriateVidDiv');
toggleDisplay('reportConcernResult');
closeAfter('reportConcernResult',3000);
}
function shareVideo(videoId){
closeAll('shareVideoDiv');
toggleDisplay('shareVideoDiv');
if(_gel('shareVideoDiv').style.display!="none"){
if(this.loaded===undefined){
showAjaxDivLoggedIn('shareVideoDiv','/watch_ajax?video_id='+videoId+'&action_get_share_video_component=1',true);
this.loaded=true;
}
_hbLink('Share+Video','Watch3');
}
}
function shareVideoEmail(videoId){
toggleDisplay('shareVideoEmailDiv');
}
function shareVideoClose(){
toggleDisplay('shareVideoDiv');
toggleDisplay('shareVideoResult');
closeAfter('shareVideoResult',3000);
}
function shareWorld(){
closeAll('shareWorldDiv');
toggleDisplay('shareVideoDiv');
toggleDisplay('shareWorldDiv');
}
function shareWorldClose(){
toggleDisplay('shareWorldDiv');
toggleDisplay('shareWorldResult');
setTimeout("closeDisplay('shareWorldResult')",3000);
}
function embedIt(){
closeAll('embedItDiv');
toggleDisplay('embedItDiv');
}
function showHonorsContent(){
getAndShowNavContent('honors',honorsLink);
}
function writeMoviePlayer(player_div,force){
var v="7";
if(force)
v="0";
var fo=new SWFObject(swfUrl,"movie_player","480","395",v,"#FFFFFF");
fo.addParam("allowFullscreen","true");
for(var x in swfArgs){
fo.addVariable(x,swfArgs[x]);
}
if(watchSourceId){
fo.addVariable("sourceid",watchSourceId);
}
if(watchSourceDetail){
fo.addVariable("sdetail",watchSourceDetail);
}
if(watchQuery){
fo.addVariable("q",watchQuery);
}
if(watchPlayerTrackingId){
fo.addVariable("plid",watchPlayerTrackingId);
}
if(watchGamUrl!=null){
fo.addVariable("gam",watchGamUrl);
}
if(watchDCUrl!=null){
fo.addVariable("ad_tag",watchDCUrl);
}
if(!watchIsPlayingAll){
fo.addVariable("playnext",0);
}
if(watchSetWmode){
fo.addParam("wmode","opaque");
}
player_written=fo.write(player_div);
}
function setSWFVersion(version_from_swf)
{
if(watchTrackWithHitbox){
_hbPageView("WatchSWFTracker/"+player_written,"FlashTracker3");
}
if(!player_written)
writeMoviePlayer("playerDiv",true);
}
function closeFullStats(){
toggleDisplay('fullStats');
if(_gel('showhide')){
_gel('showhide').innerHTML='Show';
}
}
function toggleLinkStats(){
if(_gel('fullStats').style.display!='none'&&_gel('fullStats').style.display){
toggleDisplay('fullStats');
}
toggleDisplay('linkStats');
}
function toggleFullStats(statsContent){
if(statsContent===undefined){
statsContent='honors';
ajaxUrl=additionalStatsHonorsUrl;
_gel('referDiv').style.display='block';
}
else if(statsContent=='audio'){
ajaxUrl=additionalStatsAudioUrl;
_gel('referDiv').style.display='none';
}
var fsd=_gel('fullStats').style.display;
if(fsd=='none'||fsd==''){
showAjaxDivLoggedIn('additionalStatsDiv',ajaxUrl,false);
if(statsContent=='audio'){
_gel('showhide').innerHTML=MSG_Hide;
}
if(_gel('linkStats').style.display!='none'&&_gel('linkStats').style.display){
toggleDisplay('linkStats');
}
toggleDisplay('fullStats');
}
else
{
if(((statsContent=='honors'&&_gel('audioStatHead'))||(statsContent=='audio'&&_gel('honorStatHead'))))
{
showAjaxDivLoggedIn('additionalStatsDiv',ajaxUrl,false);
if(statsContent=='honors'){
_gel('showhide').innerHTML=MSG_Show;
}
else if(statsContent=='audio'){
_gel('showhide').innerHTML=MSG_Hide;
}
}
else
{
toggleDisplay('fullStats');
if(statsContent=='audio'){
_gel('showhide').innerHTML=MSG_Show;
}
}
}
}
function showAllQueuedVideos(){
setInnerHTML('show_all_queued_videos_div',MSG_Loading);
getAndShowNavContent('watchlist_container',watchlistContainerUrl,postShowAllQueuedVideos);
}
function postShowAllQueuedVideos(){
setInnerHTML('show_all_queued_videos_div',MSG_ShowingAll);
jumpToNowPlaying();
}
function openFull(){
var fs=window.open(fullscreenUrl,
"FullScreenVideo","toolbar=no,width="+screen.availWidth+",height="+screen.availHeight
+",status=no,resizable=yes,fullscreen=yes,scrollbars=no");
fs.focus();
}
function isCurrentlyPlayingVideoInPlaylist(component){
var videosInPlaylist=getPlaylistVideoCount(component);
for(i=0;i<videosInPlaylist;i++){
var currentRow=_gel(getId('playlistRow',playnextFrom,i));
if(hasClass(currentRow,'playlistRowPlaying')){
return true;
}
}
}
function gotoNext(){
if(playnextFrom){
var nextRow=_gel(getId("playlistRow",playnextFrom,0));
var videosInPlaylist=getPlaylistVideoCount(playnextFrom);
for(i=0;i<videosInPlaylist;i++){
var currentRow=_gel(getId('playlistRow',playnextFrom,i));
if(hasClass(currentRow,'playlistRowPlaying')){
if(i+1<videosInPlaylist){
nextRow=_gel(getId('playlistRow',playnextFrom,i+1));
}else{
nextRow=null;
}
break;
}
}
if(nextRow){
window.location=getUrlFromPlaylistRow(nextRow)+"&playnext="+(parseInt(playnextCount)+1)+"&playnext_from="+playnextFrom;
}
}
}
var autoNextComponents=['PL','QL'];
function autoNext(suffix){
playnextFrom=suffix;
for(var i=0;i<autoNextComponents.length;i++){
if(autoNextComponents[i]==suffix){
showDiv(getId("playingall",autoNextComponents[i]));
hideDiv(getId("playall",autoNextComponents[i]));
}else{
hideDiv(getId("playingall",autoNextComponents[i]));
showDiv(getId("playall",autoNextComponents[i]));
}
}
var p=_gel("movie_player");
if(p.GetVariable("movie.is_playing")=="false"&&p.GetVariable("movie.restart")=="true"){
gotoNext();
}else if(!isCurrentlyPlayingVideoInPlaylist(suffix)){
gotoNext();
}else{
p.SetVariable("playnext","1");
}
return false;
}
function autoNextOff(suffix){
playnextFrom="";
_gel("movie_player").SetVariable("playnext","0");
showDiv(getId("playall",suffix));
hideDiv(getId("playingall",suffix));
return false;
}
function CheckLogin(){
return isLoggedIn;
}
function getId(baseId,component,index){
var id=baseId;
if(component!=null)
id+="_"+component;
if(index!=null)
id+="_"+index;
return id;
}
function onQuickAddClick(imgClicked,encryptedId){
imgClicked.onclick=null;
imgClicked.blur();
var suffix='QL';
var videosInPlaylist=getPlaylistVideoCount(suffix);
var alreadyInList=false;
for(var i=0;i<videosInPlaylist;i++){
var videoRow=_gel(getId("playlistRow",suffix,i));
if(encryptedId==getNodeVideoId(videoRow)){
alreadyInList=true;
break;
}
}
if(!alreadyInList){
var newRow=_gel("playlistRow_placeholder_QL").cloneNode(true);
var videoCount=getPlaylistVideoCount("QL");
fillQuicklistRow(newRow,videoCount,"","http://static.youtube.com/yt/img/pixel-vfl73.gif",MSG_Loading,"","");
removeClass(newRow,"hide");
setNodeVideoId(newRow,encryptedId);
addClass(newRow,"loading");
var rows=_gel("playlistRows_QL");
var lastRow=_gel(getId('playlistRow','QL',videoCount-1));
if(lastRow){
rows.insertBefore(newRow,lastRow.nextSibling);
}else{
rows.insertBefore(newRow,rows.firstChild);
}
scrollPlaylistToVideo('QL',videoCount);
if(incrementPlaylistVideoCount('QL',1)>4){
var containerNode=_gel(getId("playlistContainer",'QL'));
removeClass(containerNode,"autoHeight");
addClass(containerNode,"fixedHeight175");
}
}
clickedQuickAdd(imgClicked,encryptedId,alreadyInList);
_hbLink('QuickList+AddTo','Watch3');
showDiv('quicklistDiv');
return false;
}
function showPlaylist(component){
showDiv(getId("playlistOpen",component));
hideDiv(getId("playlistClosed",component));
return false;
}
function hidePlaylist(component){
showDiv(getId("playlistClosed",component));
hideDiv(getId("playlistOpen",component));
return false;
}
var delayLoadRegistry=[];
var delayLoadCompleted=[];
function delayLoad(id,img,src){
delayLoadRegistry[delayLoadRegistry.length]=[id,img,src];
delayLoadCompleted[id]=false;
}
function performDelayLoad(id){
if(!delayLoadCompleted[id]){
delayLoadCompleted[id]=true;
for(var i=0;i<delayLoadRegistry.length;i++){
if(delayLoadRegistry[i][0]==id){
delayLoadRegistry[i][1].onload="";
delayLoadRegistry[i][1].src=delayLoadRegistry[i][2];
}
}
}
}
var showAjaxDivNotLoggedIn=showAjaxDivLoggedIn;
function hideLinkingSitesCallback(){
hideDiv('referersList');
hideInline('hideLinkingSites');
showInline('showLinkingSites');
showInline('linkingSitesDisabled');
}
function hideLinkingSites(){
postUrlXMLResponse('/watch_ajax','action_hide_linking_sites=1&video_id='+pageVideoId+'&'+axc,hideLinkingSitesCallback);
return false;
}
function showLinkingSites(){
hideInline('linkingSitesDisabled');
showInline('hideLinkingSites');
hideInline('showLinkingSites');
showAjaxPostDivLoggedIn('referersList','/watch_ajax','action_show_linking_sites=1&video_id='+pageVideoId+'&'+axc);
return false;
}
function toggleChannelVideos(username){
toggleClass('channel_videos_full','hide');
if(!_gel('more_channel_videos')){
showAjaxDivLoggedIn('channel_videos_full','/watch_ajax?user='+username+'&action_channel_videos');
}
return false;
}
function showRelatedAsList(){
setInnerHTML('relatedVidsBody',MSG_Loading);
showAjaxDivLoggedIn('relatedVidsBody',relatedVideoListUrl);
showInline("relatedList");
hideInline("relatedNotList");
showInline("relatedNotGrid");
hideInline("relatedGrid");
return false;
}
function showRelatedAsGrid(){
setInnerHTML('relatedVidsBody',MSG_Loading);
showAjaxDivLoggedIn('relatedVidsBody',relatedVideoGridUrl);
hideInline("relatedList");
showInline("relatedNotList");
hideInline("relatedNotGrid");
showInline("relatedGrid");
return false;
}
var defaultRecipientFieldCount=2;
var recipientFieldNamePrefix="recipient";
var recipientFieldCount=defaultRecipientFieldCount;
var lastRecipientFieldId=recipientFieldNamePrefix+recipientFieldCount;
var maxRecipients=10;
function addRecipientFieldIfNeeded(field){
if(field.id==lastRecipientFieldId&&recipientFieldCount<maxRecipients){
newField=field.cloneNode(true);
recipientFieldCount++;
lastRecipientFieldId=recipientFieldNamePrefix+recipientFieldCount;
newField.id=lastRecipientFieldId;
newField.name=lastRecipientFieldId;
_gel('recipients').appendChild(newField);
}
}
function resetRecipients(){
recipientFieldCount=defaultRecipientFieldCount;
lastRecipientFieldId=recipientFieldNamePrefix+recipientFieldCount;
}
function consolidateRecipients(){
hiddenRecipientsField=_gel('recipients');
for(var i=1;i<=recipientFieldCount;i++){
hiddenRecipientsField.value+=(_gel(recipientFieldNamePrefix+""+i).value+",");
}
}
function readCookie(name,fallback){
var nameEQ=name+"=";
var ca=document.cookie.split(';');
for(var i=0;i<ca.length;i++){
var c=ca[i];
while(c.charAt(0)==' ')c=c.substring(1,c.length);
if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);
}
if(fallback){
return fallback;
}else{
return null;
}
}
function readIntCookie(name){
val=readCookie(name);
if(val){
return parseInt(val);
}else{
return 0;
}
}
function createCookie(name,value,days){
if(days){
var date=new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires="; expires="+date.toGMTString();
}
else var expires="";
document.cookie=name+"="+value+expires+"; path=/";
}
function eraseCookie(name){
createCookie(name,"",-1);
}
SHARED_RATINGS_INVITE_SHOW_MAX=5
SHARED_RATINGS_INVITE_REJECT_MAX=2
function displayRecentRatingsInvite(){
if(!readCookie("stop_shared_ratings_invite")){
showDiv("recentRatingsInvite");
var timesShown=parseInt(readCookie("shared_ratings_invite_shown","0"));
timesShown=timesShown+1;
createCookie("shared_ratings_invite_shown",timesShown);
if(timesShown>=SHARED_RATINGS_INVITE_SHOW_MAX){
createCookie("stop_shared_ratings_invite","1");
}
}
}
SHARED_RATINGS_INVITE_SHOW_MAX=5
function rejectRecentRatings(){
var timesRejected=parseInt(readCookie("shared_ratings_invite_rejected","0"));
timesRejected=timesRejected+1;
createCookie("shared_ratings_invite_rejected",timesRejected);
if(timesRejected>=SHARED_RATINGS_INVITE_REJECT_MAX){
createCookie("stop_shared_ratings_invite","1");
}
}
function subscribe(username,token){
postUrlXMLResponse('/ajax_subscriptions','subscribe_to_user='+username+'&session_token='+token,function(result){removeClass(_gel('unsubscribeDiv'),'hid');addClass(_gel('subscribeDiv'),'hid');});
}
function unsubscribe(username,token){
postUrlXMLResponse('/ajax_subscriptions','unsubscribe_from_user='+username+'&session_token='+token,function(){removeClass(_gel('subscribeDiv'),'hid');addClass(_gel('unsubscribeDiv'),'hid');});
}
function flagError(elName,errorText){
if(elName){
_gel(elName).innerHTML=errorText;
toggleDisplay(elName);
}
}
function clearSelectionStyles(elName){
if(elName){
elName.style.backgroundColor='';
elName.style.color='';
}
}
function setSelectionStyles(elName){
if(elName){
elName.style.backgroundColor='#6681ba';
elName.style.color='#fff';
}
}
function flagReasonSelection(selID,reason,subreason){
var selCurrent=_gel('selectedFlagReason')
var selNew=_gel(selID);
if(_gel('flag_id').value){
clearSelectionStyles(_gel(_gel('flag_id').value));
clearSelectionStyles(_gel((_gel('flag_id').value).substring(0,2)));
}
setSelectionStyles(selNew);
if(selID.length==5){
setSelectionStyles(_gel(selID.substring(0,2)));
}
_gel('flag_reason').value=reason;
_gel('flag_sub_reason').value=subreason;
_gel('flag_id').value=selID;
selCurrent.innerHTML=_gel(selID).innerHTML;
setVisible('flag_'+selID.substring(0,2),false);
setVisible('flag_main',false);
closeAllFlagMoreInfo();
}
function closeAllFlagMoreInfo(){
var divs=['flagMoreInfo1','flagMoreInfo2','flagMoreInfo3','flagMoreInfo4','flagMoreInfo5','flagMoreInfo6','flagError'];
for(var i=0;i<divs.length;i++){
var theDiv=_gel(divs[i]);
if(theDiv){
theDiv.style.display='none';
}
}
}
function processFlagForm(elForm){
var formElement=elForm;
if(formElement){
var sel=formElement.flag_id.value;
if(sel){
if(sel=='hc_hv'){
if(formElement.protected_group.options[formElement.protected_group.selectedIndex].value!=''){
toggleDisplay('reportConcernResult3');
}
else{
toggleDisplay('flagError');
return;
}
}
else if(sel=='vc_af'||sel=='sc_su'){
toggleDisplay('reportConcernResult2');
}
else{
toggleDisplay('reportConcernResult1');
}
postAjaxForm('inappropriateVidDiv',elForm.name);
_gel('selectedFlagReason').innerHTML='- '+MSG_FlagDefault+' -';
if(_gel('flag_id').value){
clearSelectionStyles(_gel(_gel('flag_id').value));
clearSelectionStyles(_gel((_gel('flag_id').value).substring(0,2)));
_gel('flag_id').value='';
}
closeAllFlagMoreInfo();
toggleDisplay('inappropriateVidDiv');
}
else{
toggleDisplay('flagError');
}
}
}
function hideLinkingSiteCallback(){
hideInline('referersList');
showInline('referersList');
}
function hideLinkingSite(video_id,site){
showAjaxPostDivLoggedIn('referersList','/watch_ajax','action_hide_linking_site=1&video_id='+video_id+'&url='+site+'&'+axc,hideLinkingSiteCallback);
return false;
}
function showLinkingSite(video_id,site){
showAjaxPostDivLoggedIn('referersList','/watch_ajax','action_show_linking_site=1&video_id='+video_id+'&url='+site+'&'+axc,hideLinkingSiteCallback);
return false;
}
function checkCurrentVideo(videoId)
{
if(pageVideoId!=videoId){
window.location.href="/watch?v="+video_id;
}
}
var videolist=new Array();
var removelist=new Array();
var qlUIEnabled=false;
function initWatchQueue(isUIEnabled){
qlUIEnabled=isUIEnabled;
}
function clearWatchQueue(){
postUrlXMLResponse("/watch_queue_ajax","&action_clear_queue",queueCleared);
var suffix="QL";
var videosInPlaylist=getPlaylistVideoCount(suffix);
decrementPlaylistVideoCount(suffix,videosInPlaylist);
for(var i=videosInPlaylist-1;i>=0;i--){
var videoRow=_gel(getId("playlistRow",suffix,i));
videoRow.parentNode.removeChild(videoRow);
}
var container=_gel(getId("playlistContainer",suffix));
addClass(container,"autoHeight");
removeClass(container,"fixedHeight175");
videolist=new Array();
removelist=new Array();
for(var i=0;i<quickAddDoneList.length;i++){
removeClass(quickAddDoneList[i],'QLIconImgOver');
removeClass(quickAddDoneList[i],'QLIconImgDone');
addClass(quickAddDoneList[i],'QLIconImg');
}
quickAddDoneList=new Array();
hideDiv("quicklistDiv");
}
function remove_from_watch_queue(video_id){
removelist.push(video_id);
delete_videos_from_server();
return false;
}
function set_pop_status(pop_status){
postUrlXMLResponse("/watch_queue_ajax","action_set_pop_status&pop_videos="+pop_status,self.popStatusSet)
}
function popStatusSet(){
}
var qlIsEditing=false;
function post_videos_to_server(){
if(videolist.length>0&&!qlIsEditing){
qlIsEditing=true;
var queryParams="&action_add_to_queue&video_id="+videolist.shift();
if(qlUIEnabled){
queryParams+="&ui=1"
}
var request=new getUrlXMLResponseJSON("/watch_queue_ajax?"+queryParams,videoQueued);
}
}
var isRemoving=false;
function delete_videos_from_server(){
if(removelist.length>0){
isRemoving=true;
postUrlXMLResponse("/watch_queue_ajax","&action_remove_from_queue&video_id="+removelist[removelist.length-1],self.videoRemoved);
removelist.pop();
}
isRemoving=false;
if(delayedCompletePlaylistLoad){
completePlaylistLoad();
}
}
function queueCleared(xmlHttpRequest){
}
function queueClearedReloadPage(xmlHttpRequest){
window.location="watch_queue?all";
}
function videoQueued(videos){
qlIsEditing=false;
if(qlUIEnabled){
if(videos){
handleWatchQueueGet(videos);
}
}
post_videos_to_server();
}
function videoRemoved(xmlHttpRequest){
delete_videos_from_server();
}
function clicked_add_icon(video_ID,fromRelated){
if(fromRelated==1){
showQuickList_first_add();
_gel('play_all_numb').innerHTML=quicklist_count+'&nbsp;';
if(_gel('show_all_video_number')){
_gel('show_all_video_number').innerHTML=quicklist_count;
}
}
_gel(button_name).blur();
}
var autoScrolledTo=null;
function scrollPlaylistToVideo(suffix,index){
var videoRow=_gel(getId('playlistRow',suffix,index));
_gel(getId("playlistContainer",suffix)).scrollTop=videoRow.offsetTop;
autoScrolledTo=_gel(getId("playlistContainer",suffix)).scrollTop;
}
function registerPlaylistAutoload(component){
if(component=='QL'&&qlAutoscrollDestination>0){
scrollPlaylistToVideo(component,qlAutoscrollDestination);
}
_gel(getId('playlistContainer',component)).onscroll=completePlaylistLoad;
if(autoScrolledTo&&autoScrolledTo!=_gel(getId("playlistContainer",'QL')).scrollTop){
completePlaylistLoad();
}
}
function clickedQuickAdd(img,videoId,alreadyInList){
quickAddDoneList[quickAddDoneList.length]=img;
removeClass(img,'QLIconImg');
removeClass(img,'QLIconImgOver');
addClass(img,'QLIconImgDone');
if(!alreadyInList){
videolist.push(videoId);
post_videos_to_server();
}
}
var quickAddDoneList=new Array();
function mouseOverQuickAdd(img){
if(!img.className.match('Done')){
removeClass(img,'QLIconImg');
removeClass(img,'QLIconImgDone');
addClass(img,'QLIconImgOver');
}
}
function mouseOutQuickAdd(img){
if(!img.className.match('Done')){
removeClass(img,'QLIconImgOver');
removeClass(img,'QLIconImgDone');
addClass(img,'QLIconImg');
}
}
function getUrlFromPlaylistRow(rowNode){
var links=rowNode.getElementsByTagName('a');
return links[0].href;
}
function removeVideo(suffix,playlistRow){
var playlistRow=getAncestorWithClass(playlistRow,"playlistRow");
var vid=getNodeVideoId(playlistRow);
playlistRow.parentNode.removeChild(playlistRow);
var newIndex=0;
var videos=getPlaylistVideoCount(suffix);
for(var i=0;i<videos;i++){
var row=_gel(getId("playlistRow",suffix,i));
var index=_gel(getId("playlistRowIndex",suffix,i));
if(row){
row.id=getId("playlistRow",suffix,newIndex);
index.id=getId("playlistRowIndex",suffix,newIndex);
index.innerHTML=newIndex+1;
newIndex++;
}
}
var newCount=decrementPlaylistVideoCount(suffix,1);
remove_from_watch_queue(vid);
var containerNode=_gel(getId("playlistContainer",'QL'));
if(newCount==0){
hidePlaylist(suffix);
}else if(newCount<4){
addClass(containerNode,"autoHeight");
removeClass(containerNode,"fixedHeight175");
}
if(containerNode.onscroll){
containerNode.onscroll();
}
}
var delayedCompletePlaylistLoad=false;
function completePlaylistLoad(){
if(!isRemoving){
suffix="QL";
_gel('playlistContainer_'+suffix).onscroll="";
request=new getUrlXMLResponseJSON("/watch_queue_ajax?v="+pageVideoId+"&action_get_all_queue_videos_component=1&all=1&watch3=1",handleWatchQueueGet);
}else{
delayedCompletePlaylistLoad=true;
}
}
function handleWatchQueueGet(videos){
for(var i=0;i<videos.length;i++){
if(videos[i]){
var newRow=_gel("playlistRow_placeholder_QL").cloneNode(true);
removeClass(newRow,"hide");
videos[i].unshift(newRow);
fillQuicklistRow.apply(this,videos[i]);
newRow.id=getId("playlistRow","QL",videos[i][1]);
var oldNode=_gel(newRow.id);
if(hasClass(oldNode,"loading")){
oldNode.parentNode.replaceChild(newRow,oldNode);
}
}
}
}
function getPlaylistVideoCount(component){
return parseInt(_gel('playlistVideoCount_'+component).innerHTML);
}
function incrementPlaylistVideoCount(component,increment_by){
var node=_gel('playlistVideoCount_'+component);
node.innerHTML=parseInt(node.innerHTML)+increment_by;
return parseInt(node.innerHTML);
}
function decrementPlaylistVideoCount(component,decrement_by){
return incrementPlaylistVideoCount(component,-1*decrement_by);
}
function getNodeVideoId(node){
return getStoredValue(node,"v")
}
function setNodeVideoId(node,id){
return setStoredValue(node,"v",id)
}
function getStoredValue(node,name){
var classes=getClassList(node);
var pattern=classNameForNameValue(name,'');
var found=false;
for(var i=0;i<classes.length;i++){
if(classes[i].substr(0,pattern.length)==pattern){
return classes[i].substr(pattern.length,classes[i].length-pattern.length);
}
}
return '';
}
function setStoredValue(node,name,value){
var classes=getClassList(node);
var pattern=classNameForNameValue(name,'');
var found=false;
for(var i=0;i<classes.length;i++){
if(classes[i].substr(0,pattern.length)==pattern){
classes[i]=classNameForNameValue(name,value);
found=true;
}
}
if(!found){
classes.push(classNameForNameValue(name,value));
}
node.className=classes.join(' ');
}
function classNameForNameValue(name,value){
return name+"*"+value;
}
function TemplateParameters(params){
this.addParameter=addParameter;
this.applyToNode=applyToNode;
this.fill=fill;
this.parameters=new Object();
for(var i=0;i<params.length;i++){
this.addParameter(params[i][0],params[i][1],params[i][2]);
}
function Parameter(attrName,value){
this.attrName=attrName;
this.value=value;
}
function addParameter(className,attrName,value){
if(!this.parameters[className]){
this.parameters[className]=new Array();
}
this.parameters[className].push(new Parameter(attrName,value));
}
function applyToNode(node){
var classList=getClassList(node);
for(var i=0;i<classList.length;i++){
var applyList=this.parameters[classList[i]];
if(applyList){
for(var j=0;j<applyList.length;j++){
if(typeof(applyList[j].value)=="function"){
node[applyList[j].attrName]=applyList[j].value();
}else{
node[applyList[j].attrName]=applyList[j].value;
}
}
}
}
}
function fill(node){
for(var i=0;i<node.childNodes.length;i++){
this.fill(node.childNodes[i]);
}
this.applyToNode(node);
}
}
function fillQuicklistRow(rowDiv,index,videoUrl,imgSrc,title,username,duration,videoId){
var params=new TemplateParameters(
[['playlistRow','id',getId("playlistRow","QL",index)],
['playlistRow','class',function(node){setNodeVideoId(rowDiv,videoId)}],
['phIndex','id',getId("playlistRowIndex","QL",index)],
['phIndex','innerHTML',index+1],
['playlistRowLink','href',videoUrl],
['vimg50','src',imgSrc],
['vtitle','innerHTML',title],
['phUsername','innerHTML',username],
['playlistItemDuration','innerHTML',duration]]);
params.fill(rowDiv);
}
var req;
if(window!=window.top){
var ref=document.referrer;
var sel=window.location.href;
req=getXmlHttpRequest();
var data='location='+encodeURIComponent(ref);
data+='&self='+encodeURIComponent(sel);
req.onreadystatechange=processReqChange;
req.open("POST",'/roger_rabbit',true);
req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
req.send(data);
}
function processReqChange(){
if(req.readyState==4){
if(req.status==200){
if(req.responseText=='block'){
window.top.location.href='/';
}
}
}
}
*/