$.preloadImages = function() {
	for(var i = 0; i < arguments.length; i++) {
		$('<img />').attr('src', arguments[i]);   
	} 
}

$(document).ready(function() {
	$.preloadImages(
		'assets/img/iphone-screen1.png',
		'assets/img/iphone-screen2.png',
		'assets/img/iphone-screen3.png',
		'assets/img/iphone-screen4.png'
	);
	
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		opacity: 0.50, /* Value between 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: true, /* true/false */
		default_width: 640,
		default_height: 480,
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'pp_tapmates', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
		wmode: 'window', /* Set the flash wmode attribute */
		autoplay: true, /* Automatically start videos: True/False */
		modal: false, /* If set to true, only the close button will close the window */
		changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
		callback: function(){}, /* Called when prettyPhoto is closed */
		flash_markup: '<object id="flashcomponent" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}"><param name="wmode" value="{wmode}" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="{path}" /><embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed></object>'
	});
	
	$('#screenshots li a.zoom')
		.mouseenter(function() {
			$this = $(this);
			if (!$this.hasClass('active'))
				$this.animate({'top': '-10px'}, 100);
		})
		.mouseleave(function() {
			$this = $(this);
			if (!$this.hasClass('active'))
				$this.stop().animate({'top': '0px'}, 100);
		})
		.click(function(event) {
			$this = $(this);
			if (!$this.hasClass('active')) {
				$('#screenshots ul li a.active')
					.removeClass("active")
					.animate({'top': '0px'}, 100);
			
				$this.addClass("active");

				$('#iphonescreen').fadeOut(300, function() {
					$(this)
						.css('background-image', 'url(' + $this.attr('href') + ')')
						.fadeIn(300);
				});
			}
	
			event.preventDefault();
		})
		.eq(0).animate({'top': '-10px'}, 100, 'linear', function() {
			$(this).addClass('active');
		});
			
	$('#iphonescreen').fadeIn(300);
	
	$('#badge-uservoice')
		.animate({'right': '-10'}, 300)
		.mouseenter(function() {
			$(this).animate({'right': '0'}, 100);
		})
		.mouseleave(function() {
			$(this).animate({'right': '-10'}, 100);
		});
	
	$('#badge-twitter')
		.animate({'top': '370px'}, 100)
		.mouseenter(function() {
			$(this).animate({'top': '360px'}, 200, 'linear', function() {
				$('#badge-tweet').fadeIn(150);
			});
		})
		.mouseleave(function() {
			$(this).stop().animate({'top': '370px'}, 200);
			$('#badge-tweet').fadeOut(150);
		});
});