$(function(){
	
	if($("div#imagens img").length>0){
	
		smaRot=undefined;
		$("div#imagens img").css('z-index','0');
		$("div#imagens img").fadeTo(0, 0);
		q=$("#textos a").length-1;
		tmm=0;
		
		function rotacionar(){
	
			bratual=($("#textos a.ativo").index());
	
			if(bratual==q || bratual==-1){
				bratual=0;
			}else{
				bratual=bratual+1;
			}
					
			if(smaRot!=undefined){
				bratual=smaRot;
				clearInterval(intervaloRot);
			}
			//mover marcador
			position=$($("#textos a")[bratual]).position();
			alturaE=$($("#textos a")[bratual]).height()+parseInt($($("#textos a")[bratual]).css('padding-top'))+parseInt($($("#textos a")[bratual]).css('padding-bottom'));
			alturaM=$("img#marcador").height();
			mt=parseInt((alturaE-alturaM)/2);
			ml=$("img#marcador").width();
			$("img#marcador").stop().animate({ 'margin-top':(position.top+mt)+'px', 'margin-left':(position.left-ml)+'px' },tmm ,function(){
				$($("div#imagens img")[bratual]).css('z-index','2');
				$($("div#imagens img")[bratual]).stop().fadeTo(0, 0);
				$($("div#imagens img")[bratual]).stop().fadeTo(500, 1 ,function(){
					$("div#imagens img").css('z-index','0');
					$($("div#imagens img")[bratual]).css('z-index','1');
				});	
				$("#textos a").removeClass('ativo');
				$($("#textos a")[bratual]).addClass('ativo');
			});
			if(tmm==0){tmm=500;}
		}
		
		rotacionar();
		intervaloRot=setInterval(rotacionar, 4000);
		
	    $("#textos a").mouseenter(function() {
	    	smaRot=$(this).index();
	    	rotacionar();
	    });
	
	    $("#bannerRotativo").mouseleave(function() {
	    	smaRot=undefined;
	    	intervaloRot=setInterval(rotacionar, 4000);
	    });
    
	}
    
});
