// JavaScript Engine

	jQuery(document).ready(function(){
	
	jQuery('#slider').slides({
			container: "slides",
			effect: "fade",
			pagination: false,
			generatePagination: false,
			play: 5000,
				pause: 500,
				fadeSpeed: 550,
				hoverPause: true
		});
	
	// Pirobox
	jQuery('.ngg-gallery-thumbnail a, .banner.lb a').piroBox({
			my_speed: 400, //animation speed
			bg_alpha: 0.1, //background opacity
			slideShow : false, // true == slideshow on, false == slideshow off
			slideSpeed : 4, //slideshow duration in seconds(3 to 6 Recommended)
			close_all : '.piro_close,.piro_overlay'// add class .piro_overlay(with comma)if you want overlay click close piroBox

	});
	
	// News ticker
	jQuery('#ticker').innerfade({
			speed: 2000,
			timeout: 5000,
			type: 'random',
			containerheight: '80px'
	});
	
	// Change lang
	jQuery("#flag a").hover(function() {
	jQuery(this).next("em").animate({opacity: "show", right: "40"}, "slow");
	}, function() {
	jQuery(this).next("em").animate({opacity: "hide", right: "50"}, "slow");
	});
	
		// Expand dt
	jQuery('dl#club').find('dd').hide().end().find('dt').append('<span class="open">apri</span>').toggle(function(){
				jQuery(this).find('span').attr('class','close').html('chiudi').end().next('dd').fadeIn();
			},function(){
				jQuery(this).find('span').attr('class','open').html('apri').end().next('dd').fadeOut(); 
			});
	
	
function setHeight(which) {
    var div = jQuery(which);
    div.css({height: div.height()});
}
	
	// Toggle a div with extra info		
	jQuery(".extra1, .extra2").css("display","none");
		jQuery("#toggle").click(function(){
		setHeight('.extra1');
			jQuery('.extra1').toggle(400);
   			 return false;
		});	
		jQuery("#toggle2").click(function(){
		setHeight('.extra2');
			jQuery('.extra2').toggle(400);
   			 return false;
		});	
		
	// Back to top
	jQuery(window).scroll(function () {  
        if (jQuery(this).scrollTop() != 0) {  
            jQuery('#top').fadeIn();  
        } else {  
            jQuery('#top').fadeOut();  
        }  
    });  
    jQuery('#top').click(function () {  
        jQuery('body,html').animate({  
            scrollTop: 0  
        },  
        800);  
    });
    
	// Datepicker
		jQuery('#dal,#al').focus(function(){jQuery(this).val('');})
		.datepicker({minDate: new Date(2012, 5 - 1, 24), maxDate: new Date(2012, 9 - 1, 16), showOn: "both", dateFormat: "dd/mm/yy", showAnim: "fadeIn", speed: "fast", buttonImage: "http://www.hotelparadiso.it/wp-content/themes/paradisov6/images/ico_calendar.gif", buttonImageOnly: true, hideIfNoPrevNext: true, changeMonth: false, changeYear: false });
	
	// submit form
 	jQuery('#myForm').ajaxForm(function(data) {
            if (data==1){
                jQuery('#success').fadeIn("slow");
                 jQuery('#myForm').slideUp("slow");
                jQuery('#myForm').resetForm();
            }
            else if (data==2){
                jQuery('#badserver').fadeIn("slow");
            }
            else if (data==3)
            {
                jQuery('#bademail').fadeIn("slow");
                setTimeout(function() { 
  				jQuery('#bademail').fadeOut("slow"); 
				}, 10000);
            }
        });

	// Form fields
	jQuery("#bambini").change(function() {
            var htmlString = "";
            var len = jQuery("#bambini").val();
            var nVal = 1;
            for (var i = 0; i < len; i++) {
                htmlString += '<div class="hiddenField"><p><label for="eta' + nVal + '">Et&agrave; del ' + nVal + '&deg; bambino:</label> <input type="text" name="eta[]" id="eta' + nVal + '" maxlength="15" value=""  class="txt short" /></p></div>';
                nVal++;
            }
            //alert(htmlString);
            jQuery("#output").html(htmlString);
        });
        
	// Fade links
	jQuery('.ngg-gallery-thumbnail a').fadeTo("fast",0.80);
	 jQuery('.ngg-gallery-thumbnail a').hover(function() {
		jQuery(this).fadeTo("fast",1);
		},
		function () {
        jQuery(this).fadeTo("fast",0.80);
     });
     
});
