//////////////////////
//	Banner Home
/////////////////////
aba = 0
function alterna(){
	
	$('#flashHome li a').removeClass('ativo');
	$('#flashHome li a:eq('+aba+')').addClass('ativo');
	$('.bannerLinks div:not(:eq('+aba+'))').hide();
	$('.bannerLinks div:eq('+aba+')').fadeIn();
	aba = aba == 3 ? 0 : aba += 1;
}


//////////////////////////
// Notas e Noticias
/////////////////////////


	/*function rolaNoticia(){
		valor1 -= 2;
		valor2 -= 2;
		
		if (valor1 < vMax){
			valor1 = vMin;
		};
		if (valor2 < vMax){
			valor2 = vMin;
		};
		$('.notas1').css('top',valor1 + 'px');
		$('.notas2').css('top',valor2 + 'px');
	}*/
	

////////////
// Select //
////////////
estiloSelect = {
	init: function(){
		var primeiro = 0;
		$("select.select").each(function(){
			var html =  '<div id="' + $(this).attr("id") + '" class="' + $(this).attr("class") + '">';
				html += '	<div class="ativo"></div>';
				html += '	<input id="' + $(this).attr("id") + '_select" name="' + $(this).attr("name") + '" type="hidden" value="" />';
				html += '	<div class="options">';
				for(i=0;i<$("option",this).length;i++){
					html += '	<a href="javascript:void(0);" title="' + $("option:eq(" + i + ")",this).text() + '" rel="' + $("option:eq(" + i + ")",this).attr("value") + '">' + $("option:eq(" + i + ")",this).text() + '</a>';
				}
				html += '	</div>';
				html += '</div>';
			
			$(this).replaceWith(html);
			$("option",this).each(function(i){
				primeiro = this.selected ? i : primeiro;
			});
		});
		$("div.select").css("visibility","visible").each(function(){
			var altura = $("a",this).length;
			altura = altura > 5 ? 5 : altura;
			$(".options", this).css({visibility:"visible", display:"none"});
			estiloSelect.change(this,primeiro);
		})
		$("div.select .ativo").unbind().click(function(){
			$(this).parent().parent().css("z-index","3");
			$(this).siblings(".options").slideDown('fast',function(){
				$("html").bind('click',estiloSelect.fecha);
			});
		});
		$("div.select").each(function(){
			$("a", this).each(function(i){
				$(this).unbind().click(function(){
					estiloSelect.change($(this).parents("div.select:eq(0)"),i);
				});
			});
		});
	},
	
	change: function(obj,option){
		$("a.optionAtivo",obj).removeClass("optionAtivo");
		$("a:eq(" + option + ")",obj).addClass("optionAtivo");
		var texto = $("a:eq(" + option + ")",obj).text();
		var valor = $("a:eq(" + option + ")",obj).attr("rel");
		$(".ativo",obj).html(texto);
		$("input",obj).val(valor);
		estiloSelect.fecha();
	},
	
	fecha: function(){
		$("div.select .options:visible").slideUp('fast',function(){$(this).parent().parent().css("z-index","2")});
		$("html").unbind('click',estiloSelect.fecha);
	}
}

imB = function(){
	$.ImageBox.init({loaderSRC:'imagens/carregando.gif', overlayOpacity: 0.5});
}

//////////////////
// ScrollPages //
////////////////
$.extend({
	scrollPages: {
		autor: "Agência DMK",
		version: 2.5,
		defaults: {
			elementSize: 250,
			elements: 3,
			speed: "slow",
			direction: "up"
		}
	}
});
$.fn.extend({
	scrollPages: function(options){
		options = $.extend({}, $.scrollPages.defaults, options);
		return this.each(function(){
			
			// Definições de variáveis
			var total = $(".scrollMask li",this).length;
			var mask = options.elementSize * options.elements;
			var area = options.elementSize * total;
			var animation = false;
			var obj = this;
			var dimension = options.direction == "left" ? "width" : "height";
			var side = new Array();
			side[0] = options.direction;
			side[1] = options.direction == "up" ? "down" : "right";
			
			$(".scrollButtom",this).css("visibility","visible");
			if(options.elements >= total){
				$(".scrollButtom",this).css("visibility","visible");
				mask = area;
			}else{
				$(".scrollButtom[rel*='"+options.direction+"']",obj).css("visibility","hidden");
			}
			
			// Aplicação de estilos
			$(".scrollMask",this).css({"width": mask + "px", overflow: "hidden"}); // Máscara
			$(".scrollMask ul",this).css({"width": area + "px", marginTop: 0}); // UL
			$(".scrollMask li",this).css({"width": options.elementSize + "px", display: "block"}); // LI

			// Função que execulta a rolagem
			var rolagem = function(direction){

				// Variáveis
				var margem = -parseInt($(".scrollMask ul",obj).css("margin-"+(options.direction == "up" ? "top" : "left")));

				var intervalo = direction == side[1]
					? ( margem + ( mask * 2 ) ) < area
						? mask
						: area - (margem + mask)
					: ( margem - mask ) < 0
						? margem
						: mask
				;
				direction = direction == side[1]
					? -margem - intervalo
					: -margem + intervalo
				;
				
				$(".scrollButtom",obj).css("visibility","visible");
				var rel = -direction == 0 ? side[0] : (-direction + mask) == area ? side[1] : null;
				if(rel != null) $(".scrollButtom[rel*='"+rel+"']",obj).css("visibility","hidden");
				
				// Animação
				animation = true;
				if(options.direction == "up"){
					$(".scrollMask ul",obj).animate({marginTop: direction + "px"},options.speed,function(){ animation = false; });
				}else{
					$(".scrollMask ul",obj).animate({marginLeft: direction + "px"},options.speed,function(){ animation = false; });
				}
			}
			
			// Aplicação de eventos
			$(".scrollButtom",this).unbind("click").click(function(){
				if(!animation){
					var direction = $(this).attr("rel");
					rolagem(direction);
				}
			});
		});
	}
});


