$(function(){
	
	$('.jcarousel-prev, .jcarousel-next').hide();
	
	$('.list-abas').each(function(){
		//alert('teste');
		
		$('div.contaba', this).stop().animate({
			'-moz-opacity'		: '0',
			'-khtml-opacity'	: '0',
			'-webkit-opacity'	: '0',
			'-o-opacity'		: '0',
			'opacity'			: '0',
			'z-index'			: '0'
		}, 0);
		
		$('div.contaba:first', this).stop().animate({
			'-moz-opacity'		: '1',
			'-khtml-opacity'	: '1',
			'-webkit-opacity'	: '1',
			'-o-opacity'		: '1',
			'opacity'			: '1',
			'z-index'			: '9'
		}, 0).find('.jcarousel-prev, .jcarousel-next').show();
		
		$('.abas a:first', this).addClass('selected');
	});
	
	$('.abas a').click(function(){
		$(this).parent().parent().parent().find('div.contaba').stop().animate({
			'-moz-opacity'		: '0',
			'-khtml-opacity'	: '0',
			'-webkit-opacity'	: '0',
			'-o-opacity'		: '0',
			'opacity'			: '0',
			'z-index'			: '0'
		}, 0).find('.jcarousel-prev, .jcarousel-next').hide();
		
		$(this).parent().parent().find('a').removeClass('selected');
		$(this).addClass('selected');
		
		$($(this).attr('href')).stop().animate({
			'-moz-opacity'		: '1',
			'-khtml-opacity'	: '1',
			'-webkit-opacity'	: '1',
			'-o-opacity'		: '1',
			'opacity'			: '1',
			'z-index'			: '9'
		}, 0).find('.jcarousel-prev, .jcarousel-next').show();
		
		$('div#estagio-da-obra-div').stop().animate({ 'height' : $('div#estagio-da-obra-div '+$(this).attr('href')).height() + 'px' }, 'fast');
		
		//alert($('div#estagio-da-obra-div '+$(this).attr('href')).height());
		
		return false;
	});
	
	$('div#estagio-da-obra-div').css({ 'height' : $('div#estagio-da-obra-div .contaba').height() + 'px' }).find('ul.list-empreendimento').each(function(){
		$('li', this).each(function(e){
			var porcentagem = parseInt($('span', this).text());
			
			if(e%3)
			{
				$(this).css({ 'margin-left' : '26px' });
			}
			else
			{
				$(this).addClass('margin-left-none');
			}
			
			if(		 (porcentagem >= 0) && (porcentagem <= 11)){	$('span', this).css({'background-position' : '0 0'});	  }
			else if((porcentagem >= 12) && (porcentagem <= 23)){	$('span', this).css({'background-position' : '0 -15px'}); }
			else if((porcentagem >= 24) && (porcentagem <= 35)){	$('span', this).css({'background-position' : '0 -30px'}); }
			else if((porcentagem >= 34) && (porcentagem <= 47)){	$('span', this).css({'background-position' : '0 -45px'}); }
			else if((porcentagem >= 46) && (porcentagem <= 59)){	$('span', this).css({'background-position' : '0 -60px'}); }
			else if((porcentagem >= 60) && (porcentagem <= 71)){	$('span', this).css({'background-position' : '0 -75px'}); }
			else if((porcentagem >= 72) && (porcentagem <= 83)){	$('span', this).css({'background-position' : '0 -90px'}); }
			else if((porcentagem >= 82) && (porcentagem <= 95)){	$('span', this).css({'background-position' : '0 -105px'});}
			else if((porcentagem >= 94) && (porcentagem <= 99)){	$('span', this).css({'background-position' : '0 -120px'});}
			else{													$('span', this).css({'background-position' : '0 -120px'});}
		});
	});
	
});
