(function($){

  $.fn.slideShow = function() {
	 
	  var slideshow = $(this);
	  
	  // Align slides
	  alignSlides();
	  
	  var sTimer = 5000;
	  var delay = 150;
	  var mode = true;

	  function alignSlides(){
		  
		  var paddingX = 0;
		  var resetX = 3;
		  var totalSlides = $(slideshow).find("li").size();
		  
		  $(slideshow).find("li").each(function (i) {
			  
			  $(this).find(".content").fadeTo(0,0.8);
			  
			  $(this).mouseenter(function(){
				 $(this).find(".content").slideDown("slow");
				 
			  }).mouseleave(function(){ 

				 $(this).find(".content").slideUp("slow"); 
			  
			  });
			  
			  if(i == 0 || i > resetX ){  
				  paddingX = 0; resetX = i + 3; 
				  $(this).css({ "left" : paddingX, 'z-index' : totalSlides - i });	
				  paddingX = $(this).width() + paddingX + 1;
			  } else {
				  $(this).css({ "left" : paddingX, 'z-index' : totalSlides - i });	
				  paddingX = $(this).width() + paddingX + 1;
			  }
			  $(this).find(".content").slideUp(0);
		  });
	  }

	  var myInterval = setInterval(initSlideshow, sTimer );
	 
	  function initSlideshow(){
		  
		  if(mode){
			  
			  var sDelay1 = delay;
			  
			  $(slideshow).find("li .content").hide();
			  $(slideshow).find("li:lt(4)").each(function(i){		  
				  $(this).delay(sDelay1).fadeTo("slow", 0, function(){ $(this).hide(); });
				  sDelay1 = sDelay1 + sDelay1 / 2;
			  });
			  mode = false;
		  
		  } else {
		  
			  var sDelay2 = delay;
			  
			  
			  $(slideshow).find("li .content").hide();
			  $(slideshow).find("li:lt(4)").each(function(i){  
				  $(this).show(); 
				  $(this).delay(sDelay2).fadeTo("slow", 1);
				  sDelay2 = sDelay2 + sDelay2 / 2;  
	
			  }); 
			  mode = true;	
		  
		  }
		  
	  }
	  
	  $(slideshow).mouseenter(function(){
		  clearInterval(myInterval);
	  }).mouseleave(function(){ 
			  myInterval = setInterval(initSlideshow, sTimer); 
	  });
	  
  };
})(jQuery);

