 /*
Nahuel Jose
http://www.nahueljose.com.ar/
*/

(function($){
	$.fn.sliderVertical = function(opciones){
		var defaults = {
			tiempo : 3000,
			velocidadSlide : 700
	  	};  		
		var opciones = $.extend(defaults, opciones);
		$(this).each(function(){
			var anim = true;
			var _contenedor = $(this);
			var _contenedor_height = _contenedor.innerHeight();
			var _items = _contenedor.children('li');
			
			//agregar markup
			_contenedor.wrap('<div class="sliderVerticalWrapper" />');
			
			//estilos necesarios
			_contenedor.parent('.sliderVerticalWrapper').css({
				overflow:'hidden',
				position:'relative',
				height:_contenedor_height
			});
			_contenedor.css({
				position:'absolute'
			});
			
			//intervalo
			setInterval(_mover_a_sig,opciones.tiempo);
			
			//eventos
			_contenedor.mouseover(function(){
				anim = false;
			})
			.mouseleave(function(){
				anim = true;
			});
			
			//funciones
			function _mover_a_sig(){
				if(!anim){
					return false;
				}
				var _items =  _contenedor.children('li');
				var _first = _items.first();
				var _offset = _items.first().next().position().top;
				_contenedor.append(_first.clone());
				_contenedor.animate({
					top:-1*_offset
				},opciones.velocidadSlide,function(){
					_first.remove();
					$(this).css('top',0);
				});
			}
		});
		return false;
	};	
})(jQuery);
