﻿$(document).ready(function() {
	
	$('img').tooltip({
	    track: true,
	    delay: 0,
	    showURL: false,
	    showBody: " - ",
	    fade: 250
    });
	
    // FUNCAO DROP LIST
    $('.ct_drop span').click(function() {
        $(this).parent().find('.lk_drop_list').slideDown();
    })
    $('.lk_drop_list li a , .variavel_drop li a').live('click', function() {
        var val = $(this).html();
        $(this).parent().parent().parent().find('span').html(val);
        $(this).parent().parent().parent().find('input').attr('value', val);
        $(this).parent().parent().slideUp();
    });
    $('.ct_drop').hover(
        function() {

        },
        function() {
            $(this).find('.lk_drop_list , .variavel_drop').slideUp();
        }
    );
    var valor_drop = null;
    // pega o valor da drop list
    $('.variavel_drop_select li a').click(function() {
        valor_drop = $(this).attr('value');
    })
    // exibe o valo do valor_drop se nulo exibe o primeiro item ul
    $('.variavel_drop_click').click(function() {
        if (valor_drop == null) {
            $(this).find('ul:first').slideDown();
        } else {
            $(this).find('#' + valor_drop + '').slideDown();
        }
    });
    // //DROP LIST

    //CALENDARIOS

	var dataInicial = $('#date1').attr('value');
	dataInicial = new Date(dataInicial);
	$('#date1').dpSetStartDate(dataInicial.asString());
	
    $('.ip_date').datePicker();
    $('#date1').bind(
		'dpClosed',
		function(e, selectedDates) {
		    	var d = selectedDates[0];
		   		if (d) {
		        d = new Date(d);
				d = d.addDays(3);
		        $('#date2').dpSetStartDate(d.asString());
				$('#date2').attr('value', d.asString());
		    }
		});	
	
	
    //RESORTS
    $('.btResort').click(function() {

        swapValues = [];
        $(this).parent().parent().find('img').each(function(i) {
            swapValues[i] = $(this).attr('src');
            $(this).attr('src', swapValues[i].replace('_on.gif', '.gif'))
        })

        var val = $(this).find('img').attr('src');
        $(this).find('img').attr('src', val.replace('.gif', '_on.gif'));

        $(this).parent().parent().parent().find('.box').hide();
        $(this).parent().parent().parent().find('#' + $(this).attr('rel')).fadeIn();
    });

    //MODAL
    $(document).ready(function() {

        $('a[name=modal]').click(function(e) {
            e.preventDefault();

            var id = $(this).attr('href');

            var maskHeight = $(document).height() - 5;
            var maskWidth = $(window).width();

            $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

            $('#mask').fadeIn(200);
            $('#mask').fadeTo("fast", 0.5);

            //Get the window height and width
            var winH = $(window).height();
            var winW = $(window).width();

            $(id).css('top', winH / 2 - $(id).height() / 2);
            $(id).css('left', winW / 2 - $(id).width() / 2);

            $(id).fadeIn(500);
            $(id).css('visibility', 'visible');
            
        });

        $('.modal .close').click(function(e) {
            e.preventDefault();

            $('#mask').hide();
            $('.modal').hide();
        });

        $('#mask').click(function() {
            $(this).hide();
            $('.modal').hide();
        });
    });

	//ABRIR FLASH DEPOIS QUE CARREGA A PÁGINA
	$(window).load(function() {
		 var html = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='513' height='398'><param name='movie' value='flash/banner.swf' /><param name='quality' value='high' /><param name='menu' value='false' /><param name='wmode' value='transparent' /><embed src='flash/banner.swf' width='513' height='398' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' wmode='transparent'></embed></object>";
		 $('.contentConteudo .contentReservas .left').html(html);
	});
	
	//RESORTS E ATRAÇÕES
	$('.atracoes').click(function() {
        $(this).parent().find('.resorts').css('background-position', '-94px 0px');
        $(this).parent().find('.resorts').css('width', '82px');
        $(this).parent().find('.resorts').css('margin-top', '-31px');
        $(this).css('background-position', '0px');
        $(this).css('margin-left', '75px');
        $(this).css('width', '94px');
        
        $('.flick').css('display', 'block');
        $('.video').css('display', 'none');
        
        
    });
    
    $('.resorts').click(function() {
        $(this).parent().find('.atracoes').css('background-position', '-94px 0px');
        $(this).parent().find('.atracoes').css('width', '82px');
        $(this).parent().find('.atracoes').css('margin-left', '87px');
        $(this).parent().find('.atracoes').css('margin-top', '-31px');
        $(this).css('background-position', '0px');
        $(this).css('width', '94px');
        
       $('.video').css('display', 'block');
        $('.flick').css('display', 'none');
    });
	
	
	
});   
// FIM DO LOADING

