

// Função acionada depois que todas as imagens são lidas
functionLoader = function() {
	//inicializarPatrocinadores();
	inicializarPublicidade();
	FS.create();
};
// Funções da página
setPageEvents = function () {
	
};

/* Eventos da página */
window.onstopscroll = function() {
	// Posiciona o Alerta, quando aberto
	SA.refresh();
	// Posiciona a imagem, quando aberta
	refreshImagem(true);
	enviarOrcamento.alinha();
};
window.onload = function() {
	
	if (enviado == 1) SA.open('Sua solicita&ccedil;&atilde;o foi enviada com sucesso!');
	
	// Posiciona a seta e cria a "tween" para a mesma
	new tween('setaBusca');
	var newLeft = getPos('buscaProfdeSaude').x+((getSize('buscaProfdeSaude').x-13)/2);
	with ($('setaBusca').style) {
		top = topSetaBusca+'px';
		left = newLeft+'px';
		display = 'block';
	}
	// Seta os eventos
	setAllEvents();
	// Inicia o preloader das imagens
	loadNextImage();
	// ALPHA
	new alpha('molduraImagem');
	new alpha('fundoBranco');
	// Cria o evento da moldura
	document.onmousemove = function(e) {
		e = e || event;
		stopMoldura(e);
	};
	molduraAtiva = true;
	// Inicia o preloader das imagens
	loadSiteImages();
	
	iniciaFormatos();
	iniciaSecoes();
	iniciaCidades();
	
};
window.onresize = function() {
	// Posiciona a seta em baixo do item atual
	var newLeft = getPos(arrBusca[btBuscaAtivo]).x+((getSize(arrBusca[btBuscaAtivo]).x-13)/2);
	$('setaBusca').stopTween();
	with ($('setaBusca').style) {
		top = topSetaBusca+'px';
		left = newLeft+'px';
		display = 'block';
	}
	// Posiciona o fundo branco e a janela de busca avançada
	if (tipoBusca == 2) {
		posicionaFundoBranco();
	}
	// Posiciona o Alerta, quando aberto
	SA.refresh();
};

iniciaFormatos = function() {
	
	var strObj = 'anuncie.formatos';
	
	var linha = null;
	var index = 0;
	
	for (var j = 0; j<arrFormatos.length; j++) {
		
		linha = document.createElement("OPTION");
		$(strObj).appendChild(linha);
		linha.value = j;
		linha.text = arrFormatos[j].titulo;
		
		
	}
	
	//$(strObj).selectedIndex = index;
	$(strObj).disabled = false;
	
	trocaFormatos(0);
	
};

trocaFormatos = function() {
	
	var j = $('anuncie.formatos').selectedIndex;
	
	$('anuncie.formatos.titulo').innerHTML = arrFormatos[j].titulo;
	$('anuncie.formatos.descricao').innerHTML = arrFormatos[j].descricao;
	$('anuncie.formatos.dimensoes').innerHTML = arrFormatos[j].dimensoes;
	$('anuncie.formatos.pesomaximo').innerHTML = arrFormatos[j].pesomaximo;
	$('anuncie.formatos.framerate').innerHTML = arrFormatos[j].framerate;
	$('anuncie.formatos.tempoanimacao').innerHTML = arrFormatos[j].tempoanimacao;
	$('anuncie.formatos.vflash').innerHTML = arrFormatos[j].vflash;
	$('anuncie.formatos.audio').innerHTML = arrFormatos[j].audio;
	
};

desmonstracaoImagem = function() {
	var j = $('anuncie.formatos').selectedIndex;
	verImagem('uploads/formatosbanners/'+arrFormatos[j].demonstracao);
};

iniciaSecoes = function() {
	
	var strObj = 'anuncie.secoes';
	
	var linha = null;
	var index = 0;
	
	for (var j = 0; j<arrSecoes.length; j++) {
		
		linha = document.createElement("OPTION");
		$(strObj).appendChild(linha);
		linha.value = j;
		linha.text = arrSecoes[j].titulo;
		
		
	}
	
	//$(strObj).selectedIndex = index;
	$(strObj).disabled = false;
	
	trocaSecoes(0);
	
};

trocaSecoes = function() {
	
	var j = $('anuncie.secoes').selectedIndex;
	
	$('anuncie.secoes.titulo').innerHTML = arrSecoes[j].titulo;
	$('anuncie.secoes.formatos').innerHTML = arrSecoes[j].formatos;
	//$('anuncie.secoes.media').innerHTML = arrSecoes[j].media;

	
};

iniciaCidades = function() {
	
	var strObj = 'anuncie.cidades';
	
	var linha = null;
	var index = 0;
	
	for (var j = 0; j<arrCidades.length; j++) {
		
		linha = document.createElement("OPTION");
		$(strObj).appendChild(linha);
		linha.value = j;
		linha.text = arrCidades[j].titulo;
		
		
	}
	
	//$(strObj).selectedIndex = index;
	$(strObj).disabled = false;
	
	trocaCidades(0);
	
};

trocaCidades = function() {
	
	var j = $('anuncie.cidades').selectedIndex;
	
	$('anuncie.cidades.titulo').innerHTML = arrCidades[j].titulo;
	$('anuncie.cidades.formatos').innerHTML = arrCidades[j].formatos;
	$('anuncie.cidades.secoes').innerHTML = arrCidades[j].secoes;

	
};

var enviarOrcamento = {
	'tweencreate': 0,
	'aberto':0,
	'btOK': '',
	'show': function() {
		$('enviarOrcamento').style.display = "block";	
		if(this.tweencreate == 0){
			new tween('enviarOrcamento');
			this.tweencreate = 1;
			
		}
		this.aberto = 1;
		this.alinha();
		bgSite.show();	
	},
	'alinha': function() {
		if(this.aberto == 0)return;
		var SC = getScroll();
		var VS = getDocVisibleSize();
		var SZ = getSize('enviarOrcamento');
		newX = (VS.x-SZ.x)/2;
		newY = (VS.y-SZ.y)/2;	
		$('enviarOrcamento').tweenTo((newY+SC.y), (newX+SC.x), 'easeoutexpo', 0.3);		
	},
	'hide': function() {
		var SC = getScroll();
		var VS = getDocVisibleSize();
		var SZ = getSize('enviarOrcamento');
		newX = (VS.x-SZ.x)/2;
		newY = (VS.y-SZ.y)/2;
		this.aberto = 0;			
		$('enviarOrcamento').tweenTo(-SZ.y+SC.y, -SZ.x+SC.x, 'easeoutexpo', 1,function(){
			$('enviarOrcamento').style.top = "-1000px";
			$('enviarOrcamento').style.lef = "-1000px";		
			$('enviarOrcamento').style.display = "none";
		});	
		bgSite.hide();	
	},
	'onClick':function(){	
		if($('enviarOrcamento.nome').value.length == 0){
			SA.onClick = function(){
				focusTo('enviarOrcamento.nome');
			};
			SA.open('Digite um nome!');
			return false;
		}
		if(!$('enviarOrcamento.email').value.isMail()){
			SA.onClick = function(){
				focusTo('enviarOrcamento.email');
			};
			SA.open('Digite um e-mail v&aacute;lido!');
			return false;
		}
		$('enviarOrcamento.form').submit();
	}
};