$(document).ready(function() {		
	slideShowSegmentos();
});

function slideShowSegmentos() {

	$('#caixa_segmento_01 a').css({opacity: 0.0});
	$('#caixa_segmento_01 a:first').css({opacity: 1.0});

	$('#caixa_segmento_02 a').css({opacity: 0.0});
	$('#caixa_segmento_02 a:first').css({opacity: 1.0});

	$('#caixa_segmento_03 a').css({opacity: 0.0});
	$('#caixa_segmento_03 a:first').css({opacity: 1.0});

	$('#caixa_segmento_04 a').css({opacity: 0.0});
	$('#caixa_segmento_04 a:first').css({opacity: 1.0});

	setInterval('mudaSegmento1()',4000);
	setInterval('mudaSegmento2()',4000);
	setInterval('mudaSegmento3()',4000);
	setInterval('mudaSegmento4()',4000);

}

function mudaSegmento1() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#caixa_segmento_01 a.show')?  $('#caixa_segmento_01 a.show') : $('#caixa_segmento_01 a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#caixa_segmento_01 a:first') :current.next()) : $('#caixa_segmento_01 a:first'));	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 500);

	//Hide the current image
	current.animate({opacity: 0.0}, 500)
	.removeClass('show');
	
}

function mudaSegmento2() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#caixa_segmento_02 a.show')?  $('#caixa_segmento_02 a.show') : $('#caixa_segmento_02 a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#caixa_segmento_02 a:first') :current.next()) : $('#caixa_segmento_02 a:first'));	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 500)
	.removeClass('show');
	
}

function mudaSegmento3() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#caixa_segmento_03 a.show')?  $('#caixa_segmento_03 a.show') : $('#caixa_segmento_03 a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#caixa_segmento_03 a:first') :current.next()) : $('#caixa_segmento_03 a:first'));	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1500);

	//Hide the current image
	current.animate({opacity: 0.0}, 500)
	.removeClass('show');
	
}

function mudaSegmento4() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#caixa_segmento_04 a.show')?  $('#caixa_segmento_04 a.show') : $('#caixa_segmento_04 a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#caixa_segmento_04 a:first') :current.next()) : $('#caixa_segmento_04 a:first'));	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 2000);

	//Hide the current image
	current.animate({opacity: 0.0}, 500)
	.removeClass('show');
	
}

