
(function($) {

	$.fn.alertSlider = function(options){
	  
		// configuration properties
		var pause = 5000; 
		
		this.each(function() {  
			var obj = $(this); 	
			var s = obj.find("#alertItem").length;
			var initDisplay = 0;	
			
			function animate(hide, display){
				
				obj.find("#alertItem:eq(" + hide + ")").fadeOut(100, function(){
					obj.find("#alertItem:eq(" + display + ")").fadeIn(150);
				});
				
				var toHide = display;
				var toDisplay = display;
				
				if ((display +1) == s){
					toDisplay = 0;
				} else {
					toDisplay = display + 1;
				}
				
				timeout = setTimeout(function(){
					animate( toHide, toDisplay);
				},pause);
				
			};
			// init
			var timeout;
			if (s >1) {
				for (i = 1; i < s; i++){
					obj.find("#alertItem:eq(" + i + ")").hide();
				}
				
				timeout = setTimeout(function(){
					animate(initDisplay, initDisplay + 1);
				},pause);
			}
		
		});
	  
	};

})(jQuery);




