
// When the DOM is ready
$('document').ready(function(){
	// Set Fancybox defaults
	$.fn.fancybox.defaults.overlayColor = '#000';
	$.fn.fancybox.defaults.overlayOpacity = 0.7;
	$.fn.fancybox.defaults.hideOnContentClick = false;
	$.fn.fancybox.defaults.padding = 0;
	$.fn.fancybox.defaults.titlePosition = "inside";
	$.fn.fancybox.defaults.centerOnScroll = true;
	
	// Fancybox links
	$('a.fancybox').fancybox();

	// Banner cycle
	$('#banner').html('<div class="banners">'+ $('#banner').html() +'</div>');
	$('.banners').cycle({
		fx : 'fade',
		timeout: 4000,
		speedIn:  800,
		speedOut: 300,
		nowrap : 0
	});

	// Horizontal jCarousel
	$('.jcarousel-h').each(function() {
		// Note that we only activate the carousel with 2 or more images
		if($(this).children().length > 2) {
			$(this).jcarousel({
				scroll : 2
			});
		}
	});

	// Vertical jCarousel
	$('.jcarousel-v').each(function() {
		// Note that we only activate the carousel with 3 or more images
		if($(this).children().length > 2) {
			$(this).jcarousel({
				vertical : true,
				scroll : 2
			});
		}
	});
	
	// Fade in thumbnail images
	$('a.thumbnail, #banner').children('img').each(function() {
		// Hide the image
		$(this).hide().stop();
		
		// Create the image resource
		var $t  = $(this);
		var img = new Image();
		img.onload = function() {
			$t.fadeIn();
		}
		
		// Load the image
		img.src = $(this).attr('src');
	});
});

