// JavaScript Engine

	jQuery(document).ready(function(){
	
	// Main Navigation
    jQuery("ul.sf-menu").supersubs({ 
    minWidth        : 12,
    maxWidth        : 15,
    extraWidth      : 1
    }).superfish();

	// jQuery(".tour").fancybox({
	//     width : 800,
	//     height : 600,
	//     beforeLoad : function() {
	//         var href = this.href,
	//             width = this.width,
	//             height = this.height;
	// 
	//         // Check if quictime movie and change content
	//         if (href.indexOf('.mov') != -1) {
	//             this.content    = '<object width="' + width + '" height="'+ height + '" pluginspage="http://www.apple.com/quicktime/download" data="'+ href + '" type="video/quicktime"><param name="autoplay" value="true"><param name="scale" value="tofit"><param name="controller" value="true"><param name="enablejavascript" value="true"><param name="src" value="' + href + '"><param name="loop" value="false"></object>';
	//             this.type       = 'html';
	//         }
	//     }
	// });

	
	
	jQuery('#slider').slides({
	preload: true,
	preloadImage: '/wp-content/themes/hcristallo/images/loading.gif',
			container: "slides",
			effect: "fade",
			pagination: false,
			generatePagination: false,
			play: 5000,
				pause: 500,
				fadeSpeed: 550,
				hoverPause: true
		});
		
	jQuery('.photo-slider').slides({
			preload: true,
			preloadImage: '/wp-content/themes/hcristallo/images/loading.gif',
			play: 5000,
			effect: 'slide, fade',
			crossfade: true,
			slideSpeed: 350,
			fadeSpeed: 500,
			generateNextPrev: false,
			generatePagination: false
	});
	
	// Offers ticker
	jQuery('#ticker').innerfade({
			speed: 2000,
			timeout: 5000,
			type: 'sequence',
			containerheight: '80px'
	});
	
	// 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);
            }
        });
	
	// Datepicker
	jQuery('#checkin,#checkout,#dal,#al').focus(function(){jQuery(this).val('');})
	.datepicker({minDate: new Date(2012, 1 - 1, 1), maxDate: new Date(2012, 12 - 1, 31), showOn: "both", dateFormat: "dd/mm/yy", showAnim: "fadeIn", speed: "fast", buttonImage: "http://www.hcristallo.it/wp-content/themes/hcristallo/images/ico_cal.gif", buttonImageOnly: true, hideIfNoPrevNext: true, changeMonth: false, changeYear: 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);  
    });
    
    jQuery(".featured img").insetBorder({
  		borderColor: "rgba(170,209,223,.5)"
	});
	
	// 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);
        });
	
/*
	// StickySide
    jQuery("#sidenav").stickySidebar({
            timer: 400, easing: "linear", constrain: true
      });
*/

jQuery(".fancybox").fancybox({
		openEffect	: 'none',
		closeEffect	: 'none'
	});

jQuery("ul (li.menu-item):has(ul.sub-menu)").hover(function () {
  jQuery(this).children("a").removeAttr('href');
  jQuery(this).children("a").css('cursor', 'default');
  jQuery(this).children("a").click(function () {
    return false;
  });
});

jQuery(function() {
	var ticker = function() {
		setTimeout(function(){
			jQuery('#roller li:first').animate( {marginTop: '-45px'}, 800, function() {
				jQuery(this).detach().appendTo('ul#roller').removeAttr('style');	
			});
			ticker();
		}, 4000);
	};
	ticker();
});

jQuery("a[rel=external]").attr('target', '_blank');

function addPortfolioHover(){
    
        $('#archives li').hover(function(){
           
           $(this).find(".archive-hover").stop(true, true).fadeIn(200)
                       .find(".circle").stop(true, true).animate({opacity:'1'},400,'easeOutBack')
                           .find("span").stop(true, true).animate({opacity:'1', paddingTop:'16px'},400,'easeOutBack');
           
           
        },
        function(){
            
            $(this).find(".archive-hover").stop(true, true).fadeOut(200)
                       .find(".circle").stop(true, true).animate({opacity:'0'},400,'easeOutBack')
                           .find("span").stop(true, true).animate({opacity:'0', paddingTop:'5px'},400,'easeOutBack');
            
       });
}

addPortfolioHover();
     
});
