/**
 * 
 * Handles video interaction on the homepage
 */
jQuery(document).ready(function($){
	
	$('.active-vid').css({borderColor: '#bdbdbd'});
	
	$('.slide-thumb').mouseover(function(){
			$(this).css({cursor: "pointer"});
		}).mouseout(function(){
			$(this).css({cursor: "normal"});
		}).click(function(){
			var imageFile = $(this).attr('src');
			var videoFile = imageFile.substr(0, imageFile.length -4) + '.flv';
		
			var player = document.getElementById('player'); 
					
			player.sendEvent("LOAD", videoFile);
			player.sendEvent("PLAY");
		});
	
	/** -- Next vid button -- */
	$('#slide-next').mouseover(function(){
				$(this).css({cursor: "pointer"});
		}).mouseout(function(){
			$(this).css({cursor: "normal"});
		}).click(function(){
			var nextImage = $('.slide-thumb .active-vid').next('img.slide-thumb');
			
			// if at the end....go back to the start
			if (typeof(nextImage) === "undefined" || nextImage.length == 0) {
				nextImage = $('.slide-thumb:first');
			}	
			
			$('.slide-thumb').removeClass('active-vid');
			$(nextImage).addClass('active-vid');
			var imageFile = $(nextImage).attr('src');
			
			var videoFile = imageFile.substr(0, imageFile.length -4) + '.flv';
			var player = document.getElementById('player'); 
					
			player.sendEvent("LOAD", videoFile);
			player.sendEvent("PLAY");
			
		});

	/** -- Prev vid button -- */
	$('#slide-prev').mouseover(function(){
				$(this).css({cursor: "pointer"});
		}).mouseout(function(){
			$(this).css({cursor: "normal"});
		}).click(function(){
			var prevImage = $('.slide-thumb.active-vid').prev('img.slide-thumb');
			
			// if at the end....go back to the start
			if (typeof(nextImage) === "undefined" || nextImage.length == 0) {
				prevImage  = $('.slide-thumb:last');
			}	
			
			$('.slide-thumb').removeClass('active-vid');
			$(prevImage).addClass('active-vid');
			var imageFile = $(prevImage).attr('src');
			
			var videoFile = imageFile.substr(0, imageFile.length -4) + '.flv';
			var player = document.getElementById('player'); 
					
			player.sendEvent("LOAD", videoFile);
			player.sendEvent("PLAY");
			
		});
	 
});
