var videoBarConfig;
var playlist = 'ytchannel:universityofrichmond';
//var ytloop;
function LoadVideoBar() {
	if(videoBarConfig != null) var options = videoBarConfig;
	else{
		var options = {
			largeResultSet : true,
			horizontal : true,
			autoExecuteList : {
			  cycleTime : GSvideoBar.CYCLE_TIME_SHORT,
			  cycleMode : GSvideoBar.CYCLE_MODE_LINEAR,
			  executeList : [playlist]
			  //statusRoot : document.getElementById("scroll_menu")
			}
			
		  };
	}

	
    var videoBar = new GSvideoBar(document.getElementById("videoBar-bar"),
                              GSvideoBar.PLAYER_ROOT_FLOATING,
                              options); 
}
	
// arrange for this function to be called during body.onload
// event processing
GSearch.setOnLoadCallback(LoadVideoBar);


//this code is for the customized page scrollers. 
var scroll_amount = 537;
function LeftScroll(id){
	document.getElementById(id).scrollLeft += scroll_amount;
}	
function RightScroll(id){
	document.getElementById(id).scrollLeft -= scroll_amount;
}

//these are used in the vertical implementation
var flip_amount = 139;
function flipNext(id){	
	document.getElementById(id).scrollTop += flip_amount;
	//go back to the top and skip the YouTube ad at the bottom;
	var limit = document.getElementById(id).scrollTop + (flip_amount*1.25);
	if(document.getElementById(id).scrollHeight <= limit){
		document.getElementById(id).scrollTop = 0;	
	}
	checkTitle();
}

function checkTitle(){
	var previews = document.getElementById('videoBar-bar').getElementsByTagName('img');
	var previews_titles = new Array();
	
	//default
	document.getElementById('video-title').innerHTML = previews[0].parentNode.title;
	
	for(var n=0; n<previews.length;n++){
		var title = previews[n].parentNode.title;
		if(previews[n].y){
			var y = previews[n].y;		
			y -= previews[0].y;
			
		}
		else{
			var y = previews[n].offsetHeight*n + (6*n);
			//alert(document.getElementById('videoBar-bar').scrollTop + ' '+ y);
		}
		if(document.getElementById('videoBar-bar').scrollTop == y){
			document.getElementById('video-title').innerHTML = title;
		}
	}
	
	
}

function checkForYTObject(){
	if(!document.getElementById("videoBar-bar")){
		setTimeout(checkForYTObject,500);
	}
	else checkTitle();
}