
jQuery(function($){

	
	var comentario_rotativo = $("#comentario_rotativo")
	var delay = parseInt(comentario_rotativo.attr("data-delay")) || 5
	delay *= 1000
	
	var slides = comentario_rotativo.find("H4")
	var n = slides.length
	 
	 
	if (n > 1) {
		var w = comentario_rotativo.width()
		var h = comentario_rotativo.height()
		var counter = 0
		var hasFocus = false
		
		comentario_rotativo.width(w).height(h).css("overflow","hidden")
		slides.show().fadeOut(0)
		slides.filter(".currentSlogan").show()
		
		function rotate() {
			if (hasFocus) return
			var from = slides.eq(counter)
			counter = (counter + 1) % n
			var to = slides.eq(counter)
			
			from.fadeOut(500,function() {
				to.fadeIn(500)
			})
			
		}
		
		function eventHandler(e) {
			hasFocus = (e.type == "mouseenter")
		}
		
		comentario_rotativo
			.bind("mouseenter",eventHandler)
			.bind("mouseleave",eventHandler)
		
		setInterval(rotate,delay)
		
		
	}
});
