$(document).ready( function(){
	
////////////////////
// Altura do Site //
////////////////////
ajustaAlturaWC = function(){
	$("html,body,#geral").css({height: parseInt($(window).height()) < parseInt($(document).height()) ? "auto" : "100%"});
}
ajustaAlturaWC();
$(window).bind('resize',ajustaAlturaWC).bind('scroll',ajustaAlturaWC);

///////////
// Index //
///////////

// Banner
var banner = {
	autor: "Diego Marques - Agência DMK - 2008",
	
	// Variáveis
	total: 0,
	atual: 0,
	timeOut: null,
	emAnimacao: false,
	
	// Início
	init: function(){
		
		banner.total = $("#banner div img").length;
		
		if(banner.total > 1){
			// gera os botões
			var html = "";
			for(i=1;i<=banner.total;i++){
				html += '<li><a href="javascript:void(0);" title="'+i+'">'+i+'</a></li>';
			}
			var top = 90 - (11 * banner.total);
			$("#banner ul").css("margin-top",top+"px").html(html);
			
			$("#banner ul a").click(function(){
				var ativo = typeof($(this).attr("class")) == "undefined" ? false : $(this).attr("class").indexOf("ativo") == -1 ? false : true;
				if(!ativo && !banner.emAnimacao){
					clearTimeout(banner.timeOut);
					var alvo = $(this).text();
					banner.muda(alvo);
				}
			});
	
			// Inicia animação
			banner.muda(1);
		}else{
			$("#banner div img").fadeIn("slow");
			$("#banner ul").remove();
		}
	},
	
	// Muda de imagem
	muda: function(alvo){
		$("#banner ul a.ativo").removeClass("ativo");
		$("#banner ul a:eq("+(alvo-1)+")").addClass("ativo");
		
		if(banner.atual > 0) $("#banner div img:eq("+(banner.atual-1)+")").stop().fadeOut(3000);
		
		banner.emAnimacao = true;
		$("#banner ul a").css("cursor","wait");
		$("#banner div img:eq("+(alvo-1)+")").stop().fadeIn(3000,function(){
			banner.atual = parseInt($("#banner ul a.ativo").text());
			var proximo = banner.atual == banner.total ? 1 : banner.atual + 1;
			clearTimeout(banner.timeOut);
			banner.timeOut = setTimeout(function(){ banner.muda(proximo); },3000);
			banner.emAnimacao = false;
			$("#banner ul a").css("cursor","pointer");
		});
	}
}
banner.init();

// Vídeo
$("#player a").click(function(){
	var html = '<a href="javascript:void(0);" title="Fechar">X Fechar</a>';
	bloqueia({},function(){
		$("body").append('<div id="video">&nbsp;</div>');
		$("#video").addFlash({
					src: "swf/video_site.swf",
					width: 425,
					height: 370,
					title: "Wellcare"
		}).append(html).absoluteCenter({animation:false}).css("display","block").absoluteCenter();
		$("#video a").click(function(){
			$("#video").css("display","none");
			bloqueia({evento:"fim"},function(){
				$("#video").html("&nbsp;").remove();
			});
		});
	});
});

/////////////
// Submenu //
/////////////
var submenu = {
	autor: "Diego Marques - Agência DMK - 2008",
	
	// Início
	init: function(){
		$("ul[class*='posicao']").each(function(){
			var left = parseInt($(this).attr("class").replace(/[^0-9]+/,""));
			var width = parseInt($(this).css("width")) - left;
			if(left > 0) $(this).css({paddingLeft:left+"px",width:width+"px"});
		});
		$("#submenu a").each(function(i){
			$(this).click(function(){
				var ativo = typeof($(this).attr("class")) == "undefined" ? "" : $(this).attr("class");
				if(ativo.indexOf("ativo") == -1){
					$("#submenu a").filter(".ativo").removeClass("ativo");
					$(this).addClass("ativo");
					submenu.muda(i);
				}
			});
		});
		$(".submenu:eq(0)").show().addClass("ativo");
		$("#submenu a:eq(0)").addClass("ativo");
	},
	
	// Muda página
	muda: function(alvo){
		$(".submenu").filter(".ativo").slideUp("slow").removeClass("ativo");
		$(".submenu:eq("+alvo+")").slideDown("slow",function(){ ajustaAlturaWC(); }).addClass("ativo");
	}
}
submenu.init();
$(".submenu:eq(0)").slideDown("slow",function(){ ajustaAlturaWC(); }).addClass("ativo");

/////////
// OTM //
/////////
	$("a").attr("target","_parent");

///////////////
// Image Box //
///////////////
	$.ImageBox.init({loaderSRC:'imagens/carregando.gif'});

});