/****************************************
 * * Global JavaScript
 ****************************************/

// Initial setup
$(document).ready(function() {
	// Set up thumbnails
	setupThumbnails();
});

function setupThumbnails() {
	// First screenshot/thumbnail is active
	var active = 0;
	var thumbnails = $('#thumbnails a');
	var screenshots = $('#iphone img');
	
	// Dim all thumbnails but the first 
	thumbnails.not(':first').css('opacity', 0.25);
	screenshots.not(':first').show().css('opacity', 0);
	
	// Click
	thumbnails.click(function(e) {
		e.preventDefault();
		var clicked = $(this);
		var index = thumbnails.index(clicked);
		if(index != active) {
			thumbnails.eq(active).animate({'opacity': 0.25}, 1000);
			clicked.animate({'opacity': 1}, 1000);
			screenshots.eq(active).animate({'opacity': 0}, 500, 'swing', function() {
				screenshots.eq(index).animate({'opacity': 1}, 500, 'swing');
			});
			active = index;
		}
	});
}