jQuery(document).ready(function($){ 

	$('body').removeClass('no_js');
	
    //scroller news
    $('.news-home ul').cycle({
        fx: "scrollDown",
        easing: "easeOutCubic",
        speed: 600,
        timeout: 5000
    });                 
    
    $('#nav li > ul.sub-menu li').each(function(){
        n = $('ul.sub-menu', this).length;
        
        if(n) $(this).addClass('sub');
    });
    
    $('#nav ul > li').hover(
        function()
        {
            $('ul.sub-menu:not(ul.sub-menu li > ul.sub-menu)', this).fadeIn(400);    
        },
    
        function()
        {
            $('ul.sub-menu:not(ul.sub-menu li > ul.sub-menu)', this).fadeOut(300);    
        }
    );               
    
	//SubMenu Testata
    $('ul.sub-menu li', this).hover(
        function()
        {
            var options;
            
            winWidth = $(document).width();
            subMenuWidth = $(this).outerWidth();
            space = $(this).offset().left + subMenuWidth * 2;
            
            if(space < winWidth) options = {left:subMenuWidth};
            else options = {left:subMenuWidth*-1};
            
            $('ul.sub-menu', this).hide().css(options).fadeIn(400);
        },
    
        function()
        {
            $('ul.sub-menu', this).fadeOut(300);
        }
    ); 
    
    
    //opacità su imamgini OnMouseOn
    $('img:not(.nofade, #slider img, img.icon, #slider-full-width img, a.thumb img)').hover(
        
        function(){ $(this).stop().animate({opacity:0.6}, 500); },
        function(){ $(this).stop().animate({opacity:1}, 500); }
    
    );      
    
	//Funzione Ingrandisci Foto
    $("a[rel^='prettyPhoto']").prettyPhoto({
        slideshow:5000, 
        autoplay_slideshow:false,
        show_title:false
    });
    
    $('a.thumb').hover(
        function()
        {
            $('<a class="zoom">zoom</a>').appendTo(this).css({dispay:'block', opacity:0}).animate({opacity:0.4}, 500);
        },
        function()
        {           
            $('.zoom').fadeOut(500, function(){$(this).remove()});
        }
    );

    $('a.socials').tipsy({fade:true, gravity:'s'});
    
    $('.toggle-content').hide();
    $('.toggle-title').click(function(){
        $(this).next().slideToggle(300);
        $(this).children('span.open-toggle').toggleClass('closed');
        $(this).attr('title', ($(this).attr('title') == 'Close') ? 'Open' : 'Close');
        return false;
    });     
    
    $('.tabs-container').tabs();                                       
    $('.tabs-container').tabs( "option", "fx", { opacity: 'toggle' } );
	
	// aggiunto 11.2011
	$("#ContactForm").validate({
	 rules: {
	   nome: "required",
	   cognome: "required",
	   struttura: "required",
	   telefono: "required",
	   testo: "required",
	   email: {
		 required: true,
		 email: true
	   }
	 },
	 messages: {
	   nome: "Questo campo &eacute; obbligatorio",
	   cognome: "Questo campo &eacute; obbligatorio",
	   struttura: "Questo campo &eacute; obbligatorio",
	   telefono: "Questo campo &eacute; obbligatorio",
	   testo: "Questo campo &eacute; obbligatorio",
	   email: {
		 required: "Inserire una mail valida",
		 email: "La mail va scritta nel formato nome@dominio.est"
	   }
	 }
	}); 
	$("#ContactForm label.error").live("click", function() {
		$(this).fadeOut(150, function() {

			// remove prompt once invisible
			$(this).remove();
		});
	});

});
