// 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'


// ************************************************
// fix bug per IE7 - questo script serve a visualizzare correttamente il dropcontent su IE7 
// http://www.vancelucas.com/blog/fixing-ie7-z-index-issues-with-jquery/
$(function() {
	var zIndexNumber = 1000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 1;
	});
});

// ************************************************

// jQuery Mega Menu Effects

// To apply one of those effects (replace "hover_fade" by any other effect) :
// $(function() {
//	 $("#menu_top").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.dropcontent").slideDown(200);
			$this.hover(function() {
			}, function(){	
				$(this).children("div.dropcontent").slideUp(200);
			});
		});
		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;



/*	case "click_fade":
		$('.megamenu li').click(function() {
			var $this = $(this);
			$('.megamenu ul li div.dropcontent').slideFadeToggle(200).show();
			$('.megamenu li ').hover(function() {
			}, function(){	
				$('.megamenu ul li div.dropcontent').delay(50).fadeOut(150);
			});
		});
		break;*/


	case "apri_drop":
		$("li.lingua > 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 "click_slide":
		$('li').click(function() {
			var $this = $(this);
			$this.children().slideDown('fast').show();
			$this.hover(function() {
			}, function(){	
				$this.children("div").slideUp('slow');
			});
		});
		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;

	
	}

	
}

