$(function () {
	$("#slider").weeSlider();
	
	$("#hotel-tabs").weeTabs();
    
    $("#cadastrase").click(function () {
        newsletter('email' ,this);   
    });
    
    
    var pac_destaque = 1;
    var $pac_destaque = $("#pacotes-destaque li");
    var por_pac = MONTE_SINAI ? 3 : 12;                  //adasdasd
    var total_pac = Math.ceil($pac_destaque.length / por_pac);
    //var pac_timer = null;
    //var pac_time  = 3000;

    function next_pac() {
        var tmp = pac_destaque + 1;
        if (tmp > total_pac)
            tmp = 1;
        
        $pac_destaque.hide().slice((tmp - 1) * por_pac, tmp * por_pac).show();
        pac_destaque = tmp;
    }
    
    function prev_pac() {
        var tmp = pac_destaque - 1;
        if (tmp == 0)
            tmp = total_pac;
        
        $pac_destaque.hide().slice((tmp - 1) * por_pac, tmp * por_pac).show();
        pac_destaque = tmp;
    }
    
    //pac_timer = setInterval(next_pac, pac_time);
    
    $("#pacotes-destaque-left").click(function () {
       // clearInterval(pac_timer);
        //pac_timer = setInterval(prev_pac, pac_time);
        prev_pac(); 
    });
    $("#pacotes-destaque-right").click(function () {
        //clearInterval(pac_timer);
        //pac_timer = setInterval(next_pac, pac_time);
        next_pac(); 
    });
    
    $("#search-destino").autocomplete({
		source: function(request, response) {
			$.ajax({
				url: "http://ws.geonames.org/searchJSON",
				dataType: "jsonp",
				data: {
					featureClass: "P",
					style: "full",
					maxRows: 12,
					name_startsWith: request.term
				},
				success: function(data) {
					response($.map(data.geonames, function(item) {
						return {
							label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
							value: item.name
						}
					}))
				}
			})
		},
		minLength: 2,
		select: function(event, ui) {
            $("#search-destino").val(this.value);
			//log(ui.item ? ("Selected: " + ui.item.label) : "Nothing selected, input was " + this.value);
		},
		open: function() {
			$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
		},
		close: function() {
			$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
		}
	});

    
});
