// JavaScript Document

$(function(){
	
	//Shadowbox.init({
//        handleOversize: "drag",
//        modal: true
//    });		

			Shadowbox.init();
			
			Cufon.replace('h2');
			Cufon.replace('h3');
        	Cufon.replace('#menu ul li a');
			Cufon.replace('.article p strong');
			Cufon.replace('.end strong');

	$(window).load(function() {
		$('#slider').nivoSlider();
	});
	

$(function acordeon(){
	$('.acordeon h2').css({cursor:'pointer'})
	$('.acordeon h2').click(function(){
		$(this).parents('.acordeon').find('.recipiente:visible').slideUp();
		$('.acordeon h2').css({backgroundPosition:'0 0'});
		if($(this).next().is(':visible')){
			$(this).next().slideUp();
			$(this).css({backgroundPosition:'0 0'});
		}else{
			$(this).next().slideDown();
			$(this).css({backgroundPosition:'0 -44px'});
		}
	})
})	
	
// ABAS

$(document).ready(function() {
	$("#overflowContAbas > div").hide();
	$("#overflowContAbas > div:eq(0)").show();
	$("#tabs > a:eq(0)").css({'background': '#FFF', 'border-bottom-color': '#FFF'});
	return false;
});

function opentab(num) {
	$("#overflowContAbas > div").hide();
	$("#overflowContAbas > div:eq(" + (num-1) + ")").fadeIn();
	$("#tabs > a").css({'background': '#F7F7F7', 'border-bottom-color': '#a6a6a6'});
	$("#tabs > a:eq(" + (num-1) + ")").css({'background': '#FFF', 'border-bottom-color': '#FFF'});	
	return false;
}	

	$(window).load(function(){
		$('.centerImage').each(function(){
				var contHeight   = $(this).height();
				var contWidth    = $(this).width();
				var imgHeight    = $(this).find('img').height();
				var imgWidth     = $(this).find('img').width();
				var cetralizingV = ((contHeight-imgHeight)/2);
				var cetralizingH = ((contWidth-imgWidth)/2);
				$(this).find('img').css({marginTop:cetralizingV+'px',marginLeft:cetralizingH+'px'});
		});
	});
	
})

$(function slideShow(){
	
	var $qtdItens = $('#banner ul.chamadas li').length;
	var $chamadaCurrentIndice = 0;
	
	$('#banner ul.chamadas li:first a').addClass('current');
	
	if($qtdItens>1){
		
		$('#banner ul.imagens li').not(':first').css({opacity:0});
		$('#banner ul.imagens li:first').addClass('show');
		
		$('#banner ul.chamadas li a').click(function(e){
			var indice = $('#banner ul.chamadas li a').index(this);
			sliding(indice);
			return false;
		});
		
		function contador(){
			intervalo = window.setInterval(function(){
				sliding();
			}, 6000);
		}contador();
		
		function sliding(goToIndice){
			
			if(goToIndice >= 0){
				$chamadaCurrentIndice=goToIndice;
			}else{
				if($chamadaCurrentIndice<($qtdItens-1)){
					$chamadaCurrentIndice++;
				}else{
					$chamadaCurrentIndice=0;
				}
			}
			
			$('#banner ul.chamadas li a.current').removeClass('current');
			$('#banner ul.chamadas li').eq($chamadaCurrentIndice).find('a').addClass('current');
			
			$('#banner ul.imagens li.show').animate({opacity:0}).removeClass('show');
			$('#banner ul.imagens li').eq($chamadaCurrentIndice).animate({opacity:1}).addClass('show');
			
			clearInterval(intervalo);
			contador();
			
		}
	
	}
	
})
