  function initSlider() {
        function startSliderTimer() {
            resetSliderTimer();
            timer = setInterval(function() { current.next().click(); }, 100);
        }

        function resetSliderTimer() {
            clearInterval(timer);
        }

        $('#slider').hover(
            function() {
                $('#slider-pagination').stop(true, true).slideDown();
            },
            function() {
                $('#slider-pagination').slideUp();
            }
        );

		if($("#slider-pagination-items").length > 0){
			var firstSlide = $('#slider-pagination-items img:first');
			var current    = null;
			var timer      = null;
	
			$('#slider-pagination-items ul').carouFredSel({
				'next'  : {
					'button'   : '#slider-pagination-next',
					'onAfter'  : startSliderTimer,
					'onBefore' : resetSliderTimer
				},
				'prev'  : {
					'button'   : '#slider-pagination-prev',
					'onAfter'  : startSliderTimer,
					'onBefore' : resetSliderTimer
				},
				'items' : 5,
				'auto'  : {'play' : false}
			});
	
			$('#slider-pagination-items li:first').addClass('activeSlide')
			$('#slider-pagination-items li').each(function() {
				$(this).click(function() {
					resetSliderTimer();
	
					var $this        = $(this);
					var currentPhoto = $('#slider-photo img');
					var thumbUrl     = $(this).find('img').attr('src');
					var nextPhoto    = $('<img src="' + thumbUrl.replace(/_th(\.(?:jpe?g|bmp|gif|png))$/, '$1') + '" />').hide();
	
					currentPhoto.fadeOut('slow', function() {
						$(this).remove();
	
						$('#slider-pagination-items li').removeClass('activeSlide');
						$this.addClass('activeSlide');
					});
	
					$('#slider-photo').append(nextPhoto);
					nextPhoto.fadeIn('slow');
					current = $this;
					
					startSliderTimer();
				});
			});

			$('#slider-pagination').slideUp();
			$('#slider-pagination-items li:first').click();
			if($("#slider-pagination-items").length > 0){
				startSliderTimer();
			}
	
			function startSliderTimer() {
				if ( timer ){
					resetSliderTimer();
				}
				
				timer = setInterval(function() { (current.next().length ? current.next() : current.parent().children().first()).click(); }, 5000);
			}
	
			function resetSliderTimer() {
				clearInterval(timer);
			}
		}
    }

	$(document).ready(function() {
	$('#children').keyup(function() {
            var childrenField = $('#children_field');
            var children      = parseInt($(this).val(), 10);
            var maxChildren   = 20;

            if( isNaN(children) )
            {
                for ( var i = 1; i <= maxChildren; i++ )
                {
                    $('#child_age_field_' + i).remove();
                }
            }
            else
            {
                children = Math.min(Math.max(children, 0), maxChildren);

                for ( var i = 1; i <= children; i ++ )
                {
                    if ( !$('#child_age_field_' + i).length )
                    {
                        var childAgeField = $(
                            '<p class="flottante-c" id="child_age_field_' + i + '">' +
                                '<label for="child_age_' + i + '" class="generica">età bambino ' + i + ' <span class="rosso">*</span>:</label>' +
                                '<input id="child_age_' + i + '" name="child_age_' + i + '" type="text" class="required lungo" value="0" size="" />' +
                            '</p>'
                        );

                        if ( i == 1 )
                        {
                            childAgeField.insertAfter(childrenField);
                        }
                        else
                        {
                            childAgeField.insertAfter($('#child_age_field_' + (i - 1)));
                        }
                    }
                }

                for ( var i = children + 1; i <= maxChildren; i++ )
                {
                    $('#child_age_field_' + i).remove();
                }
            }
        });
        $('#send-to').dialog({
            autoOpen: false,
            buttons: {
                'Invia messaggio': function() {
                    $this = $(this).parents('.ui-dialog');

                    $('#send-to form').ajaxSubmit({
                        beforeSubmit: function() {
                            $('#send-to .errore').text('');
                            $this.block({message: null});
                        },
                        success: function(response) {
                            response = eval('(' + response + ')');

                            switch ( response.status )
                            {
                                case 'fail':
                                    $.each(response.errors, function(name, message) {
                                        $('#st_' + name + '_label').text(message);
                                    });
                                break;
                                case 'success':
                                    $('#send-to .errore').text('');
                                    $('#send-to').dialog('close');
                                break;
                            }

                            var dialog = $('<div />');
                            dialog.text(response.message);
                            dialog.dialog({
                                buttons: {
                                     'Ok': function() {$(this).dialog('close');}
                                },
                                modal: true,
                                resizable: false,
                                title: 'Invia a un amico'
                            });
                            
                            $this.unblock();
                        }
                    });
                }
            },
            resizable: false,
            title: 'Invia a un amico',
            width: '600px'
        });
        $('#send-to-button').click(function() {
            $('#send-to').dialog('open');

            return false;
        });
							   
		$("a[rel='gallery']").colorbox();
		$("a[rel='video']").colorbox({iframe:true, innerWidth:425, innerHeight:344,current: ' '});
		
        $('a[rel=external]').click(function() {
            window.open($(this).attr('href'));
            return false;
        });
		$("#form-prenota").submit(function(){
			if($("#datadiarrivo").val() == ""){
				var currentTime = new Date();
				var month = currentTime.getMonth();
				var day = currentTime.getDate() + 1;
				var year = currentTime.getFullYear();

				$("#datadiarrivo").val(year + "-" + month + "-" + day);
			}
			if($("#datadipartenza").val() == ""){
				var currentTime = new Date();
				var month = currentTime.getMonth();
				var day = currentTime.getDate() + 2;
				var year = currentTime.getFullYear();

				$("#datadipartenza").val(year + "-" + month + "-" + day);
				
				
				if($("#datadiarrivo").val() != ""){
					varlist = $("#datadiarrivo").val();
					nlist = varlist.split("-");
					var currentTime = new Date(nlist[0],nlist[1],nlist[2]);
					var month = currentTime.getMonth();
					var day = currentTime.getDate() + 1;
					var year = currentTime.getFullYear();
	
					$("#datadipartenza").val(year + "-" + month + "-" + day);
				}
			}
			
			var formData = $(this).serialize();
			
			$.colorbox({iframe:true, innerWidth:960, innerHeight:700,href: $(this).attr("action")+"?"+formData }); 
			return false;
		});
		
		//When page loads...
		$(".tab_content").hide(); //Hide all content
		$("ul.tabs li:first").addClass("active").show(); //Activate first tab
		$(".tab_content:first").show(); //Show first tab content
	
		//On Click Event
        $("ul.tabs li").click(function() {

            $("ul.tabs li").removeClass("active"); //Remove any "active" class
            $(this).addClass("active"); //Add "active" class to selected tab
            $(".tab_content").hide(); //Hide all tab content

            var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
            $(activeTab).fadeIn(); //Fade in the active ID content
            return false;
        });

        $("#slider-servizi").jCarouselLite({
            btnNext: "#next2",
            btnPrev: "#prev2",
            auto: false,
            speed: 500,
            circular: true,
            visible: 2,
            scroll: 1
        });

	$(".datepicker").datepicker();
	$("#focus-dataarrivo").css({'cursor':'pointer'});
	$("#focus-dataarrivo").click(function(){
		$("#datadiarrivo").focus();
	});
	
	
	$("#focus-datapartenza").css({'cursor':'pointer'});
	$("#focus-datapartenza").click(function(){
		$("#datadipartenza").focus();
	});
	
	$(".form-generico").each(function(){
		$(this).validate();
	});

    initSlider();
	$('.ui-tabs').tabs({fx: {opacity: 'toggle'}});

	if($("#map").length > 0){
		showmaps();	
	}
					  
});
	

