jQuery(function( $ ){			
	$("#preloader").fadeIn("fast");
	
	/**
	 * All the functions below, are used to update the summary div
	 * That is not the objective of the plugin, the really important part 
	 * is the one right below. The option placeholder, and threshold.
	 */
	$.preload( '#preload-div img', {//the first argument is a selector to the images
		onRequest:request,
		onComplete:complete,
		onFinish:finish,
		//placeholder:'../img/placeholder.jpg',//this is the really important option
		//notFound:'../img/notfound.jpg',//optional image if an image wasn't found
		threshold: 2 //'2' is the default, how many at a time, to load.
	});
	
	function update( data ){
	  /*
		$('#done').html( ''+data.done );
		$('#total').html( ''+data.total );
		$('#loaded').html( ''+data.loaded );
		$('#failed').html( ''+data.failed );
		*/
		
		/*
	  var percent = parseFloat(parseInt((parseFloat(data.loaded)/parseFloat(data.total)*10)+2)/10);
    var absPercent =parseInt(percent * 100);
	  var cheesePercent = -210 * parseInt(parseFloat(percent - 0.1) * 10);
	  */
	  
	  segment = Math.round(100/data.total)/100
	  percent = Math.round((data.loaded / data.total) * 100) / 100;
	  
	  roundPercent = Math.round(percent * 10) / 10;
	  absPercent = Math.round(percent * 100);
	  cheesePercent = -210 * Math.round((roundPercent-segment) * 10);

		$("#percent-bar").html( '' + absPercent + '%');
		$("#preload-bar").css({'background-position' : '' + cheesePercent + 'px ' + '0px'});
		//$("#preload-bar").animate({'opacity' : percent}, 1);
	};
	function complete( data ){
		update( data );
		//$('#image-next').html( 'none' );//reset the "loading: xxxx"
		$('#image-loaded').html( data.image );
	};
	function request( data ){
		//update( data );
		$('#image-next').html( data.image );//set the "loading: xxxx"
	};
	function finish(){//hide the summary
	  $(".pb-wrapper").fadeOut("slow", function() { $("#preloader").css({'display':'none'}); startWindmillAnimation(); });
	};
});
