jQuery( document ).ready( function( ) {
	// Get total number of images in slide.
	var delay			= 5; // Gets multiplied by 1000.
	var slideSpeed		= 5; // Gets multiplied by 100.
	var imageWidth		= jQuery( '#window' ).css( 'width' ).replace( 'px', '' );
	var imageSum		= jQuery( '#imageSlide img' ).size( );
	var imageSlideWidth	= imageWidth * imageSum;

	// Set the width of imageSlide to equal the total width of all images.
	// The overflow is hidden.
	jQuery( '#imageSlide' ).css( 'width', imageSlideWidth );

	// Rotate through the images every 5 seconds.
	delay	*= 1000;
	setInterval( function( ) {
		// Get the next slide to show.
		var active	= jQuery( '#imageSlide a.active' ).next( );
		if( active.length === 0 ) {
			// Slides reached the end. Show first.
			var active	= jQuery( '#imageSlide a:first' );
		}

		// Determines the css offset we need.
		var imageNumber	= active.attr( 'alt' ) - 1;
		var imageOffset	= imageNumber * imageWidth;

		// Remove active image. Set current image as active for the next loop.
		jQuery( '#imageSlide a' ).removeClass( 'active' );
		active.addClass( 'active' );

		// Now, slide!
		jQuery( '#imageSlide' ).animate( {
			left: -imageOffset
		}, ( slideSpeed * 100 ) );
	}, delay );
});
