var isPlaying = false;
var movieToPlay = "";
	
	
function switchMovieOnDelay() {
	document.qt_player.SetURL("movies/" + movieToPlay.find(".movie")[0].innerHTML);
	document.qt_player.SetControllerVisible(true);
	document.qt_player.Play();
	isPlaying = true;
}


$(document).ready(function() {	
	$("#main .right ul li").hover(function(){
		$(this).addClass("highlighted");
	}, function() {
		$(this).removeClass("highlighted");
	});
	
	
	//-----------------------------------------------------
	// A video is clicked
	$("#main .right ul li").click(function(){
		// unselect all the others
		$("#main .right ul li").removeClass("selected");
		
		$('#movie_stub').hide();
		$('#movie').show();

		// and add it to me
		$(this).addClass("selected");
		document.qt_player.Stop();
		// change the video
		movieToPlay = $(this);
		setTimeout("switchMovieOnDelay()", 500);
	});
	
	//-----------------------------------------------------
	// Play/pause is clicked
	$("#playpause, #movie, #movie_stub").click(function() {
		$('#movie_stub').hide();
		$('#movie:hidden').show();

		if (isPlaying == true) {
			document.qt_player.Stop();
			isPlaying = false;
		} else {
			document.qt_player.Play();
			isPlaying = true;
			
			movieToPlay = $("#overview");
			setTimeout("switchMovieOnDelay()", 500);
		}
	});
	
	//------------------------------------------------------
	// Figure out if they came here with a screencast=?moviename
	if ($.getQueryString({ID:"screencast", DefaultValue:"empty"}) != "empty") {
		// unselect all the others
		$("#main .right ul li").removeClass("selected");
		
		$('#movie_stub').hide();
		$('#movie').show();
		
		
		// and add it to me
		movieToPlay = $("#" + $.getQueryString({ID:"screencast"}));
		
		movieToPlay.addClass("selected");
	
		// change the video
		document.qt_player.Stop();
		isPlaying = true;
		
		setTimeout("switchMovieOnDelay()", 500);
	}
});
