$(document).ready(function() {
  // mainMenuAutomatic();
  widgetTitleClick();
  fancyBoxActivation();
});

/**
 *
 * Click su testata H3 widget
 *
 */
function widgetTitleClick()
{
	$("h3.widget-title").css("cursor","pointer");
	$("h3.widget-title").click(function ()
	{
      $(this).next().slideToggle();
    });

} 
 
/**
 *
 * Implementazione Lightbox Fancy Box
 *
 */
function fancyBoxActivation()
{
	$(".ngg-gallery-thumbnail a").fancybox({
		'overlayShow'	: true,
		'transitionIn'	: 'fade',
		'transitionOut'	: 'fade',
		'cyclic' 		: true,
		'overlayColor'	: '#000',
		'overlayOpacity': 0.5
	});
	
	$("a img.size-full").parent().fancybox({
		'overlayShow'	: true,
		'transitionIn'	: 'fade',
		'transitionOut'	: 'fade',
		'cyclic' 		: true,
		'overlayColor'	: '#000',
		'overlayOpacity': 0.5
	});
	
	$(".ngg-singlepic").parent().fancybox({
		'overlayShow'	: true,
		'transitionIn'	: 'fade',
		'transitionOut'	: 'fade',
		'cyclic' 		: true,
		'overlayColor'	: '#000',
		'overlayOpacity': 0.5
	});
}


/**
 *
 * Gestione dell'automazione del movimento del menu
 *
 */
function mainMenuAutomatic()
{
	$('#mainMenu .first_level li').each(function(index)
	{
		$(this).mouseover(function()
		{
  			// hideAllMenuSubLevels();
  			// $(this).find(".children").show();
  			$(this).siblings().find(".children").fadeOut(200);
  			$(this).find(".children").fadeIn(200);
		});
	});
	
	$('#mainMenu').mouseleave(function()
	{
		if( $(this).find(".current_page_parent").length > 0 ) // Il secondo livello  selezionato
		{
			// alert("MOUSE LEAVE: 1");
			// if( $(this).find(".current_page_parent").find(".children").is(":hidden") )
			// {
				$(this).find(".current_page_parent").find(".children").fadeIn(200);
				$(this).find(".current_page_parent").siblings().find(".children").fadeOut(200);
			// }
		}else // Il secondo livello non  selezionato
		{
			// alert("MOUSE LEAVE: 2");
			// if( $(this).find(".current_page_item").find(".children").is(":hidden") )
			// {
				$(this).find(".current_page_item").find(".children").fadeIn(200);
				$(this).find(".current_page_item").siblings().find(".children").fadeOut(200);
			// }
		}
	});
}
