jQuery(document).ready(function(){
	var numImages = (jQuery('.ipad-screenshot-home div').length) - 1;
	var i = 0;
	    
	// Cycle through background images
	jQuery.fn.changeBackground = function() {	
		if (i == 0) {
	    	jQuery('.ipad-screenshot-chat').fadeIn('fast');
	    	jQuery('.ipad-screenshot-login').fadeOut('fast');
		}
		else if (i == 1) {
			jQuery('.ipad-screenshot-windows').fadeIn('fast');
			jQuery('.ipad-screenshot-chat').fadeOut('fast');
		}
		else if (i == 2) {
			jQuery('.ipad-screenshot-login').fadeIn('fast');
			jQuery('.ipad-screenshot-windows').fadeOut('fast');
		}
		else {
			return;
		}
		
		i++;
		setTimeout(function(){  
		    jQuery(this).cycle();  
		}, 7000);  
	}
	
	jQuery.fn.cycle = function() {

		if (i > numImages) {
			i = 0;
			jQuery(this).changeBackground();
		}
		else {
			jQuery(this).changeBackground();
		}	
	}
	
	// Start the cycle
	jQuery(this).changeBackground();
});

