$(document).ready(function(){
	
	$('.thumbmenu').hide();
	
	$('.thumb').hover(function(){
		$(this).children('.thumbmenu').fadeIn(200);
	}, function(){
		$(this).children('.thumbmenu').fadeOut(200);
	});
	
	$('#banner').cycle({ 
		fx:			'scrollLeft',
		easing:		'easeInOutQuint',
		speed:		1000,
		timeout:	3000
	});
	
	$('#slideshow').cycle({ 
		fx:			'fade',
		speed:		800,
		timeout:	0,
		next:		'.slideshow-next',
		prev:		'.slideshow-prev'
	});
	
	$('#viewer').hide();
	
	$('.thumbmenu > a.import').click(function(){
		var target = $(this).attr("href");
		
		$('#viewer').fadeTo(0, 0);
		
		$('#viewer').load(target + ' #primary_content', function(response, status, xhr) {
		
			if (status == "error") {
				var msg = "<p>Oops, there's been a bit of a problem fetching the data: <strong>" + xhr.status + " " + xhr.statusText + "</strong></p>";
				$('#viewer').html(msg);
			} else {
				onLoadReady();
			}
			
			$('html, body').animate({scrollTop:167}, 200, function() {
				$('#viewer').fadeTo(150, 1);
			});
		
		});
		
		return false;
	});
	
	$(function() {
		$("a.email").nospam({ replaceText: true });
	});
	
});

function onLoadReady() {

	$('#slideshow').cycle({ 
		fx:			'fade',
		speed:		800,
		timeout:	0,
		next:		'.slideshow-next',
		prev:		'.slideshow-prev'
	});

}
