		$.fn.image = function(src, f){ 
   return this.each(function(){ 
     var i = new Image(); 
     i.src = src; 
     i.onload = f; 
     this.appendChild(i);
   }); 
 } 
		
		
		// DOM Ready
		$(function () {
			// Image Sources
			var preloadImages = new Array();
			var preloadOriginal = new Array();
			$('img.preview').each( function( intIndex ){
				preloadImages[intIndex] = $(this);
				preloadOriginal[intIndex] = $(this).attr('src');
				$(this).attr('src','/img/blank.gif');
			});	
	
			// images length
			var max = $(preloadImages).length;
			// at least 1 image exist
			if(max>0)
			{
				LoadImage(0,max);
				
			}


			// function of loading image
			// params: (int) index of image in array, (int) length of images array
			function LoadImage(index,max)
				{
					// if current index is lower then max element (max-1)
					if(index<max)
						{
							//alert(preloadOriginal[index]);
							
							// new image object
					        var img = new Image();
							// image onload
					        $(img).load(function () {
					        	preloadImages[index].css('display','none'); // since .hide() failed in safari
								preloadImages[index].attr('src',preloadOriginal[index]);

					            $(preloadImages[index]).fadeIn('slow',function(){
										// once the current loaded, trigger the next image
										LoadImage(index+1,max);
									});
					        }).error(function () {
								// on error remove current
								//$(curr).remove();
								// trigger the next image
								//LoadImage(index+1,max);
					        }).attr('src', preloadOriginal[index]);
						}
				}

		});
