﻿$(document).ready(function(){
	
	$("#cont").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
	
	$("#list_avare").mouseover(function(){
		$("#sub_avare").show();
	});
	
	
	$("#list_avare").mouseout(function(){
		$("#sub_avare").hide();
	});
	
	$("#list_bauru").mouseover(function(){
		$("#sub_bauru").show();
		
	});
	
	$("#list_bauru").mouseout(function(){
		$("#sub_bauru").hide();
	});
	
	$("#list_botucatu").mouseover(function(){
		$("#sub_botucatu").show();
		
	});
	
	$("#list_botucatu").mouseout(function(){
		$("#sub_botucatu").hide();
	});
	
	$("#list_curitiba").mouseover(function(){
		$("#sub_curitiba").show();
	});
	
	$("#list_curitiba").mouseout(function(){
		$("#sub_curitiba").hide();
	});
	
	$("#list_saojose").mouseover(function(){
		$("#sub_saojose").show();
	});
	
	$("#list_saojose").mouseout(function(){
		$("#sub_saojose").hide();
	});
	
	$("#list_saopaulo").mouseover(function(){
		$("#sub_saopaulo").show();
	});
	
	$("#list_saopaulo").mouseout(function(){
		$("#sub_saopaulo").hide();
	});
	
	$("#list_saobernardo").mouseover(function(){
		$("#sub_saobernardo").show();
	});
	
	$("#list_saobernardo").mouseout(function(){
		$("#sub_saobernardo").hide();
	});
	
	$("#list_sorocaba").mouseover(function(){
		$("#sub_sorocaba").show();
	});
	
	$("#list_sorocaba").mouseout(function(){
		$("#sub_sorocaba").hide();
	});
	
	
		      $("#avare_1," +
		  		"#avare_2," +
		  		"#bauru_1," +
				"#botucatu_1," +
		  		"#curitiba_1," +
		  		"#saojose_1," +
		  		"#saopaulo_1," +
		  		"#saopaulo_2," +
		  		"#saopaulo_3," +
		  		"#saobernardo_1," +
		  		"#sorocaba_1," +
		  		"#sorocaba_2").click(function(){
		  			$("#cont").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
										$.ajax({
											url: "hoteis/" + $(this).attr("name"),
											success:function(h){
											$("#cont").html(h);
										}
										});
									
									});
	//---------------------
	
	//---------------------
	
	
	$(".logotop").click(function(){
		
		$("#cont").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
		
		$.ajax({
			url: "index/cont",
			success: function(j){
			
			$("#cont").html(j);
			
			$("#bt_promocao").click(function(){
				$("#cont").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
				$.ajax({
					url: "promocao",
					success: function(c){
					$("#cont").html(c);
					
					$(".link_promo").click(function(){
						$("#noticia_corpo").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
						$.ajax({
							url: $(this).attr("name"),
							success: function(c){
							$("#noticia").html(c);
						}
						});
					});
				}
				});
			});
			
			//---------------------------
			
			$("#bt_noticias").click(function(){
				$("#cont").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
				$.ajax({
					url: "noticias",
					success: function(c){
					$("#cont").html(c);
					
					$(".link_noticia").click(function(){
						$("#noticia_corpo").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
						$.ajax({
							url: $(this).attr("name"),
							success: function(c){
							$("#noticia").html(c);
						}
						});
					});
					
					//----------------------------
				}
				});
			});
			
			//----------------------------
			
		}
			
		});
		
		
								});
	
	$("#mn_quemsomos").click(function(){
		$("#cont").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
		$.ajax({
			url: "quemsomos",
			success: function(c){
			$("#cont").html(c);
		}
			
		});
		
		
										});
	
		
	$("#mn_promocao").click(function(){
		$("#cont").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
		$.ajax({
			url: "promocao",
			success: function(c){
			$("#cont").html(c);
			$(".link_promo").click(function(){
						$("#noticia_corpo").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
						$.ajax({
							url: $(this).attr("name"),
							success: function(c){
							$("#noticia").html(c);
						}
						});
					});
		}
			
		});
									});
	
		
	$("#mn_hoteis").click(function(){
		$("#cont").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
		$.ajax({
			url: "hoteis",
			success: function(c){
			$("#cont").html(c);

			$(".detalhes").click(function(){
		  			$("#cont").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
										$.ajax({
											url: "hoteis/" + $(this).attr("name"),
											success:function(h){
											$("#cont").html(h);
										}
										});
									
									});
		}
			
		});
									});
	
		
	$("#mn_noticias").click(function(){
		$("#cont").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
		$.ajax({
			url: "noticias",
			success: function(c){
			$("#cont").html(c);
			$(".link_noticia").click(function(){
					$("#noticia").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
				$.ajax({
					url: $(this).attr("name"),
					success: function(c){
					$("#noticia").html(c);
				}
				});
			});
		}
			
		});
		
		
		
		//----------------------------
									});
	
		
	$("#mn_contato").click(function(){
		$("#cont").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
		$.ajax({
			url: "contato",
			success: function(c){
			$("#cont").html(c);
		}
			
		});
									});
	
	
	$("#bt_busca").click(function(){
		$("#cont").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
		$.ajax({
			url: "busca",
			success: function(c){
			$("#cont").html(c);
		}
			
		});
									});
	
	//------------carregando as paginas
	$.ajax({
		url: "index/cont",
		//url: "hoteis", //-------testando
		success: function(j){		
		
		$("#cont").html(j);
		
		$("#bt_promocao, #mn_promocao").click(function(){
			$("#cont").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
			$.ajax({
				url: "promocao",
				success: function(c){
				$("#cont").html(c);
				$(".link_promo").click(function(){
						$("#noticia_corpo").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
						$.ajax({
							url: $(this).attr("name"),
							success: function(c){
							$("#noticia").html(c);
						}
						});
					});
			}
			});
		});
		
		/*$("#testeiframe").click(function(){
							$("#cont").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
							$.ajax({
								   url:"reservas",
								   success:function(d){
									$("#cont").html(d);   
								   }
								   });
										 });*/
		
		//----------------------------------
		
		$("#bt_noticias").click(function(){
			$("#cont").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
			$.ajax({
				url: "noticias",
				success: function(c){
				$("#cont").html(c);
				
				$(".link_noticia").click(function(){
					$("#noticia").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
					$.ajax({
						url: $(this).attr("name"),
						success: function(c){
						$("#noticia").html(c);
					}
					});
				});
				
				//----------------------------
			}
			});
			
			
		});
		
		//-----------------------------------
		
	
		
		
	}
									 });
	
	






});// end of document -> ready(function



