$(document).ready( function() {				
	
	jQuery.fn.slideshow = function(list) {
		theframe = $(this);
		theframe.prepend('<div class="image1" ></div>')
		theframe.prepend('<div class="image2" ></div>')
		
		var imageone = theframe.find('.image1');
		var imagetwo = theframe.find('.image2');
		
		
		var theimage = 1;
		var loop = Math.floor(Math.random()*list.length-1);
		var thisimage = imageone;
		var nextimage = imagetwo;
		
			$( function () {
				
				imageload = list[loop];
				// alert(imageload);	  
			  var img = new Image();
				nextimage.hide();	
			  $(img)
					
				.load(function () {
					 
				  //$(this).hide();
					
				  nextimage
					.empty()
					.append(img);
					
				  nextimage.fadeIn(400);
				  
				  nextimage.css({'z-index':9});
				  thisimage.css({'z-index':8});
				  if (theimage == 1) {
						
						theimage = 2; 
						thisimage = imagetwo;
						nextimage = imageone;
				  } else {
						theimage = 1; 
						thisimage = imageone;
						nextimage = imagetwo;
				  }
				  
				})
				
				.error(function () {
				})
				.attr('src', imageload);
					
			});	
			
			newloop = Math.floor(Math.random()*list.length-1);
			
			while (newloop == loop) {
				newloop = Math.floor(Math.random()*list.length-1);
			}
			loop = newloop;
			// if (list.length-1 > loop){loop++} else {loop=0};

		
		setInterval( function() {
		

			$( function () {
				
				imageload = list[loop];
				// alert(imageload);	  
			  var img = new Image();
				nextimage.hide();	
			  $(img)
					
				.load(function () {
					 
				  //$(this).hide();
					
				  nextimage
					.empty()
					.append(img);
					
				  nextimage.fadeIn(400);
				  
				  nextimage.css({'z-index':9});
				  thisimage.css({'z-index':8});
				  if (theimage == 1) {
						
						theimage = 2; 
						thisimage = imagetwo;
						nextimage = imageone;
				  } else {
						theimage = 1; 
						thisimage = imageone;
						nextimage = imagetwo;
				  }
				  
				})
				
				.error(function () {
				})
				.attr('src', imageload);
					
			});	
			if (list.length-1 > loop){loop++} else {loop=0};
		}, 3000);
	}
	

})
