$(function(){

 $('input[type=text], input[type=email], form textarea').focus(function(){
    if ($(this).val()===$(this).attr('placeholder'))
    {
     $(this).val('');
    }
   })   
 
  $('input[type=text], input[type=email], form textarea').blur(function(){
    if ($(this).val()==='')
    {
     $(this).val($(this).attr('placeholder'));
    }
   })  	
   

$('.titulo, .texto-banner').animate({width:'show'},500);
  
//$('#slideshow').tinycarousel({ interval: true, intervaltime:6000});

$('#slideshow .viewport').carousel({effect:"fade", autoSlide:true, animSpeed:1000, autoSlideInterval:9000, prevBtn:'#volta', nextBtn:'#vai'});

$('#slide-fotos-lazer').tinycarousel({ interval: true, intervaltime:5000});

//$('#slide-fotos .viewport').carousel({effect:"fade", autoSlide:true, animSpeed:1000, autoSlideInterval:8000, prevBtn:'#slide-fotos .prev', nextBtn:'#slide-fotos .next'});

$('#slide-fotos .overview').cycle({fx:'fade', next:'#slide-fotos .next', prev:'#slide-fotos .prev'});

$('#slider-overlay').cycle({fx:'fade', next:'.slideshow-acomodacoes #ant', prev:'.slideshow-acomodacoes #prox', animSpeed:1000, autoSlideInterval:9000});

$('#slider-menor').cycle({fx:'fade', next:'#proxmenor', prev:'#antmenor', animSpeed:1000, autoSlideInterval:9000});

$('#slide-fotos a, .carousel-control a').click(function(c){
	c.preventDefault();
})

/*$('#slide-fotos1').tinycarousel({ interval: true, axis:'y', intervaltime:6000, callback: function(element, index){
	var texto = $(element).children('a').attr('title');
	var titulo = $(element).children('a').attr('rel');
	$('#titulo-lazer').fadeOut().fadeIn().text(titulo);
	$('#texto-lazer').fadeOut().fadeIn().text(texto);	
	}
});*/

$('#slide-fotos1 .overview').cycle({fx:'fade', next:'#slide-fotos1 .next', prev:'#slide-fotos1 .prev', after:Troca, animSpeed:1000, autoSlideInterval:6000});

function Troca(){
	var texto = $(this).attr('title');
	var titulo = $(this).attr('rel');
	$('#titulo-lazer').fadeOut().fadeIn().text(titulo);
	$('#texto-lazer').fadeOut().fadeIn().text(texto);	
}

/*
$('#slide-fotos-lazer').tinycarousel({ interval: true, intervaltime:7000, callback: function(element, index){
	var texto = $(element).children('a').attr('title');
	var titulo = $(element).children('a').attr('rel');
	$('#titulo-lazer').fadeOut().fadeIn().text(titulo);
	$('#texto-lazer').fadeOut().fadeIn().text(texto);	
	}
});*/

$('#scrollbar1').tinyscrollbar();

//$("a[rel^='prettyPhoto']").prettyPhoto({theme:'light_rounded',autoplay_slideshow: true, social_tools:false}); 

$('.menu li').hover(function(){
	$(this).append('<span></span>');
	var parente = $(this).parents('div').attr('class');
	if (parent === 'esq-div'){
		$(this).find('span').animate({top:0, right:0},300);
	} else {
		$(this).find('span').animate({top:0, left:0},300);		
	}
}, function(){
	$(this).find('span').css({right:'-100px', top:'-100px'});  	
	$(this).find('span').remove();
})

	if (!jQuery.support.opacity){		
		$('.menu span').css('left','-100px');
	}


$('.galeria-fotos a').click(function(c){
	var slideInicial = $(this).parents('li').attr('id');
	$('#loader').fadeIn();		
	$.get('overlay.php',{tabela: 'eventos', slideInicial:slideInicial}, function(conteudo){
			$('#loader').delay(5000).fadeOut();		
			$('#overlay').html(conteudo).delay(5000).fadeIn();			
	})
	c.preventDefault();
})

$('.fechar').click(function(c){
	$('#overlay').fadeOut();
	$('#slideshow .viewport').carousel({effect:"fade", autoSlide:true, animSpeed:1000, autoSlideInterval:9000, prevBtn:'#volta', nextBtn:'#vai'});

	c.preventDefault();
})

$('#slide-fotos .overview a, #abrir-galeria').click(function(c){
	var id_evento = $(this).attr('href');
		$('#loader').fadeIn();		
	$.get('overlay.php',{id_evento:id_evento, tabela:'acomodacoes'}, function(conteudo){
			$('#loader').delay(5000).fadeOut();		
			$('#overlay').html(conteudo).delay(5000).fadeIn();			
	})
	c.preventDefault();
})

$('.comodidades-lista a').click(function(c){
	var id_evento = $(this).attr('href');
	$.get('overlay.php',{id_evento:id_evento, tabela:'comodidades'}, function(conteudo){
			$('#loader').slideUp();		
			$('#overlay').html(conteudo).fadeIn();			
	})
	c.preventDefault();
})

$(document).keypress(function(e) { 
    if (e.keyCode == 27) {
	  $('div#overlay').fadeOut('normal', function(){
	  		$('#overlay').empty();			
	  	});
	 }
})



slideShow();
 
function slideShow(){
	
   function changeSlide( newSlide ) {
          clearTimeout( slideTimeout );
          currSlide = newSlide;
          if ( currSlide > maxSlide ) currSlide = 0;
          else if ( currSlide < 0 ) currSlide = maxSlide;
          $slideReel.animate({
              left : currSlide * -763
          }, 200, 'swing', function() {
              if ( currSlide == 0 ) $slidePrevNav.hide();
              else $slidePrevNav.show();
  
              if ( currSlide == maxSlide ) $slideNextNav.hide();
              else $slideNextNav.show();
              if ( activeSlideshow ) slideTimeout = setTimeout(nextSlide, 5000);
          });
  
		$('.navega-imgs li').fadeTo('fast',0.9);		    
	  	$('.navega-imgs li:eq('+currSlide+')').fadeTo('slow',1);		
     }
  
      function nextSlide() {
          changeSlide( currSlide + 1 );
      }
  
    var activeSlideshow = true,
    currSlide = 0,
    slideTimeout,
    $slideshow = $('#slider-overlay'),
    $slideReel = $slideshow.find('ul'),
    maxSlide = $slideReel.children().length - 1,
    $slidePrevNav = $('#ant'),
	$itemNav = $('.navega-imgs li');
    $slideNextNav = $('#prox');	  
  	 	 
  	
      $slidePrevNav.click(function(ev) {
          ev.preventDefault();
          activeSlideshow = false;
          changeSlide( currSlide - 1 );
      });
  
      $slideNextNav.click(function(ev) {
          ev.preventDefault();
          activeSlideshow = false;
          changeSlide( currSlide + 1 );
      });
  	 
      $('.navega-imgs li').click(function(ev) {
          ev.preventDefault();
          activeSlideshow = false;
          changeSlide( $(this).index() );
      });	 

	$('.navega-imgs li').fadeTo('fast',0.9);	  
  	$('.navega-imgs li:eq(0)').fadeTo('slow',.5);		  
  	slideTimeout = setTimeout(nextSlide, 7000);
}

 var div = $('div.navega-imgs'), ul = $('div.navega-imgs ul'), ulPadding = 15;
 var divWidth = div.width();
 div.css({overflow: 'hidden'});
 var lastLi = ul.find('li:last-child');
 div.mousemove(function(e){
   var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
   var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
   div.scrollLeft(left);
 });	

$('#enviar_contato').click(function(){
		var nome = $("#nome").val();
		var email = $("#email").val();
		var telefone = $("#telefone").val();
		var msg= $("#msg").val();
		if (nome!='' & email!='' & msg!='')
		{
			$('.loading').show();
			$('form')[0].reset();
			$('#form-contato').fadeTo("slow", 0.5);					
			$.post("envia_contato.php",{nome: nome, email:email, msg:msg, telefone:telefone},
				function(retorno){
					$('.loading').fadeOut();
					$('#resposta').html(retorno).delay(5000).fadeOut();
					$('#form-contato').fadeTo("slow", 1);					
			}) 
		}else{
					alert("Existem campos incompletos no formulário. Favor preencher todos.");
					return false;
		}
		return false;
})

$('#reservar').click(function(){
})

$('#reservar').click(function(){
	
	if ($('#concordo').is(':checked')){

		var nome = $("#nome-res").val();
		var email = $("#email-res").val();
		var telefone = $("#telefone-res").val();
		if (nome!='' & email!='' & telefone	!='')
		{
			$('.loading').show();
			$('#form-reserva').fadeTo("slow", 0.5);					
			$.post("envia_reserva.php",$('#form-reserva').serialize(),
				function(retorno){
					$('.loading').fadeOut();
					$('#resposta').html(retorno).delay(5000).fadeOut();
					$('form')[1].reset();
					$('#form-reserva').fadeTo("slow", 1);					
			}) 
		}else{
					alert("Existem campos incompletos no formulário. Favor preencher todos.");
					return false;
		}
		return false;
	} else {
	alert('Você precisa concordar com as condições de reserva.');
	return false;		
	}		
})



//slideShow2('#slider-menor','.navega-menor-imgs li', '#antmenor', '#proxmenor','-513');


function slideShow2(idslide, thumbs, ant, prox, distancia ){
	
   function changeSlide( newSlide ) {
          clearTimeout( slideTimeout );
          currSlide = newSlide;
          if ( currSlide > maxSlide ) currSlide = 0;
          else if ( currSlide < 0 ) currSlide = maxSlide;
          $slideReel.animate({
              left : currSlide * distancia
          }, 200, 'swing', function() {
              if ( currSlide == 0 ) $slidePrevNav.hide();
              else $slidePrevNav.show();
  
              if ( currSlide == maxSlide ) $slideNextNav.hide();
              else $slideNextNav.show();
              if ( activeSlideshow ) slideTimeout = setTimeout(nextSlide, 5000);
          });
  
	$(thumbs).fadeTo('fast',0.9);		    
  	$(thumbs+':eq('+currSlide+')').fadeTo('slow',1);		
      }
  
      function nextSlide() {
          changeSlide( currSlide + 1 );
      }
  
    var activeSlideshow = true,
    currSlide = 0,
    slideTimeout,
    $slideshow = $(idslide),
    $slideReel = $slideshow.find('ul'),
    maxSlide = $slideReel.children().length - 1,
    $slidePrevNav = $(ant),
	$itemNav = $(thumbs);
    $slideNextNav = $(prox);	  
  	 	 
  	
      $slidePrevNav.click(function(ev) {
          ev.preventDefault();
          activeSlideshow = false;
          changeSlide( currSlide - 1 );
      });
  
      $slideNextNav.click(function(ev) {
          ev.preventDefault();
          activeSlideshow = false;
          changeSlide( currSlide + 1 );
      });
  	 
      $(thumbs).click(function(ev) {
          ev.preventDefault();
          activeSlideshow = false;
          changeSlide( $(this).index() );
      });	 

	$(thumbs).fadeTo('fast',0.9);	  
  	$(thumbs+':eq(0)').fadeTo('slow',.5);		  
  	slideTimeout = setTimeout(nextSlide, 7000);
}


// slideShow3()

function slideShow3(){
	
   function changeSlide( newSlide ) {
          clearTimeout( slideTimeout );
          currSlide = newSlide;
          if ( currSlide > maxSlide ) currSlide = 0;
          else if ( currSlide < 0 ) currSlide = maxSlide;
          $slideReel.animate({
              left : currSlide * -763
          }, 200, 'swing', function() {
              if ( currSlide == 0 ) $slidePrevNav.hide();
              else $slidePrevNav.show();
  
              if ( currSlide == maxSlide ) $slideNextNav.hide();
              else $slideNextNav.show();
              if ( activeSlideshow ) slideTimeout = setTimeout(nextSlide, 5000);
          });
		$('.navega-imgs li').fadeTo('fast',0.9);		    
	  	$('.navega-imgs li:eq('+currSlide+')').fadeTo('slow',1);		
    }

    var activeSlideshow = true,
    currSlide = parseInt($('#slideInicial').attr('href')),
    slideTimeout,
    $slideshow = $('#slider-overlay1'),
    $slideReel = $slideshow.find('ul'),
    maxSlide = $slideReel.children().length - 1,
    $slidePrevNav = $('#ant1'),
	$itemNav = $('.navega-imgs li');
    $slideNextNav = $('#prox1');	
	 
      function nextSlide() {
          changeSlide(currSlide);
      }
  
       $slidePrevNav.click(function(ev) {
          ev.preventDefault();
          activeSlideshow = false;
          changeSlide( currSlide - 1 );
      });
  
      $slideNextNav.click(function(ev) {
          ev.preventDefault();
          activeSlideshow = false;
          changeSlide( currSlide + 1 );
      });
  	 
      $('.navega-imgs li').click(function(ev) {
          ev.preventDefault();
          activeSlideshow = false;
          changeSlide( $(this).index() );
      });	 

	$('.navega-imgs li').fadeTo('fast',0.9);	  
  	$('.navega-imgs li:eq(0)').fadeTo('slow',.5);		  
  	slideTimeout = setTimeout(nextSlide, 7000);
}

})