function busca(tecla) {
	var termo = $(".busca").val();
	
		if((tecla == 13 || tecla == 8 || tecla == 32 || (tecla >= 112 && tecla <=123))){
			//alert('Apertou enter');
		} else {
			$.ajax({
				   url:"busca/index/termo/"+termo,
				   success:function(g){
					   $("#resposta").css({"display" : "block"});
					   $("#resposta").html("<ul>"+g+"</li>");
					   $(".fechaBusca").click(function(){
												 $("#resposta").css({"display" : "none"});	
												 document.getElementById("busca").value = "";
													   });
				   }
				   });
		}
}
		
		
function enviar_contato()
		{
			var dados = new Array();
			dados[0] = $("#frm_contato");
			dados[1] = $("#nome");
			dados[2] = $("#email");
			dados[3] = $("#tel");
			dados[4] = $("#cidade");
			dados[5] = $("#msg");
			
			parte1 = dados[2].val().indexOf("@");
			parte2 = dados[2].val().indexOf(".");
			parte3 = dados[2].val().length;
	
			if (dados[1].val() == "" || dados[1].val() == null || !isNaN(dados[1].val()) ){
			window.alert("Digite um nome válido");
			dados[1].focus();
		
			} else if(dados[2].val() == "" || !(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
			window.alert("E-mail inválido");
			dados[2].focus();
		
			} else if (dados[3].val() == "" || dados[3].val() == null || isNaN(dados[3].val()) || dados[3].val().length <= 8 ){
			window.alert("Telefone inválido");
			dados[3].focus();
		
			} else if (dados[4].val() == "" || dados[4].val() == null){
			window.alert("Digite o nome de sua cidade");
			dados[4].focus();
			
			} else if (dados[5].val() == "" || dados[5].val() == null){
			window.alert("Digite uma mensagem");
			dados[5].focus();
			
			} else {
				
				$.post("/contato/enviar", dados[0].serialize(),
				function(d) {
					
					alert('Mensagem enviada com sucesso!');
					document.getElementById('frm_contato').reset();
						
						});
				
			
			}
		}
		
		function limpar_form() {
	document.getElementById('frm_contato').reset();
}

function noticia(id) {
	
	$("#cont").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
	$.ajax({
		   url: "noticias",
		   success: function(c){
			   $("#cont").html(c);
			   $(".link_noticia").click(function(){
												 $("#noticia_corpo").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
												 $.ajax({
														url: $(this).attr("name"),
														success: function(c){
															$("#noticia").html(c);
															
															}
															});
												 });
			   
			   
			    $.ajax({
														url: "/noticias/chamanoticia/noticia/"+id,
														success: function(c){
															$("#noticia").html(c);
															
															}
															});
			   
			   }
			   });
	
	
	
}

function hotel(id) {
	$.ajax({
		   url: "/hoteis/"+id,
		   success: function(c){
			   $("#cont").html(c);
		   }
		   });
	
}

function vaihoteis() {
	$("#cont").html("<center><img src='/public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
		$.ajax({
			url: "hoteis",
			success: function(c){
			$("#cont").html(c);

			$(".detalhes").click(function(){
		  			$("#cont").html("<center><img src='public/default/images/carregando.gif' style='margin-top:50px;'/></center>");
										$.ajax({
											url: "hoteis/" + $(this).attr("name"),
											success:function(h){
											$("#cont").html(h);
										}
										});
									
									});
		}
			
		});
}
			
			
			
			
	
