var hometimer;
$(document).ready(function() {
	$("#imageviewer .foto img").hide();
	$("#imageviewer .foto img:first").show();
	$("#imageviewer .foto img:first").addClass("active");
	$("#spotlight .spotitem").hide();
	$("#spotlight .spotitem:first").show();
	$("#spotlight .spotitem:first").addClass("active");
	$(".btn_next").click(function() {
		nextThing();		
	});
	$(".btn_previous").click(function() {
		previousThing();
	});
	$(".homeviewer").mouseover(function(){
      clearTimeout(hometimer);
    }).mouseout(function(){
      hometimer=setTimeout("nextThing();",3000);
    });
	hometimer=setTimeout("nextThing();",10000);
});

function nextThing() {
	clearTimeout(hometimer);
	$("#imageviewer .foto img.active").hide();
	$("#spotlight .active").hide();
	if ($("#imageviewer .foto img.active").attr("src") != $("#imageviewer .foto img:last").attr("src")) {
		$("#imageviewer .foto img.active").next().fadeIn("slow",function() {
			$("#imageviewer .foto img.active").removeClass("active");
			$(this).addClass("active");				
		});
		$("#spotlight .active").next().show(function() {
			$("#spotlight .active").removeClass("active");
			$(this).addClass("active");				
		});
	} else { 
		$("#imageviewer .foto img:first").fadeIn("slow",function() {
			$("#imageviewer .foto img.active").removeClass("active");
			$(this).addClass("active");
		});
		$("#spotlight .spotitem:first").show(function() {
			$("#spotlight .active").removeClass("active");
			$(this).addClass("active");
		});
	}
	hometimer=setTimeout("nextThing();",10000);
}

function previousThing() {
	clearTimeout(hometimer);
	$("#imageviewer .foto img.active").hide();
	$("#spotlight .active").hide();
	if ($("#imageviewer .foto img.active").attr("src") != $("#imageviewer .foto img:first").attr("src")) {
		$("#imageviewer .foto img.active").prev().fadeIn("slow",function() {
			$("#imageviewer .foto img.active").removeClass("active");
			$(this).addClass("active");
		});
		$("#spotlight .active").prev().show(function() {
			$("#spotlight .active").removeClass("active");
			$(this).addClass("active");
		});
	} else { 
		$("#imageviewer .foto img:last").fadeIn("slow",function() {
			$("#imageviewer .foto img.active").removeClass("active");
			$(this).addClass("active");
		});
		$("#spotlight .spotitem:last").show(function() {
			$("#spotlight .active").removeClass("active");
			$(this).addClass("active");
		});
	}
	hometimer=setTimeout("nextThing();",10000);
}