//INICIALIZAÇÃO CARROSSEL
function mycarousel_initCallback(carousel) {

	// Disable autoscrolling if the user clicks the prev or next button.
	carousel.buttonNext.bind('click', function() {
		carousel.startAuto(0);
	});

	carousel.buttonPrev.bind('click', function() {
		carousel.startAuto(0);
	});

	carousel.startAuto(0);
	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
};

jQuery(document).ready(function() {
	jQuery('.mycarousel').jcarousel({
		auto: 1,
		wrap: 'last',
		initCallback: mycarousel_initCallback
	});
	
});

//DEFININDO IMAGENS QUE ABREM LIGHTBOX
$(function() {
	$('.destaque').lightBox();
	$('.hlkMais').lightBox();
	$('.jcarousel-skin-tango a').lightBox();
});

//POP UP
function abrir(URL) {

  var width = 740;
  var height = 500;

  var left = 99;
  var top = 99;

  window.open(URL,'janela', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}

//RESERVA
function buscaCM(){
    
    
    var URL = "http://reservas.beachpark.com.br/busca.aspx";
	
	try
	{
		URL = URL + "?start-date="+ document.getElementById("date1").value;
        URL = URL + "&end-date="+ document.getElementById("date2").value;
		
	}
	catch(err)
	 {
        URL = URL + "?start-date="+ document.getElementById("date1").value;
        URL = URL + "&end-date="+ document.getElementById("date2").value;
	 }
	
    URL = URL + "&adultos="+ document.getElementById("hddAdultos").value;
    URL = URL + "&criancas="+ document.getElementById("hddCriancas").value;
	window.location = URL;    
}




//RESERVA
function buscaCM2(){
    
    
    var URL = "http://reservas.beachpark.com.br/busca.aspx";
	
	try
	{
		URL = URL + "?start-date="+ document.getElementById("date1b").value;
        URL = URL + "&end-date="+ document.getElementById("date2b").value;
		
	}
	catch(err)
	 {
        URL = URL + "?start-date="+ document.getElementById("date1b").value;
        URL = URL + "&end-date="+ document.getElementById("date2b").value;
	 }
	
    URL = URL + "&adultos="+ document.getElementById("hddAdultosb").value;
    URL = URL + "&criancas="+ document.getElementById("hddCriancasb").value;
	window.location = URL;    
}

function buscaCM3(){
    
    
    var URL = "http://reservas.beachpark.com.br/busca.aspx";
	
	try
	{
		URL = URL + "?start-date="+ document.getElementById("date1c").value;
        URL = URL + "&end-date="+ document.getElementById("date2c").value;
		
	}
	catch(err)
	 {
        URL = URL + "?start-date="+ document.getElementById("date1c").value;
        URL = URL + "&end-date="+ document.getElementById("date2c").value;
	 }
	
    URL = URL + "&adultos="+ document.getElementById("hddAdultosc").value;
    URL = URL + "&criancas="+ document.getElementById("hddCriancasc").value;
	window.location = URL;    
}





function passaId(obj, val)
{
	document.getElementById(obj).value = val;	
}


