$(document).ready(function(){

	$('a[@rel=facebox]').facebox();

	carregaBanner(1);
	carregaBanner(2);
	carregaBanner(3);	
	carregaBanner(4);
	
	montaTemperatura();

	buscaColunista('Manoel');
	buscaColunista('Cleber');

	

	$('#Busca').click(function(){
		var chave = $('#buscar').val();
		if(chave != ''){
			carregaBusca(chave);
		}
	});
	
	
	classificados();
	montaAlbums();
	painelDestaques();
	carregaNoticias('', 1);
	
	
	$('a[@tipo=canal]').click(function(){
		verificaNoticia(this.id);
	});
	
	
	$('#dtMedicaoRios').focus(function(){
		$('#dtMedicaoRios').datepicker();
	});
	
	$('#dtMedicaoRios').change(function(){
		var data = $('#dtMedicaoRios').val();
		montaRios(data);
	});
	
	montaRios('');
	
	//carregaCharge('');
	
	
	$('#buttonEmail').click(function(){
			
			var nome    = $('#seuNome').val();			
			var destino = $('#recipient').val();
			var emailSaida = 'contato@corumbaonline.com.br'
			var corpoEmail = $('#Noticia').html();
		
			if(!valida_Email(destino) || (nome=='')){
				alert('Email no formato invalido, ou nome em branco!')
				setFocus('recipient');
			}else{
				$.ajax({
				type: "POST",
				data: { nome: nome, recipient: destino, email: emailSaida, emailCorpo: corpoEmail },
				url: "modelo/EnviarEmail.asp",
				success:
					function(){
						alert('Email enviado com sucesso!');
						$('#tbEmail1').fadeOut("slow", function(){ void 0; });
					}								
				});
			}					
		
		
		})
				

	
});

	function verificaNoticia(tipo){
		if(tipo=='Expediente'){
			$('#tabelaInicial').fadeOut('slow',
				function(){					
					$("#Noticia").load("expediente.asp", {},
						function(){
							$('#tbNoticia').fadeIn('slow');
							montaLinks('');
						}
					);
				}
			);
		}else{
			var canal = tipo;
			//SETA NA ABA NOTICIAS O TITULO DO CANAL ESCOLHIDO
				if(canal == 'Meio Ambiente'){
					$('#nomeCanal').html('<b>Meio<font color="white">_</font>Ambiente</b>');
				}else{
					
					if(canal == ''){
						$('#nomeCanal').html('<b>&Uacute;ltimas</b>');
					}else{
						$('#nomeCanal').html('<b>'+canal+'</b>');
					}
				}
			//FECHA A NOTICIA SE ESTIVER ABERTA E CARREGA O PANEL COM AS NOTICIAS RELACIONADAS AO MENU CLICADO
			$('#tbNoticia').fadeOut('slow',
					function(){
						carregaNoticias(canal, 1);
						$('#tabelaInicial').fadeIn('slow');
					}
			);
		}
	}

	

	//controla o album de fotos
	function montaAlbums(){	
		$.getScript('../_libs/jQueryPlugins/lightBox/jquery.lightbox-0.3.js');
		$.ajax({
			 type: "POST",
			 dataType: "json",
			 data: { parametro: 'opcional' },
			 url: "modelo/buscaAjax_Albuns.asp",
			 success:
				function(json){
					if(json[0].foto != '0'){
					
					var listaProdutos = '';
					$.each( json, function(i, n){
						listaProdutos = listaProdutos +
						'<li>'+
						'<a id="'+n.id+'" href="#" tipo="album" type="">'+
						'<img tipo="album" src="'+n.srcFotoM+'" width="66" height="66">'+
						'</a>'+
						'</li>'
					});
					
					setHTML('<ul id="">'+listaProdutos+'</ul>', 'divProdutos');
					
					$(".jMyCarousel").jMyCarousel({
						visible: '4',
						eltByElt: true,
						evtStart: 'mousedown',
						evtStop: 'mouseup'
					 });

					$.getScript('../Album/Fotos/_scripts/Fotos.js');
					
					}						
				},//fim da function sucess				
			error:
				function(){
					alert("Erro no carregamento do Album");
				}	
		});//fim do ajax	
	}
	
	

	//controla o painel dos destaques
	function painelDestaques(){
		//controle do painel de noticias
		var newsoption1 = {
			firstname:	 "mynews",
			secondname:  "showhere",
			thirdname:	 "news_display",
			fourthname:	 "news_button",
			newsspeed:	 '10000'
		}
		$.init_news(newsoption1);		
		var myoffset=$('#news_button').offset();		
		var mytop=myoffset.top-1;		
		$('#news_button').css({top:mytop});
		//fim do controle do painel de noticias
	}

	//objeto que carrega o json inicial
	var objNoticias;
   	var objCanal;
	function carregaNoticias(canal, pagina){	
	
		if(objCanal == canal){
			montaNoticias(objNoticias, pagina);
			montaPgNoticias(objNoticias, canal);
		
		
		}else{
			$('#tdNoticias').html('<img src="../_imgs/ajaxLoader_1.gif" alt="" width="32" height="32" /><br>Carregando ... </p>');
			$.ajax({
				 type: "POST",
				 dataType: "json",
				 data: { canal: canal },
				 url: "modelo/buscaAjax_Noticias.asp",
				 success:
					function(json){
						if(json[0].noticia != '0'){
							objNoticias = json;
							objCanal = canal;
							montaNoticias(json, pagina);
							montaPgNoticias(json, canal);
						}else{
							$('#tdNoticias').html('Nenhuma noticia relacionada, selecione um canal!');
						}						
					},//fim da function sucess
					
				error:
					function(){
						alert("Erro no carregamento function(carregaNoticias) pg: controle.js");
					}	
			});//fim do ajax		
		}//fim do else		
	}
	
	function montaNoticias(json, pagina){
		var materia;						
		var paginaFim = pagina * 16;//define a qtd de noticias que sera mostrada na tela
		var paginaIni = paginaFim - 16;	//define a qtd de noticias que sera mostrada na tela
			var noticias = '';
			var j = paginaIni;
			do{
				titulo = left(json[j].titulo, 90);				

				noticias = noticias +
				'<tr id="trNoticia'+j+'" style="cursor:hand;" tipo="trNoticia" cod="'+json[j].codigo+'">'+
				'<td width="10%" aling="left" valing="top" style="vertical-align:top; text-align:left;">'+
				'<b>'+left(right(json[j].hora, 8), 5)+' </b></td>'+
				'<td width="90%" aling="left" valing="top"><a href="#" style="font-weight: none;">'+titulo+'</a></td>'+
				'</tr>';
				 
				 if(json[j].data != json[j+1].data){//escreve a ultima noticia daquela data depois o cabecalho da proxima data
					noticias = noticias +
					'<tr>'+
					'<td colspan="2" width="100%" aling="left" valing="top" style="vertical-align:top">'+
					'<b><span class="style6">'+json[j+1].data+'</span></b></td>'+
					'</tr>'
					j++;
					noticias = noticias +//escreve a ultima noticia do dia anterior
					'<tr id="trNoticia'+j+'" style="cursor:hand;" tipo="trNoticia" cod="'+json[j].codigo+'">'+
					'<td width="10%" aling="left" valing="top" style="vertical-align:top; text-align:left;">'+
					'<b>'+left(right(json[j].hora, 8), 5)+' </b></td>'+
					'<td width="90%" aling="left" valing="top"><a href="#" style="font-weight: none;">'+left(json[j].titulo, 90)+
					'</a></td>'+
					'</tr>';
				 }
				 
				 j++;
				 
			}while(j < paginaFim);
			
		$('#tdNoticias').html('<table width="100%" aling="left" valing="top" style="text-align:left;">'+noticias+'</table>');
		
		$('tr[@tipo=trNoticia]').click(function(){
			var cod = getAttr(this.id, 'cod');
			carregaNoticia(cod, '');
		});		
	}
	
	
	function montaPgNoticias(json, canal){
		var paginas = '';
		var qtdPag = (json.length / 15);
			for(i = 1; i < qtdPag; i++){
				paginas = paginas + '<a tipo="paginador" href="#" id="'+i+'"> '+i+' </a>';
			}		
		$('#tdPagNoticias').html(paginas+'<a href="#" tipo="mais" id="'+canal+'"> <b>veja mais</b></a>');
		
		$('a[@tipo=paginador]').click(function(){
	montaNoticias(json, this.id);
		});
		
		$('a[@tipo=mais]').click(function(){
					  
			carregaMais(this.id, '');
		});
	}
	
	
	function montaDestaques(){
		$('#showhere').html('<img src="../_imgs/ajaxLoader_1.gif" alt="" width="32" height="32" /><br>Carregando ... </p>');
		$.ajax({
			 type: "POST",
			 dataType: "json",
			 data: { ajax: 'parametro obrigatorio!' },
			 url: "modelo/buscaAjax_Destaques.asp",
			 success:
				function(json){
					carregaDestaques(json);
				},//fim da function sucess
				
			error:
				function(){
					alert("Erro no carregamento function(montaDestaques) pg: controle.js");
				}	
		});//fim do ajax
	}
	
	
	function carregaDestaques(json){
		var destaques = '';
		$.each( json, function(i, n){
				destaques = destaques +
				'<div id="news'+i+1+'" class="news_style" rel="">'
				'<table><tr>'+
				'<td><font color="#006600">'+
				'<img src="'+n.imagem+'" align="left"/>'+
				'<b>'+n.titulo+'</b></font>'+n.materia+
				'</td></tr>'+
				'</table>'+
				'</div>'
		});
		alert(destaques);
		$('#mynews').html(destaques);
		
	}
	
	
	
	function carregaNoticia(codNoticia, busca){
		$('#Noticia').html('');
		$('#tabelaInicial').fadeOut('slow',
				function(){
					$('#tbNoticia').fadeIn('slow',
					function(){
					$.ajax({
							 type: "POST",
							 dataType: "json",
							 data: { codNoticia: codNoticia },
							 url: "modelo/buscaAjax_Noticia.asp",
							 success:
								function(json){									
									
											var noticia = '';
											var secao = json[0].secao;
											$.each(json, function(i, n){
												
												if(n.credito){ 
													var creditos= '<span class="text7"><b>'+n.credito+'</bs></span>';
												}else{
													var creditos= '';
												}

												if(n.foto1){
													var foto1 = 
													'<b>'+n.credito1+'</b><br>'+
													'<a href="#Modal" rel="facebox" >'+
							'<img tipo="mFoto" src="../../fotos/'+n.foto1+'" alt="'+n.legenda1+'" width="140" height="105" /><br>'+
													'</a>'+
													'<span class="text7">'+n.legenda1+'</span>'
												}else{
													var foto1 = '&nbsp;';
												}
												
												if(n.foto2){
													var foto2 = 
													'<b>'+n.credito2+'</b><br>'+
													'<a href="#Modal" rel="facebox" >'+
							'<img tipo="mFoto" src="../../fotos/'+n.foto2+'" alt="'+n.legenda2+'" width="140" height="105" /><br>'+
													'</a>'+													
													'<span class="text7">'+n.legenda2+'</span>'
												}else{
													var foto2 = '&nbsp;';
												}
												
												if(n.foto3){
													var foto3 = 
													'<b>'+n.credito3+'</b><br>'+
													'<a href="#Modal" rel="facebox" >'+
						    '<img tipo="mFoto" src="../../fotos/'+n.foto3+'" alt="'+n.legenda3+'" width="140" height="105" /><br>'+
													'</a>'+													
													'<span class="text7">'+n.legenda3+'</span>'
												}else{
													var foto3 = '&nbsp;';
												}
												
												if(n.foto4){
													var foto4 = 
													'<b>'+n.credito4+'</b><br>'+
													'<a href="#Modal" rel="facebox" >'+
							'<img tipo="mFoto" src="../../fotos/'+n.foto4+'" alt="'+n.legenda4+'" width="140" height="105" /><br>'+
													'</a>'+													
													'<span class="text7">'+n.legenda4+'</span>'
												}else{
													var foto4 = '&nbsp;';
												}
												
												noticia = noticia +
												'<table width="98%" border="0">'+
												'<tr>'+
												'<td align="left" valign="top">'+
												'<table border="0" style="float:left;'+
												'text-align:justify; padding-left:2px; padding-bottom: 2px;">'+
												'<tr>'+
												'<td>'+creditos+'</td>'+
												'</tr>'+
												'<tr>'+
												'<td><a href="#Modal" rel="facebox" >'+
												'<img tipo="mFoto" src="'+n.imagem+'" style="padding-right:10px" />'+
												'</a></td>'+
												'</tr>'+
												'<tr>'+
												'<td><span class="text7"><b>'+n.legenda+'</b></span></td>'+
												'</tr>'+
												'</table>'+
													'<span class="style11 style26">'+n.titulo +'</span><br><b>'+ n.hora +'</b>'+
													'<br>'+n.autor+''+
													'<span class="style3 style25"><br><br>'+ n.materia +'</span>'+
													'<br><br>'+
												'</td>'+
												'</tr>'+
												'</table>'+

												'<table width="100%" border="0">'+
												'<tr>'+
												'<td width="25%" style="text-align:left;">'+foto1+'</td>'+
												'<td width="25%" style="text-align:left;">'+foto2+'</td>'+
												'<td width="25%" style="text-align:left;">'+foto3+'</td>'+
												'<td width="25%" style="text-align:left;">'+foto4+'</td>'+
												'</tr>'+
												'</table>'
												
											});
											
											var retornaBusca = '';
											if(busca!=''){
												retornaBusca = retornaBusca+
												'<table width="100%" border="0">'+
												'<tr>'+
												'<td><b><a href="#" '+
												'tipo="retonarBusca" '+
												'"id="'+busca+'">'+
												'<img src="../_imgs/ico_newsletter.gif" alt="" width="15" height="11" />'+
												' retornar ao resultado da pesquisa</b> "'+busca+'" </a><br><br></td>'+
												'</tr>'+
												'</table>'
											}

											
											$('#Noticia').html(retornaBusca+noticia);
											
											montaLinks(codNoticia);

											$('a[rel*=facebox]').facebox({
												close_image   : '../../faceBox/closelabel.gif'
											});
											
											
											$('a[@tipo=retonarBusca]').click(function(){
												carregaBusca(busca);
											});
											
											$('img[@tipo=mFoto]').click(function(){
												var foto = this.src;
												var legenda = this.alt;
												//alert(legenda);
												carregaFoto(foto, legenda);
												$('td[@tipo=flash]').hide();//esconde os flashs
											});
											
											$('#close > a').click(function(){//imagem de fechar o modal
												$('#Modal').html('');
												$('td[@tipo=flash]').show();//mostra os flashs
											});
											
																
								},//fim da function sucess					
							error:
								function(){
									alert("Erro no carregamento function(carregaNoticia) pg: controle.js");
								}	
					});//fim do ajax
					
					}//fecha function fedaIN
					);//fecha fadeIn
					
					
				}
		);

	}
	
	function montaLinks(codNoticia){
		$('#Email1').html('<a href="#" tipo="email1">'+
						  '<img src="../_imgs/ico_envelope.gif"'+
						  'alt="" width="13" height="11" /> Encaminhar por Email '+
							  '</a>');
		$('#Emai2').html('<a href="#" tipo="email2">'+
							  '<img src="../_imgs/ico_envelope.gif"'+
						  'alt="" width="13" height="11" /> Encaminhar por Email '+
							  '</a>');
	
		$('#impressao1').html('<a href="#" tipo="impressao">'+
							  '<img src="../_imgs/ico_impressao.gif"'+
						  'alt="" width="13" height="11" /> Vers&atilde;o para Impress&atilde;o '+
							  '</a>');
		$('#impressao2').html('<a href="#" tipo="impressao">'+
							  '<img src="../_imgs/ico_impressao.gif"'+
						  'alt="" width="13" height="11" /> Vers&atilde;o para Impress&atilde;o '+
							  '</a>');										
		
		
		//1
		//retornar('defalt');
		$('a[@tipo=retornar]').click(function(){
			//retornar('defalt');
			$('#tbNoticia').fadeOut('slow',
					function(){
						carregaNoticias('', 1);
						$('#tabelaInicial').fadeIn('slow');
					}
			);												
		});
		
		
		if(codNoticia!=''){
			$('a[@tipo=impressao]').click(function(){
				window.open('http://www.corumbaonline.com.br/novo/home/noticia.asp?codNoticia='+codNoticia);
			});
		}
		
		
		$('a[@tipo=email1]').click(function(){
			$('#seuNome').val('');			
			$('#recipient').val('');
			enviarEmail();
		});
		
		$('a[@tipo=email2]').click(function(){
			$('#seuNome').val('');			
			$('#recipient').val('');
			enviarEmail();
		});
	}
	
	function enviarEmail(id){

			$('#tbEmail1').fadeIn("slow", function(){
				$('#fecharEmail1').click(function(){
					$('#tbEmail1').fadeOut("slow", function(){ void 0; });
				});			
			});	
			
	}
	
	function carregaFoto(src, alt){
		$('#Modal').html('<table width="590" border="0" align="center">'+
								'<tr>'+
								'<td height="380" align="center" valign="middle">'+				
								'<table width="174" border="0" align="center">'+
								'<td><img src="'+src+'" /></td>'+
								'</tr>'+
								'<tr>'+
								'<td style="text-align:left"><b>'+alt+'</b></td>'+
								'</tr>'+
								'</table>'+					 
							    '</td>'+
								'</tr>'+
								'</table>');		
	}
	
	
	
	function montaNoticiasCanal(canal){
		$('#Noticia').html('');
		$('#tabelaInicial').fadeOut('slow',
				function(){
					$.ajax({
							 type: "POST",
							 dataType: "json",
							 data: { codNoticia: codNoticia },
							 url: "modelo/buscaAjax_Noticia.asp",
							 success:
								function(json){									
									$('#tbNoticia').fadeIn('slow',
										function(){
											var noticia = '';
											$.each(json, function(i, n){
												noticia = noticia +
												'<img src="'+n.imagem+'" style="float:left; padding-left:2px; padding-right:10px; padding-bottom: 2px;" />'+
												'<span class="style11">'+n.titulo +'</span><br><b>'+ n.hora +'</b>'+
												'<span class="news_show"><br><br>'+ n.materia +'</span>'+
												'<br><br>';							
											});									
											$('#Noticia').html(noticia);
											
											//2
											//retornar('defalt');
											$('a[@tipo=retornar]').click(function(){
												retornar('defalt');
												var text = $('#buscar').val();
												$('#tbNoticia').fadeOut('slow',
														function(){
															if(text==''){
																carregaNoticias(objCanal, 1);
																$('#tabelaInicial').fadeIn('slow');
															}else{
																carregaBusca(text);
															}
															
														}
												);
											});
											
										}//fim da function fade
									);
									
																
								},//fim da function sucess					
							error:
								function(){
									alert("Erro no carregamento function(carregaNoticia) pg: controle.js");
								}	
					});//fim do ajax	
				}
		);
	
	
	}
	
	
	
	function montaRios(data){
	
		$('#tdRios').html('<img src="../_imgs/ajaxLoader_1.gif" alt="" width="32" height="32" /><br>Carregando ...');
	
		$.ajax({
			type: "POST",
			dataType: "json",
			data: { data: data },
			url: "modelo/buscaAjax_Rios.asp",
			success:
				function(json){
				if(json[0].rio != 0){
					var tbRios = '';
					var dtCosulta;
					$.each(json, function(i, n){
						dtCosulta = n.data;
						tbRios = tbRios +
						'<table width="100%" cellpadding="0" cellspacing="0">'+
						'<tr bgcolor="#FFFFCC">'+
						'<td width="30%" style="text-align:left;"><b>'+n.Ladario+'</b></td>'+
						'<td width="70%" style="text-align:left;"><p class="style23">'+n.s_ladario+'</p>'+
						'</td>'+
						'</tr>'+
						'<tr>'+
						'<td style="text-align:left;"><b>'+n.Murtinho+'</b></td>'+
						'<td style="text-align:left;"><p class="style20">'+n.s_murtinho+'</p>'+
						'</td>'+
						'</tr>'+
						'<tr bgcolor="#FFFFCC">'+
						'<td style="text-align:left;"><b>'+n.Caceres+'</b></td>'+
						'<td style="text-align:left;"><p class="style23">'+n.s_caceres+'</p>'+
						'</td>'+
						'</tr>'+
						'<tr>'+
						'<td style="text-align:left;"><b>'+n.Coimbra+'</b></td>'+
						'<td style="text-align:left;"><p class="style20">'+n.s_coimbra+'</p>'+
						'</td>'+
						'</tr>'+
						'<tr bgcolor="#FFFFCC">'+
						'<td style="text-align:left;"><b>'+n.Cuiaba+'</b></td>'+
						'<td style="text-align:left;"><p class="style23">'+n.s_cuiaba+'</p>'+
						'</td>'+
						'</tr>'+
						'<tr>'+
						'<td style="text-align:left;"><b>'+n.BelaVista+'</b></td>'+
						'<td style="text-align:left;"><p class="style20">'+n.s_belavista+'</p>'+
						'</td>'+
						'</tr>'+
						'</table>'				
					});
					
					$('#dtMedicao').html('<b>Data da Medi&ccedil;&atilde;o: </b>'+dtCosulta);
					$('#tdRios').html(tbRios);
				}else{
					$('#dtMedicao').html('<br><br><b>Data da Medi&ccedil;&atilde;o: </b>'+data);
					$('#tdRios').html('N&atilde;o existe medi&ccedil;&atilde;o para essa data!');
				}
				
				},
			error:
				function(){
					alert("Erro no carregamento function(carregaNoticia) pg: controle.js");
				}	
		});//fim do ajax
	}
		
		function classificados(){
		$('#classificados').load('../classificados/default.asp?rnd='+numRnd(), {},
			function(){
				
				$('a[@rel=facebox]').facebox();
	
				$('a[@tipo=classificados]').click(function(){
					$('td[@tipo=flash]').hide();//esconde os flashs
					var id = getAttr(this.id, 'id');
					carregaCategoria(id);
				});
				
			}
		);
	}
	
	function carregaCategoria(id){
		$('#Modal2').load('../classificados/viewads.asp?CatID='+id+'&rnd='+numRnd(), { param: 'vazio' },
			function(){
				$('#classAdd').click(function(){
					var cod = getAttr(this.id, 'cod');
					carregaFormCad(cod);				
				});
				
				$('a[@tipo=detalhes]').click(function(){
					var cod = this.id;
					carregaDetalhe(cod, id);//id refere-se a categoria
				});
				
				$('#close > a').click(function(){//imagem de fechar o modal
					$('td[@tipo=flash]').show();//mostra os flashs
					//classificados();
				});
				
			}
		);
	}
	
	function carregaDetalhe(cod, idCat){
		$('#Modal').html('Carregando...<br><img src="../_imgs/ajax-loader.gif"/>');
		$('#Modal').load('../classificados/viewdetail.asp?id='+cod, { }, 
				function(){
					$('#dtVoltar').click(function(){
						carregaCategoria(idCat);
					});
				}
		);
	}
	


	function carregaColuna(id, colunista){
		$('#Noticia').html('Carregando...<br><img src="../_imgs/ajax-loader.gif"/>');
		$('#tabelaInicial').fadeOut('slow',
		function(){
			$('#tbNoticia').fadeIn('slow',
			function(){
				$.ajax({
					 type: "POST",
					 dataType: "json",
					 data: { colunista: id},
					 url: "modelo/buscaAjax_Colunistas.asp",
					 success:
						function(json){									
							var coluna = '';
							$.each(json, function(i, n){
								titulo = left(json[i].titulo, 90);				
								coluna = coluna +
									'<tr id="trColuna'+i+'" style="cursor:hand;" tipo="trNoticia" cod="'+json[i].codigo+'">'+
									'<td width="15%" aling="left" valing="top" style="vertical-align:top; text-align:left;">'+
									'<b>'+json[i].data+' </b></td>'+
									'<td width="85%" aling="left" valing="top">'+
									'<a id="'+json[i].codigo+'" href="#" style="font-weight: none;">'+titulo+'</a></td>'+
									'</tr>';
							});
						 						   
							$('#Noticia').html('<table id="Coluna" width="100%" aling="left" valing="top" style="text-align:left;">'+
												''+coluna+'</table>');
							//3
							$('a[@tipo=retornar]').click(function(){
								//retornar('defalt');
								$('#tbNoticia').fadeOut('slow',
									function(){
										carregaNoticias(objCanal, 1);
										$('#tabelaInicial').fadeIn('slow');
								});
							});
							
							$('#Coluna a').click(function(){
								carregaNoticia(this.id, '');
							});
							
							
						}						
				});//fim do ajax				
			});
		});
	}


	function carregaMais(canal, data){
		if( (data == '') ){
			montaMais(objNoticias, canal);
		}else{
			$('#Noticia').html('Carregando...<br><img src="../_imgs/ajax-loader.gif"/>');
			$('#tabelaInicial').fadeOut('slow',
			function(){
				$('#tbNoticia').fadeIn('slow',
				function(){
					$.ajax({
						 type: "POST",
						 dataType: "json",
						 data: { 
									canal: canal,
									data: data
								},
						 url: "modelo/buscaAjax_Noticias.asp",
						 success:
							function(json){
								if(json[0].noticia == 0){
									$('#Noticia').html('Carregando...<br><img src="../_imgs/ajax-loader.gif"/>');
									$('#tabelaInicial').fadeOut('slow',
										function(){
											$('#tbNoticia').fadeIn('slow',
												function(){
													$('#Noticia').html('<table id="Coluna" width="100%" aling="left" valing="top" style="text-align:left;">'+
												   '<tr><td align="left" valign="middle"><h2 class="style24">'+canal+'</h2></td></tr>'+
												   '<tr><td aling="left"><b>Escolha outra data: </b>'+
												   '<input name="text" type="text" id="dtNoticias" cod="'+canal+'" value="" size="8" /></td></tr>'+
												   '<tr><td>Nenhuma noticia relacionada para essa data: <b>'+data+'</b> Canal: <b>'+canal+'</b></td></tr>'+
												   '</table>');
													$('#dtNoticias').focus(function(){
														$('#dtNoticias').datepicker();
													});
													$('#dtNoticias').change(function(){
														var data = $('#dtNoticias').val();
														carregaMais(canal, data);
													});
												}
											);
										}
									);			
								}else{
									montaMais(json, canal);								
								}
							}						
					});//fim do ajax				
				});
			});
		}
	}
	
	

	function montaMais(json, canal){

		$('#Noticia').html('Carregando...<br><img src="../_imgs/ajax-loader.gif"/>');
		$('#tabelaInicial').fadeOut('slow',
		function(){
			$('#tbNoticia').fadeIn('slow',
				function(){
					var noticias = '';
					$.each(json, function(i, n){
						titulo = left(json[i].titulo, 90);				
						noticias = noticias +
							'<tr id="trColuna'+i+'" style="cursor:hand;" tipo="trNoticia" cod="'+json[i].codigo+'">'+
							'<td width="20%" aling="left" valing="top" style="vertical-align:top; text-align:left;">'+
							'<b>'+json[i].hora+' </b></td>'+
							'<td width="80%" aling="left" valing="top">'+
							'<a id="'+json[i].codigo+'" href="#" style="font-weight: none;">'+titulo+'</a></td>'+
							'</tr>';
					});
				
					$('#Noticia').html('<table id="Coluna" width="100%" aling="left" valing="top" style="text-align:left;">'+
									   '<tr><td colspan="2" align="left" valign="middle"><h2 class="style24">'+canal+'</h2></td></tr>'+
									   '<tr><td colspan="2" aling="left"><b>Filtrar por Data: </b>'+
									   '<input name="text" type="text" id="dtNoticias" cod="'+canal+'" value="" size="8" /></td><tr>'+
									   ''+noticias+'</table>');
					
					
					$('#dtNoticias').focus(function(){
						$('#dtNoticias').datepicker();
					});
					
					$('#dtNoticias').change(function(){
						var data = $('#dtNoticias').val();
						carregaMais(canal, data);
					});
					
					//4
					//retornar('defalt');
					$('a[@tipo=retornar]').click(function(){
						$('#tbNoticia').fadeOut('slow',
							function(){
								carregaNoticias(objCanal, 1);
								$('#tabelaInicial').fadeIn('slow');
						});
					});
					
					
					$('#Coluna a').click(function(){
						carregaNoticia(this.id, '');
					});
				}
			);	
		});
	}

	var chaveBusca;
	function carregaBusca(chave){
		chaveBusca = chave;
		$('#Noticia').html('Carregando...<br><img src="../_imgs/ajax-loader.gif"/>');
		$('#tabelaInicial').fadeOut('slow',
			function(){
				$('#tbNoticia').fadeIn('slow',
				function(){
					$.ajax({
						 type: "POST",
						 dataType: "json",
						 data: { 
									chave: chave
								},
						 url: "modelo/buscaAjax_Consulta.asp",
						 success:
							function(json){
								if(json[0].noticia == 0){
									$('#Noticia').html('Carregando...<br><img src="../_imgs/ajax-loader.gif"/>');
									$('#tabelaInicial').fadeOut('slow', function(){
											$('#tbNoticia').fadeIn('slow', function(){
													$('#Noticia').html('<table id="Coluna" width="100%" '+
																	 'aling="left" valing="top"style="text-align:left;">'+
 																	 '<tr><td>Nenhuma noticia relacionada para esse '+
																	 'criterio de pesquisa: <b>'+chave+'</b></td></tr>'+
												   					 '</table>');
											});
									});
								}else{
									montaBusca(json, chave);
								}
							}						
					});//fim do ajax				
				});
			});
		}





	function montaBusca(json, chave){
		$('#Noticia').html('Carregando...<br><img src="../_imgs/ajax-loader.gif"/>');
		$('#tabelaInicial').fadeOut('slow',
		function(){
			$('#tbNoticia').fadeIn('slow',
				function(){
					var noticias = '';
					$.each(json, function(i, n){
						titulo = left(json[i].titulo, 90);				
						noticias = noticias +
							'<tr id="trColuna'+i+'" style="cursor:hand;" tipo="trNoticia" cod="'+json[i].codigo+'">'+
							'<td width="15%" aling="right" valing="top" style="vertical-align:top; text-align:left;">'+
							'<b>'+json[i].data+' </b></td>'+
							'<td width="85%" aling="left" valing="top">'+
							'<a id="'+json[i].codigo+'" href="#" style="font-weight: none;">'+titulo+'</a></td>'+
							'</tr>';
					});
				
					$('#Noticia').html('<table id="Coluna" width="100%" aling="left" valing="top" style="text-align:left;">'+
									   ''+noticias+'</table>');
					
					/*
					$('#dtNoticias').focus(function(){
						$('#dtNoticias').datepicker();
					});
					
					$('#dtNoticias').change(function(){
						var data = $('#dtNoticias').val();
						carregaMais(canal, data);
					});
					*/
					
					//5
					retornar('busca');
					$('a[@tipo=retornar]').click(function(){
						//retornar('busca');
						$('#tbNoticia').fadeOut('slow',
							function(){
								carregaNoticias(objCanal, 1);
								$('#tabelaInicial').fadeIn('slow');
						});
					});
					
					
					$('#Coluna a').click(function(){
						carregaNoticia(this.id, chave);
					});
				}
			);	
		});
	}
	
	
	
	function buscaColunista(colunista){
		$.ajax({
			 type: "POST",
			 dataType: "json",
			 data: { colunista: colunista },
			 url: "modelo/buscaAjax_Colunista.asp",
			 success:
				function(json){
					var materia = json[0].titulo;
					$('#td'+colunista).html('<a href="#" tipo="colunaIndex" id="'+json[0].codigo+'">'+materia+'</a><br>'+
											'<a id="'+colunista+'" tipo="coluna" href="#">mais materias(+).</a>');
					
					$('a[@tipo=colunaIndex]').click(function(){
						carregaNoticia(this.id, '');					
					});
					
					$('a[@tipo=coluna]').click(function(){
						carregaColuna(this.id, colunista);
					});
				}
		});
	}
	
	
	
	function montaTemperatura(){
			$.ajax({
			 type: "POST",
			 dataType: "json",
			 data: { nada: 'parametro nulo' },
			 url: "modelo/buscaAjax_Tempo.asp",
			 success:
				function(json){
					$('#tdImagem').html('<img src="../_imgs/tempo/'+json[0].imagem+'.gif" alt="" width="20" height="20" />');
					$('#tdMinima').html(json[0].minima+'&deg;');
					$('#tdMaxima').html(json[0].maxima+'&deg;');
				}
			});
	}
	
	
	function carregaBanner(id){
		$.ajax({
		 type: "POST",
		 dataType: "json",
		 data: { banner: id },
		 url: "modelo/buscaAjax_Banners.asp",
		 success:
			function(json){
				
				if(json[0].banner==0){
					void 0;
				}else{
					
					if(id!=3){
						qtd = json.length;
						rnd = numRnd(qtd);
						var banner = '';
						banner = banner +
						'<div>'+
						'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
						'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"'+
						'width="468" height="60"><param name="movie" value="'+json[rnd].banner+'" />'+
						'<param name="quality" value="high" /><embed src="'+json[rnd].banner+'" '+
						'quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" '+
						'type="application/x-shockwave-flash" width="468" height="60"></embed></object>'+
						'</div>'								
						$('#banner0'+id).html(banner);
					}else{
						qtd = json.length;
						rnd = numRnd(qtd);
						var banner = '';
						banner = banner +
						'<div>'+
						'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
						'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"'+
						'width="278" height="67"><param name="movie" value="'+json[rnd].banner+'" />'+
						'<param name="quality" value="high" /><embed src="'+json[rnd].banner+'" '+
						'quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" '+
						'type="application/x-shockwave-flash" width="278" height="67"></embed></object>'+
						'</div>'								
						$('#banner0'+id).html(banner);					
					}

				}								

			}
		});
	}
	
	
	
	function votaEnq(CodEnq, CodResp){
		$("#tdEnquete").load(
			'../Enquetes/ShowResultEnquete.asp',
			{Enq:CodEnq, Resp:CodResp},
			function(){
				var i = 1;
			}
		);
	}
	
	
	function retornar(local){
		

	};
