(function($){	
	$.randomImage = {
		defaults: {			
			//you can change these defaults to your own preferences.
			path: 'img/intro/', //change this to the path of your images
			myImages: ['1.png', '2.png', '3.png', '4.png', '5.png'] //put image names in this bracket. ex: 'harold.jpg', 'maude.jpg', 'etc'				
		}			
	}
	
	$.fn.extend({
			randomImage:function(config) {
				
				var config = $.extend({}, $.randomImage.defaults, config); 
				
				 return this.each(function() {
						
						var imageNames = config.myImages;
						
						//alert(imageNames);
						var removeItem = $.cookie("lastimg");   // item do array que deverá ser removido
						imageNames = jQuery.grep(imageNames, function(value) {return value != removeItem;});						
						var imageNamesSize = imageNames.length;
						var lotteryNumber = Math.floor(Math.random()*imageNamesSize);
						var winnerImage = imageNames[lotteryNumber];
						var fullPath = config.path + winnerImage;						
						
						//put this image into DOM at class of randomImage
						// alt tag will be image filename.
						$(this).attr( {
							src: fullPath,
							alt: winnerImage
						});	
						
						$("#introimg2").attr( {
							src: "img/intro/0"+winnerImage,
							alt: winnerImage
						});		

						$.cookie("lastimg", winnerImage);
				});	
			}			
	});
})(jQuery);
