/**
 * @author adam
 */

var display_timeout = 0;
var slideShowTimer = 0;
var counter = 0;

$(document).ready(function() {
	
	var descriptions = new Array();
	descriptions[0] = "Red Sky Descending, 2008";
	descriptions[1] = "The Alamo, 2007";
	descriptions[3] = "Strange Journey (part 2), 2006";
	descriptions[4] = "Natural Noise, 2006";
	descriptions[2] = "Beneath a Pale Moon, 2007";
	descriptions[5] = "The Alamo, 2004";
	descriptions[6] = "Strange Journey (part 1), 2004";
	
	var id = null;
	var number = null;
	
	$('.thumb').css('opacity', 0.4).hover(function() {
		
		if(slideShowTimer != 0) {
			clearTimeout(slideShowTimer);
		}
		
		if(display_timeout != 0) {
			clearTimeout(display_timeout);
		}
		
		$('.thumb').css('opacity', 0.4);
		
		var this_element = $(this);
		
		display_timeout = setTimeout(function() {
			this_element.fadeTo("fast", 1);
			id = this_element.attr('id').split("_");
			number = parseInt(id[1]);
			counter = number;
			$('#info').html(descriptions[number]).css('visibility', 'visible');
		}, 200);				
		
	}, function() {
		if(display_timeout != 0) {
			clearTimeout(display_timeout);
		}	
		
		counter = (counter == 6) ? (0) : (counter + 1);
		slideShow();
	});
	
	$("#thumb_0").css('opacity', 1);
	$('#info').html(descriptions[0]).css('visibility', 'visible');
	counter = (counter == 6) ? (0) : (counter + 1);
	
	slideShow();
	
	function slideShow() {
		slideShowTimer = setInterval(function() {
			$('.thumb').css('opacity', 0.4);
			var strNum = String(counter);
			$("#thumb_"+strNum).fadeTo("fast", 1);
			$('#info').html(descriptions[counter]).css('visibility', 'visible');
			counter = (counter == 6) ? (0) : (counter + 1);
		}, 2500);
	}
	
});


