// funzioni aggiuntive per animazioni 'toggle'
// http://www.learningjquery.com/2008/02/simple-effects-plugins
// è possibile inserire .fadeToggle('400') oppure .slideFadeToggle('400')



jQuery.fn.fadeToggle = function(speed, easing, callback) {
  return this.animate({opacity: 'toggle'}, speed, easing, callback);  
};

$(document).ready(function() {
  $('#fade').click(function() {
    $(this).next().fadeToggle('slow');
  });
  
});


jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
  return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);  
};

$(document).ready(function() {
  $('#slide-fade').click(function() {
    $(this).next().slideFadeToggle('slow', function() {
      var $this = $(this);
      if ($this.is(':visible')) {
        $this.text('Successfully opened.');
      } else {
        $this.text('Sucessfully closed.');
      }
    });
  });
  
});

jQuery.fn.blindToggle = function(speed, easing, callback) {
  var h = this.height() + parseInt(this.css('paddingTop')) + parseInt(this.css('paddingBottom'));
  return this.animate({marginTop: parseInt(this.css('marginTop')) < 0 ? 0 : -h}, speed, easing, callback);  
};

$(document).ready(function() {
  var $box = $('#box')
    .wrap('<div id="box-outer"></div>');
  $('#blind').click(function() {
    $box.blindToggle('slow');  
  });    
});

// fine 'toggle'






// jQuery Mega Menu Effects

// To apply one of those effects (replace "hover_fade" by any other effect) :
// $(function() {
//	 $("#menu").megaMenu('hover_fade');
// });


jQuery.fn.megaMenu = function(menu_effect)
{

	$(".dropcontent").css('left', 'auto').hide();
	$(".fullwidth").css('left', '-1px').hide();
	
	switch( menu_effect )
	{

	case "hover_fade":
		$('li').hover(function() {
			$(this).children().stop().fadeTo(400, 1);
			}, function () { 
			$(this).children("div").stop().fadeTo(400, 0, function() {
			  $(this).hide(); 
		  });
		});
		break;

	case "hover_fadein":
		$('li').hover(function() {
			$(this).children().stop().fadeTo(400, 1).show();
			}, function () { 
			$(this).children("div").stop().hide(); 
		});
		break;

	case "hover_slide":
		$('li').hover(function() {
			var $this = $(this);
			$this.children("div").slideDown(300);
			$this.hover(function() {
			}, function(){	
				$(this).children("div").slideUp(400);
			});
		});
		break;

	case "hover_toggle":
		$('li').hover(function() {
			$(this).children("div").toggle('fast').show();
		});
		break;

	case "click_fade":
		$('li').click(function() {
			var $this = $(this);
			$this.children().fadeIn(400).show();
			$this.hover(function() {
			}, function(){	
				$this.children("div").fadeOut(400);
			});
		});
		break;

/* ORIGINALE
	case "click_slide":
		$('li').click(function() {
			var $this = $(this);
			$this.children().slideDown(300).show();
			$this.hover(function() {
			}, function(){	
				$this.children("div").slideUp(300);
			});
		});
		break;
*/		
		
		
	// MODIFICATO  slideFadeToggle
	case "click_slide":
		$('li.ristorante a').click(function() {
			$('div.dropcontent.ristorante').slideFadeToggle(300).show();
			$('li.ristorante').hover(function() {
			}, function(){	
				$('div.dropcontent.ristorante').slideUp(300);
			});
		});
		
		$('li.press a').click(function() {
			$('div.dropcontent.press').slideFadeToggle(300).show();
			$('li.press').hover(function() {
			}, function(){	
				$('div.dropcontent.press').slideUp(300);
			});
		});
		break;
		
		
		

	case "click_toggle":
		$('li').click(function() {
			var $this = $(this);
			$this.children("div").toggle('fast').show();
			$this.hover(function() {
			}, function(){	
				$this.children("div").hide('slow');
			});
		});
		break;

	case "click_open_close":
		$('li').click(function() {
			var $this = $(this);
			$this.toggleClass('active');
			$this.siblings().removeClass('active');
			$(".dropcontent, .fullwidth").fadeOut(400, 0);
			$(this).children().fadeTo(400, 1);
		});
		break;

	case "opened_first":
		$("li:first-child > div").fadeTo(400, 1).parent().toggleClass('active');
		$("li").click(function() {
			var $this = $(this);
			$this.toggleClass('active');
			$this.siblings().removeClass('active');
			$(".dropcontent, .fullwidth").fadeOut(400, 0);
			$this.find(".dropcontent, .fullwidth").fadeTo(400, 1);
		});
		break;

	case "opened_last":
		$("li:last-child > div").fadeTo(400, 1).parent().toggleClass('active');
		$("li").click(function() {
			var $this = $(this);
			$this.toggleClass('active');
			$this.siblings().removeClass('active');
			$(".dropcontent, .fullwidth").fadeOut(400, 0);
			$this.find(".dropcontent, .fullwidth").fadeTo(400, 1);
		});
		break;

	case "opened_second":
		$("li:nth-child(2) > div").fadeTo(400, 1).parent().toggleClass('active');
		$("li").click(function() {
			var $this = $(this);
			$this.toggleClass('active');
			$this.siblings().removeClass('active');
			$(".dropcontent, .fullwidth").fadeOut(400, 0);
			$this.find(".dropcontent, .fullwidth").fadeTo(400, 1);
		});
		break;

	case "opened_third":
		$("li:nth-child(3) > div").fadeTo(400, 1).parent().toggleClass('active');
		$("li").click(function() {
			var $this = $(this);
			$this.toggleClass('active');
			$this.siblings().removeClass('active');
			$(".dropcontent, .fullwidth").fadeOut(400, 0);
			$this.find(".dropcontent, .fullwidth").fadeTo(400, 1);
		});
		break;

	case "opened_fourth":
		$("li:nth-child(4) > div").fadeTo(400, 1).parent().toggleClass('active');
		$("li").click(function() {
			var $this = $(this);
			$this.toggleClass('active');
			$this.siblings().removeClass('active');
			$(".dropcontent, .fullwidth").fadeOut(400, 0);
			$this.find(".dropcontent, .fullwidth").fadeTo(400, 1);
		});
		break;

	case "opened_fifth":
		$("li:nth-child(5) > div").fadeTo(400, 1).parent().toggleClass('active');
		$("li").click(function() {
			var $this = $(this);
			$this.toggleClass('active');
			$this.siblings().removeClass('active');
			$(".dropcontent, .fullwidth").fadeOut(400, 0);
			$this.find(".dropcontent, .fullwidth").fadeTo(400, 1);
		});
		break;

	
	}

	
}

