var videoPlayer;

var flashvars = {
	videoUrl: videoFiles[0], 
	imageUrl: imageFiles[0]
};
var params = {bgcolor:"#000000", allowFullScreen: "true"};
var attributes = { id: "VideoPlayer", name: "VideoPlayer" };


swfobject.embedSWF(videoPlayerFile, "VideoPlayerHldr", "650", "352", "9.0.0","expressInstall.swf", flashvars, params, attributes);

var currNum = 0;

(function($) {
	$(document).ready(function(){
		
		$('#slideShow').cycle('fade');
		
		
		$("#videoThumbs li a").animate({ opacity: 0.5}, "fast");
		$("#" + currThumb).animate({ opacity: 1}, "fast");
	
		$("#videoThumbs li a").hover(function(){
			if(this.id != currThumb){
				$(this).animate({ opacity: 1}, "fast");
			}
		}, function(){
			if(this.id != currThumb){
				$(this).animate({ opacity: 0.5}, "fast");
			}
		});
		
		
		$("#videoTitle").text(videoTitles[0]);
	});
})(jQuery);


function playClip(Pos, fromComplete){
	
	if(Pos - 1 != currNum || fromComplete == true){
		if(fromComplete == true){
			Pos++;
			if(videoFiles.length == (Pos - 1)){
				Pos = 1;	
			}
		}
		if($("#slideShow").is(":visible")){
			$("#slideShow").fadeOut(function(){
				loadVideo(Pos);
			})
		}
		
		if($("#flashHldr").is(":visible")){
			$("#flashHldr").fadeOut(function(){
				loadVideo(Pos);
			})	
		}
						
		
		
		prevThumb = currThumb;
		$("#" + prevThumb).animate({ opacity: 0.5}, "fast");
		currThumb = "thumb" + Pos;
		$("#" + currThumb).animate({ opacity: 1}, "fast");
		
	}
				
}

function loadVideo(Pos){
	$("#flashHldr").show();
	currNum = Pos - 1;
	
	
	$("#videoTitle").text(videoTitles[currNum]);
	var videoFile = videoFiles[currNum];
	var imageFile = imageFiles[currNum];
	if(imageFile == undefined){
		imageFile = imageFiles[0];
	}
	
	
	videoPlayer = document.getElementById("VideoPlayer");
	videoPlayer.changeVideo(videoFile,  imageFile);
	
}
		

function videoComplete(){
	var pos = currNum + 1;
	playClip(pos, true);
}

function playSlideshow(){

	
	$("#flashHldr").fadeOut("fast", function (){
		currNum = totalVids;
		videoPlayer = document.getElementById("VideoPlayer");
		videoPlayer.stopVideo();
	
		$("#slideShow").fadeIn();
		
		$("#videoTitle").text("Playing Slideshow");
	});
	
	
	prevThumb = currThumb;
	$("#" + prevThumb).animate({ opacity: 0.5}, "fast");
	currThumb = "thumb0";
	$("#" + currThumb).animate({ opacity: 1}, "fast");
		
}