var ArrivalOverview = function() 
{
	
	var activeImageId = '#overview-video';
	
	prepareElements = function()
	{
		// Play demo video buttons
		$('#overview-video, #video-thumb, .play-demo-video').click(function() {
			updateThumbs('#video-thumb');
			embedVideo();
			return false;
		});
		
		// Show thumb 1
		$('#img-thumb-1').click(function() {
			if (activeImageId == '#overview-img-2') return false;
			killVideo();
			showImageAnimated('#overview-img-2');
			updateThumbs('#img-thumb-1');
			return false;
		});
		
		// Show thumb 2
		$('#img-thumb-2').click(function() {
			if (activeImageId == '#overview-img-3') return false;
			killVideo();
			showImageAnimated('#overview-img-3');
			updateThumbs('#img-thumb-2');
			return false;
		});
		
	}
	this.prepareElements = prepareElements;
	
	
	embedVideo = function() {
	
		if (activeImageId.length > 0) {
			$(activeImageId).stop().css({left:'240px'});
		}
	
		$('#overview-video').media({
			width:     240,
			height:    360,
			autoplay:  true,
			src:       'assets/arrival-demo-240x360.mov',
			params:    { controller: 'false' },
			caption:   false // supress caption text 
		});
	
		activeImageId = '#overview-video';
			
	}
	this.embedVideo = embedVideo;
	
	killVideo = function() {
		$('#overview-video').replaceWith('<a id="overview-video" href="#"><img src="assets/overview-img-1.jpg" alt="Arrival" width="240" height="360" /></a>');
		// Play demo video buttons
		$('#overview-video').click(function() {
			updateThumbs('#video-thumb');
			embedVideo();
			return false;
		});
	}
	this.killVideo = killVideo;
	
	updateThumbs = function(selectedThumbId) {
		$('#overview-thumbs li a').removeClass('selected');
		if (selectedThumbId.length > 0) {
			$(selectedThumbId).addClass('selected');
		}
	}
	this.updateThumbs = updateThumbs;
	
	showImageAnimated = function(imageId) {
	
		if (activeImageId.length > 0) {
			$(activeImageId).animate({left:'-240px'});
		}
		
		if (imageId.length > 0) {
			$(imageId).stop().css({left:'240px'});
			$(imageId).animate({left:'0px'});
			activeImageId = imageId;
		}
	}
	this.showImageAnimated = showImageAnimated;

}

// When DOM is ready, prepare elements
$(document).ready(function()
{
	
	// Instantiate overview interaction layer
	var overview = new ArrivalOverview();
	overview.prepareElements();
	
	
});