window.addEvent('domready', function(){
	//Deixa o scroll lento ao clicar em uma ancora
	new SmoothScroll();
	
	//Ajusta a tela
	if(window.getWidth() < 770 && screen.width < 800){
		$('geral').style.position = 'relative';
		$('geral').style.float = 'left';
		$('geral').style.margin = 0;
		$('geral').style.top = 0;
		$('geral').style.left = 0;
	}else{
		if(window.getWidth() < 770){
			if(!window.resizeTo(800,600)){
				
			};
		}
	}
});

//Faz a troca das cores dos botões do menu
menu_sel = "menu_programas";
function muda_bg(el,img){

	if(img == 1){
		var imag = "url(images/menu_fundo_01.jpg) repeat-x";
	}
	if(img == 2 || menu_sel == el){
		var imag = "url(images/menu_fundo_02.jpg) repeat-x";
	}
	$(el).style.background = imag;
	
}


//Clicou em um botão?
var menu_trans = false;
function menu_abre(el,ext){
		if(!menu_trans && menu_sel != el){
			menu_trans = true;
			
			var menu_sel_old = menu_sel;
			menu_sel = el;
			muda_bg(menu_sel_old, 1);
			
			window.location = "#goMenu";
			
			
			var mySlider = new Fx.Slide('conteudo_menu_in', {duration: 500});
				$('conteudo_menu').style.overflow = 'hidden';
			mySlider.slideOut().chain(function(){
				$('conteudo_menu_in').innerHTML = "<table width='100%' height='258'><tr><td align='center'><img src='images/ajax-loader.gif' /></td></tr></table>";
				mySlider.slideIn().chain(function(){
												  
					var cont_me_in = $('conteudo_menu_in');
					$('conteudo_menu').setHTML('<div id="conteudo_menu_in"><span class="padding_padrao"><table width="100%" height="258"><tr><td align="center"><img src="images/ajax-loader.gif" /></td></tr></table></span></div>');
					
					if(menu_sel == "menu_programas"){
						var el_put = $('conteudo_menu_in');
					}else{
						var el_put = $('conteudo_menu_in').childNodes[0];
					}
					
					//Ajax
					new Ajax(menu_sel + "." + ext,{
						method: 'get',
						update: el_put,
						evalScripts: true
					}).request().chain(function(){window.location = "#goMenu"});
					
					menu_trans = false;
					
				});
				
			});
		}

}

function manda_email(){
	
	var nome = $('seu_nome').value;
	var mail = $('seu_email').value;
	var mess = $('sua_mensagem').value;
	var assu = $('seu_assunto').value;
	
	var dados = "nome=" + nome + "&email=" + mail + "&mess=" + mess + "&assu=" + assu;
	
	$('conteudo_menu_in').innerHTML = "<table width='100%' height='258'><tr><td align='center'><img src='images/ajax-loader.gif' /></td></tr></table>";
	
	new Ajax("envia_contato.php?" + dados,{
		method: 'get',
		update: $('conteudo_menu_in'),
		evalScripts: true
	}).request();
	
}

//Controla a transição entre a enquete e o participe
var cont_forms = true;
function troca_cont_form(tes){
	if(cont_forms && tes == 1){
		
		$('cont_form_participe').effect('opacity').start(1,0).chain(function(){
			$('form_participe').effect('height').start(30,200);
			$('cont_form_enquete').effect('opacity').start(0,0).chain(function(){$('cont_form_enquete').style.display = 'block'});
			$('cont_form_participe').style.display = 'none';
			$('form_participe').effect('backgroundColor').start('#274F35','#192D21').chain(function(){
				$('cont_form_enquete').effect('opacity').start(0,1);
						cont_forms = false;
			});
		});
		
	}
	
	if(!cont_forms && tes == 2){
		$('cont_form_enquete').effect('opacity').start(1,0).chain(function(){
			$('form_participe').effect('height').start(30,200);
			$('cont_form_participe').effect('opacity').start(0,0).chain(function(){$('cont_form_participe').style.display = 'block'});
			$('cont_form_enquete').style.display = 'none';
			$('form_participe').effect('backgroundColor').start('#192D21','#274F35').chain(function(){
				$('cont_form_participe').effect('opacity').start(0,1);
						cont_forms = true;
			});
		});
		
	}
}

email_quadro_antigo = "";

//Formulario Participe Ja
function envia_participe(){
	
	var nome = $('for_nome').value;
	var mail = $('for_mail').value;
	var mess = $('for_mess').value;
	
	var dados = "nome=" + nome + "&email=" + mail + "&mess=" + mess;
	
	var email_quadro_antigo = $('cont_form_participe').innerHTML;
	$('cont_form_participe').innerHTML = "<center><br /><br /><br /><br /><br />Enviando...</center>";
	
	new Ajax("envia_participe.php?" + dados,{
		method: 'get',
		update: $('cont_form_participe'),
		evalScripts: true
	}).request();
	
	setTimeout(function(){
		$('cont_form_participe').innerHTML = email_quadro_antigo;
	}, 5000);
}

function NewWindow(myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	mypage = 'http://www.uptv.com.br/cgi-bin/noticias/sistema_noticias_versao_2_0.cgi?body=FFFFFF&size=2&font=Verdana&color=333333&funcao=assinar&id=003509591000115_uptv&volta_pagina=ok&email='+ document.getElementById('rec_email').value;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
	win = window.open(mypage, myname, winprops);
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function apre_borda_over(id){
	id.style.borderColor = '#076F2B';
}

function apre_borda_out(id){
	id.style.borderColor = '#333333';
}

function grade_fundo_over(id, color){
	id.style.background = color;
}

function grade_fundo_out(id){
	id.style.background = '#1d1d1d';
}

function troca_grade(id){
	$('grade_0').style.display = "none";
	$('grade_1').style.display = "none";
	$('grade_2').style.display = "none";
	$('grade_3').style.display = "none";
	$('grade_4').style.display = "none";
	$('grade_5').style.display = "none";
	$('grade_6').style.display = "none";
	
	$(id).style.display = "block";
	
	one_sec_focus();
}

function one_sec_focus(){
	$('conteudo_menu').effect('background-color', {
		duration: 1000,
		transition: Fx.Transitions.linear
	}).start('#3E8356','#0F0F0F');
}