$(function() {

	initHomePhotos();
	/* initHomeBicycle(); */
	
	$('#illustration_bicycle').flash({
		swf: 'swfs/bicycle.swf',
		width: 415,
		height: 85,
		wmode: 'transparent'
	});
	
});

var wait = 4000;
var duration = 1750;
var currentHomePhoto = 0;
var homePhotosSlideShowTimeout;

var bicycleWait = 1200;
var bicycleDuration = 3500;
var bicycleEndRight = 120;
var homeBicycleTimeout;

function initHomePhotos() {
	$('#homephotos img').eq(currentHomePhoto).addClass('active').fadeIn(0);
	
	continueHomePhotosSlideShow();
}

function continueHomePhotosSlideShow() {
	var nextPhoto = currentHomePhoto + 1;
	var numPhotos = $('#homephotos img').length;
	
	if (nextPhoto > (numPhotos - 1)) nextPhoto = 0;
	
	homePhotosSlideShowTimeout = setTimeout(function() {
		revealHomePhoto(nextPhoto);
	}, wait);
}

function revealHomePhoto(nextPhoto) {
	$('#homephotos img.active').css('z-index', '1');
	
	$('#homephotos img').eq(nextPhoto).css('z-index', '5').fadeIn(
		duration,
		'easeOutQuint',
		function() {
			$('#homephotos img.active').fadeOut(0).removeClass('active');
			$(this).addClass('active');
			currentHomePhoto = nextPhoto;
			continueHomePhotosSlideShow();
	});
}

function initHomeBicycle() {
	homeBicycleTimeout = setTimeout(function() {
		revealBicycle();
	}, bicycleWait);
}

function revealBicycle() {
	$('#illustration_bicycle').fadeIn(50).animate(
		{
			right: bicycleEndRight + 'px'
		},
		bicycleDuration,
		'easeOutQuart'
	);
}