$(document).ready(function(){
						   
	estiloSelect.init();			
	imB();
						


	if (paginaAtivo.toLowerCase() == "brasil-mezanino.asp"){
		$("a[href *= 'fundos-especializados.asp']").addClass("ativo").parent().parent().removeClass('hide').siblings('div').removeClass("hide").siblings('a').addClass('ativo');	
	}
	else if (paginaAtivo == 'tecnologia-aplicada.asp' || paginaAtivo == 'cleantech.asp'){
		$("a[href *= 'growth-capital.asp']").addClass("ativo").parent().parent().removeClass('hide').siblings('div').removeClass("hide").siblings('a').addClass('ativo');
	}
	else if (paginaAtivo.indexOf('portifolio-gc.asp') >= 0 || paginaAtivo.indexOf('portifolio-gc-3.asp') >= 0){
		$("a[href *= 'portifolio.asp']").addClass("ativo");
	}
	else if (paginaAtivo.indexOf('profissionais-descricao.asp') >= 0){
		$("a[href *= 'equipe.asp']").addClass("ativo");
	}
	else if (paginaAtivo == 'projetos-assessoria-estrategica.asp' || paginaAtivo == 'projetos-financas-corporativas.asp'){
		$("a[href *= 'projetos-selecionados.asp']").addClass("ativo");
	}
	
//////////////////////
// Rolagem Noticias
/////////////////////////
	/*nota1 =	$('.notas1').height();
	nota2 =	$('.notas2').height();
	
	valor1 = 0;
	valor2 = nota1;
	vMax = -nota1;
	vMin = nota1;
	
	setTimeout(function(){
		
		slideNota = setInterval('rolaNoticia()', 20);
		
		$('.notasMascara').hover(function(){
				clearInterval(slideNota);
			},function(){
				clearInterval(slideNota);
				slideNota = setInterval('rolaNoticia()', 20);
			}
		)
	
	}, 2000);
	
	$('.notasMascara').height($('.notas1').height())
	$('.notas2').css('top',$('.notas1').height())*/
	
////////////////////////
//Rolagem Clientes
///////////////////////

	$('.chamadaServicos').scrollPages({elementSize:256, elements:2, direction:'left'});
	$('.miniatura').scrollPages({elementSize:124, elements:5, direction:'left'});


//////////////////////
//ChamaBloqueio
/////////////////////

	$(".linkMapa, .mapaLink").click(function(){
		bloqueia({ speed: "slow", bgcolor: "#000" });
		$("#comoChegar").absoluteCenter({animation:false}).absoluteCenter().show();
	});

	$(".fechaBloqueio").click(function(){
		$("#comoChegar").hide();
		bloqueia({ speed: "slow", evento: "fim" });
		
	});


//////	
// area restrita 
////////////
	$('.abreRestrita').click(function(){
		$('.areaRestrita').slideDown('slow');	
	});
	$('.fechaRestrita').click(function(){
		$('.areaRestrita').slideUp('fast');
	});

//////	
// Centraliza Paginação
/////////////////////////////
	$('.navegaConteudo ul').each(function(){
		var larguraDiv = $(this).parent().width();
		var larguraUl = $(this).width();
		
		var margem = larguraDiv / 2 - larguraUl / 2
		$(this).css('margin-left',margem+'px')
	})
	
//////////////////
// Imprimir
/////////////////
	$("#imprimirNoticia").click(function(){
		$("#printLocalizacao").remove();
		$("head").append('<link id="printLocalizacao" rel="stylesheet" type="text/css" href="css/css-imprime.css" media="print" />');
		self.print();
	});
	
///////////////////////	
// Banner Home 
////////////////////////

	$('#flashHome li a').click(function(){
		var obj = $(this).parents('ul:eq(0)');
		var indice = $('a', obj).index(this);
		$('li a', obj).removeClass('ativo');
		$(this).addClass('ativo');
		$('.bannerLinks div:not(:eq('+indice+'))').hide();
		$('.bannerLinks div:eq('+indice+')').fadeIn();
		
	});
	$('#flashHome ul').hover(function(){
		clearInterval(intervalo);
	}, function(){
		intervalo = setInterval("alterna()", 5000);	
	});

////////
// Banner Home Alterna
///////////////////////////
	
	alterna();
		intervalo = setInterval("alterna()", 5000);


});