function load() {
	var img = new Image();
	$(img).load(function () {
		$('#photo_' + index).prepend(this);
		$('#photo_' + index).addClass('loaded');
		if (photos[index + 1]) {
			index++;
			load();
		}
	}).error(function () {
	}).attr('src', image_path + photos[index]);
} 
function arrows() {
	if (current_index == last_index) {
		$('#arrow_right').css('opacity', .25);
	}
	else {
		$('#arrow_right').css('opacity', 1);
	}
	if (current_index == first_index) {
		$('#arrow_left').css('opacity', .25);
	}
	else {
		$('#arrow_left').css('opacity', 1);
	}
}
var timer_id = 0;
$(document).ready(function() {
	arrows();
	load(); 
	$('#thumbs img').mouseout(function() {
		clearTimeout(timer_id);
	});
	$('#thumbs img').mouseover(function() {		
		var el = $(this);
		clearTimeout(timer_id);
		timer_id = setTimeout(function() {
			var new_index = el.attr('id').split('_')[1];				
			if (new_index != current_index) {
				new_current_index = new_index;		
				if (el.hasClass('text')) {
					var position = $('#content').position();
					$('img#text').css('top', position.top);
					new_index--;
				}			
				else {
					$('img#text').css('top', -5000);
				}		
				$("#thumbs div img[id!='thumb_" + new_index + "']").removeClass("current");
				$("#thumbs div img#thumb_" + new_index).addClass("current");
				$("#photos div.sample[id!='sample_" + new_index + "']").css("display", "none");
				$("#photos div#sample_" + new_index).css("display", "");
				current_index = new_current_index;
				arrows();
			}
		}, 100);
	});
	$('img#text').click(function() {
		$('img#text').css('top', -5000);
		current_index--;
		arrows();
	});
	$('#arrow_left').click(function() { 
		$(this).blur();	
		new_index = parseInt(current_index) - 1;
		if (new_index >= first_index) {
			$('#thumb_' + new_index).mouseover();
		}
		arrows();
		return false;
	});	
	$('#arrow_left').dblclick(function() { 
		$(this).click(); 
	})	
	$('#arrow_right').click(function() { 
		$(this).blur();
		new_index = parseInt(current_index) + 1;
		if (new_index <= last_index) {
			$('#thumb_' + new_index).mouseover();
		}
		arrows();
		return false;		
	});	
	$('#arrow_right').dblclick(function() { 
		$(this).click(); 
	})
});