// JavaScript Document
var imagem_actual=0;
var imagem_anterior=0;
var timer;
function slideSwitch() {
	
	var $active = $('#slideshow DIV.active');
	imagem_anterior=imagem_actual;
	imagem_actual++;
	
	
	if ( $active.length == 0 ) 
	{
		$active = $('#slideshow DIV:last');
	}
	// use this to pull the divs in the order they appear in the markup
	var $next;
	if($active.next().length)
		$next =$active.next();
	else
	{
		$next=$('#slideshow DIV:first');
		imagem_actual=0;
	}
	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 500, function() {
			$active.removeClass('active last-active').animate({opacity: 0.0}, 300);
		});
	
	$(".banner_seta").addClass("h");
	$("#menu_coluna").find("#seta"+imagem_actual).removeClass("h");
	$(".banner_titulo").html(($next.find(".caption_titulo").html()));
	$(".banner_texto").html(($next.find(".caption_texto").html()));
	
	$(".positionrel_over").addClass('h');
	$("#menu_coluna").find("#blue"+imagem_actual).removeClass("h");
	
	
	
	
	 $(".banner_item_img").bind("mouseover", function() {        
                             $(this).find(".positionrel_over").removeClass('h');	} ); 
							 
      $(".banner_item_img").bind("mouseout", function() {        
                             $(this).find(".positionrel_over").addClass('h');	} ); 
	
		
	$("#menu_coluna").find("#bannerimg"+imagem_actual).unbind("mouseover");
	$("#menu_coluna").find("#bannerimg"+imagem_actual).unbind("mouseout");
}


$(document).ready( function() 
{
	timer=setInterval( "slideSwitch()", 5000 );
	$(".banner_item_img").hover(function() {
												  
		$(this).find(".positionrel_over").removeClass('h');										  
												  
	}, function() {
	
		$(this).find(".positionrel_over").addClass('h');
	
	});
	
	$(".banner_item_img").click(function(e){
		
		e.preventDefault();
		clearTimeout(timer);
		var banner_sel=($(this).find(".banner_item_link").attr("id")).replace('banner-','');
		
		if(banner_sel!=imagem_actual)
		{
			imagem_actual=banner_sel;
			var $active = $('#slideshow DIV.active');
			$next=$('#slideshow DIV:eq('+imagem_actual+')');
			
			$active.addClass('last-active');
		
			$next.css({opacity: 0.0})
				.addClass('active')
				.animate({opacity: 1.0}, 500, function() {
					$active.removeClass('active last-active').animate({opacity: 0.0}, 300);
				});
			
			$(".banner_seta").addClass("h");
			$("#menu_coluna").find("#seta"+imagem_actual).removeClass("h");
			$(".banner_titulo").html(($next.find(".caption_titulo").html()));
			$(".banner_texto").html(($next.find(".caption_texto").html()));
			
			
			
			 $(".banner_item_img").bind("mouseover", function() {        
                             $(this).find(".positionrel_over").removeClass('h');	} ); 
							 
			 $(".banner_item_img").bind("mouseout", function() {        
									 $(this).find(".positionrel_over").addClass('h');	} ); 
			
			
			$("#menu_coluna").find("#bannerimg"+imagem_actual).unbind("mouseover");
			$("#menu_coluna").find("#bannerimg"+imagem_actual).unbind("mouseout");
			
			
			$(".positionrel_over").addClass('h');
			$("#menu_coluna").find("#blue"+imagem_actual).removeClass("h");
		}
		
	});
	
	
	/*
	$(".banner_item_img").click(function(){
		//alert($(this).children("a").attr("href"));
		$("#banner_image").attr("src",$(this).children("a").attr("href"));
		
		$(".banner_titulo_container").html($(this).find("img").attr("alt"));
		$(".banner_texto").html($(this).children("a").attr("rel"));
		
		$(".banner_link").attr("href",$(this).children("a").attr("title"));
		
		//VER
		$(".banner_link").attr("href",$(this).children("a").attr("title"));
		
		
		$(".banner_seta").addClass("h");
		
		$(this).parent(".banner_item").find(".banner_seta").removeClass("h");
		
		return false;
	});
	
	var total_banners=$(".banner_item_img").size();
	var count=1;
	var temp=-1;
	
	$(".banner_item_img").everyTime(6000,function(i) {
		//evita que faça 2 vezes a operação
		if(temp!=i)
		{
			temp=i;
			if(count==total_banners)
				count=0;
			
			$(".banner_item_img:eq("+count+")").click();
			count++;
		}
	});
*/
});

