/* ------------------------------------------------------------------------
   jSlide
	Developped By: Nyamagana Butera Ignace -> http://nyams.planbweb.com/
	Version: 1.0
	Copyright: Feel free to do whatever you like with this file as long as you leave my infos at the top.
------------------------------------------------------------------------- */
(function($){
	$.fn.jSlide = function(vars) {
		 var dis   = (vars.timeOut !== undefined) ? vars.timeOut : 5E3; //dis time
		 var trans = dis/6; // transition time
		 var pause = false; // do we pause or not the slideshow
		 var f;  // the initial item to show
		 var o;  // the current item in the sliding process
		 var t;  // timer pointer
		 function showItem () {
		 	if (o === undefined || o.length !== 1) { 
				o = f; 
			}
		 	o.fadeIn(trans, function(){ 
				o.find('span:first').slideDown(trans, function () {
					t = setTimeout(hideItem, dis);
				}); 
			});
		 }
		 function hideItem () {
		 	if (pause === true) {
				clearTimeout(t);
			} else {
				o.find('span:first').slideUp(trans, function() { 
					o.fadeOut(trans, function () { 
						o = $(this).next('li'); 
						showItem(); 
					}); 
				});
			}
 		}
		$(this).find('li').each(function (i) { 
			if (i === 0) { 
				f = $(this); 
			} 
			$(this).find('span').hide();
			$(this).hide();
			$(this).bind('mouseenter', function() { pause = true; });
			$(this).bind('mouseleave', function() { pause = false; hideItem(); });
		});
		showItem();
	};
})(jQuery);
