// JavaScript Engine

	$(document).ready(function(){
	
	Cufon.replace("h1, #services h2", {
        hover : true
    });
	
	$("#sidebar .page_item ul").hide();
	$("#sidebar  .current_page_item ul:first").slideDown();
	$("#sidebar  .current_page_item").parents("ul, li")
	.map(function () {
		$(this).slideDown();
	});

	// home scroller
	$('#main').serialScroll({
		target:'.scroll',
		items:'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
		prev:'div.prev',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
		next:'div.next',// Selector to the 'next' button (absolute too)
		axis:'xy',// The default is 'y' scroll on both ways
		duration:200,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
		force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
		onBefore:function( e, elem, $pane, $items, pos ){
			e.preventDefault();
			if( this.blur )
				this.blur();
		},
		onAfter:function( elem ){
		}
	});
	
	// lang switcher
	$(".btn-slide").click(function(){
        $("#panel").slideToggle("fast");
        $(this).toggleClass("active"); return false;
    });

	$('#featured').loopedSlider({
				autoStart: 5000,
				restart: 100,
				slidespeed: 800
	});


$('.service').each(function () {
	    // options
	    var distance = 0;
	    var time = 250;
	    var hideDelay = 50;

	    var hideDelayTimer = null;

	    // tracker
	    var beingShown = false;
	    var shown = false;

	    var trigger = $('.bar', this);
	    var popup = $('div', this).css('opacity', 0);

	    // set the mouseover and mouseout on both element
	    $([trigger.get(0), popup.get(0)]).hover(
			function () {
	     		// stops the hide event if we move from the trigger to the popup element
	     		if (hideDelayTimer) clearTimeout(hideDelayTimer);
         		
	     		// don't trigger the animation again if we're being shown, or already visible
	     		if (beingShown || shown) {
	     		  return;
	     		} else {
	     			beingShown = true;
         			
	     			// reset position of popup box
	     			popup.css({ height: 200, display: 'block' }).animate({ opacity: 0.8, height: 200 }, time, 'swing', function() {
	     			 	// once the animation is complete, set the tracker variables
	     			  	beingShown = false;
	     			  	shown = true;
	     			});
	     			
	
					popup.click(function(){
						  window.location=$(this).find("a").attr("href"); return false;
					});
					

	     		}
	    	},
			function () {
	      		// reset the timer if we get fired again - avoids double animations
	      		if (hideDelayTimer) clearTimeout(hideDelayTimer);
          		
	      		// store the timer so that it can be cleared in the mouseover if required
	      		hideDelayTimer = setTimeout(function () {
	      		  hideDelayTimer = null;
	      		  popup.animate({
	      		    opacity: 0,
					height: 200
	      		  }, time, 'swing', function () {
	      		    // once the animate is complete, set the tracker variables
	      		    shown = false;
	      		    // hide the popup entirely after the effect (opacity alone doesn't do the job)
	      		    popup.css('display', 'none');
	      		  });
	      		}, hideDelay);
				
	    	}
	    	);
	  });

});




$(document).ready(function(){
    $("#cf_toggle").click(function () {
      $("#cf_container").toggle(700);
    });
  });



function validateWebForm() {
   if(document.getElementById('p1').checked == false) {
     alert("Se non accetti la privacy non puoi proseguire con l\'iscrizione");
     return false;
   }
     return true;
}

