// per il menu' principale

var __currentMenu = null;
var __lis = null;
var __index = 0;
var __menu1 = null;
var __menu1A = null;

function setMenu()
{
	//cerco il menu
	var elem = document.getElementById("CMSMenu");
	if(elem)
	{
		//cerco tutti i link nel menu
		var elems = elem.getElementsByTagName("a");
		//cerco tutti gli UL
		__lis = elem.getElementsByTagName("li");
		if(elems && __lis)
		{
			for(var k=0; k < __lis.length; k++)
				setLis(__lis[k]);
			//cerco il link (eventualmente) attivo
			var currentLocation = new String(document.location);
			var index = 0;
			for(var i=0; i < elems.length; i++)
			{
				var myHref = elems[i].href.substring(0,elems[i].href.length - 5);
				//alert(myHref)
				if(currentLocation.indexOf(myHref) >=0)
				{
					//lascio aperto l'UL contenitore
					if(elems[i].parentNode.parentNode && elems[i].parentNode.parentNode.id != "CMSMenu")
					{
						var currUL = elems[i].parentNode.parentNode;
						__currentMenu = currUL;
						currUL.style.display = "block";
					}
				}
			}
		}
	}
	
	
	//abilito il menu lingua
	setLingua();
}

function setLingua()
{
	var $Altezza = null;
	jQuery('#Lingua').hover(function(){
					$Altezza = jQuery(".LinguaSlider").position().top;
					jQuery(this).stop().animate({ height:'80px'},300);
					jQuery(this).children('.LinguaSlider').stop().animate({ top:'0px'},300);
	}, function(){
										
					jQuery(this).children('.LinguaSlider').stop().animate({ top:'' + $Altezza+'px'},300);
					jQuery(this).stop().animate({ height:'20px'},300);
	});
}

function setLis(li)
{	
	var uls = li.getElementsByTagName("ul");
	li.onmouseover = menuOn;
	li.onmouseout = menuOff;
	if(uls && (uls.length > 0)) //sono un li di primo livello
		li.ul = uls[0];
	else
		li.ul = null;
}

function menuOn()
{
	//verifico se c'e' un menu evidente con CSS
	if(jQuery(".CMSListMenuHighlightedLI").length > 0)
	{
		__menu1 = jQuery(".CMSListMenuHighlightedLI");
		__menu1A = jQuery(".CMSListMenuLinkHighlighted");
		__menu1.removeClass("CMSListMenuHighlightedLI");
		__menu1A.removeClass("CMSListMenuLinkHighlighted");
		__menu1.addClass("CMSListMenuLI");
		__menu1A.addClass("CMSListMenuLink");
	}
	//prima verifica se c'e' il menu' attivo
	if(__currentMenu != null)
		__currentMenu.style.display = "none";
	if(this.ul != null)
		this.ul.style.display = "block";
}

function menuOff()
{
	//verifico se c'e' un menu evidente con CSS
	if(__menu1 != null)
	{
		__menu1.removeClass("CMSListMenuLI");
		__menu1A.removeClass("CMSListMenuLink");
		__menu1.addClass("CMSListMenuHighlightedLI");
		__menu1A.addClass("CMSListMenuLinkHighlighted");
	}
	if(this.ul != null)
		this.ul.style.display = "none";
	//prima verifica se c'e' il menu' attivo
	if(__currentMenu != null)
		__currentMenu.style.display = "block";
}

function showHider()
{
	var elem = document.getElementById("hider");
	if(elem)
		elem.style.display = "block";
}

// per i dettagli in popup

function ViewDetail(id)
{
	if(!$("#dettaglio"+id).hasClass("outerShadowPanelCavePunte") && $("#dettaglio"+id).parent().length > 0 && !$("#dettaglio"+id).parent().hasClass("outerShadowPanelCavePunte"))
	{
		$("#dettaglio"+id).addClass("outerShadowPanelCavePunte");
		applyOuterShadow($("#dettaglio"+id));	
		$("#dettaglio"+id).css("display","block");
	}
	$("#dettaglio"+id).parent().css("display","block");
}

function HideDetail(id)
{
	$("#dettaglio"+id).parent().css("display","none");
}

/* per le news in home in popup */

function HideNews()
{
	$("#NewsHome").parent().css("display","none");
	//document.getElementById('NewsHome').style.display = 'none';	
}

function HideNatale()
{
	$("#NataleHome").parent().css("display","none");	
}


// animazione banner

var __bannerIMG = new Array();
var __zIndex = 100;
var __maxZindex = 200;
var __currentOpacity = 0;
var __step = 2;
var __currentImage = null;
var __millis = 20;
var __currentIndex = 1;

var __pause = 5000;

function addImage(id, linkId)
{
	var elem = document.getElementById(id);
	if(elem)
	{
		elem.style.zIndex = 0;
		elem = document.getElementById(linkId);
		if(elem)
			elem.style.zIndex = 0;
	}
	__bannerIMG[__bannerIMG.length] = new Array(id,linkId);
}



function initFader()
{
	if(__bannerIMG.length > 1)
	{
		//inizia l'animazione
		setTimeout("nextImage()",__pause);
	}
}

function nextImage()
{
	var elem = null;
	if(__currentIndex >= __bannerIMG.length)
	{
		//resetto tutti gli zIndex
		for(var zi = 0; zi < __bannerIMG.length; zi++)
		{
			elem = document.getElementById(__bannerIMG[zi][0]);
			if(elem)
				elem.style.zIndex = 0;
			elem = document.getElementById(__bannerIMG[zi][1]);
			if(elem)
				elem.style.zIndex = 0;
		}
		__maxZindex = 200;
		__currentIndex = 0;
	}
		
	elem = document.getElementById(__bannerIMG[__currentIndex][0]);
	if(elem)
	{
		__currentImage = elem;
		__currentImage.style.opacity = 0;
		//__currentImage.style.filter = "alpha(opacity=100)";
		__currentImage.style.filter = "progid:DXImageTransform.Microsoft.Alpha (style=0, opacity=0);"
		var z = __maxZindex++;
		__currentImage.style.zIndex = z
		elem = document.getElementById(__bannerIMG[__currentIndex][1]);
		if(elem)
			elem.style.zIndex = z;
		__currentIndex++;
	}
	fadeIt();
}

function fadeIt()
{
	__currentOpacity += __step;
	if(__currentOpacity <= 100)
	{
		__currentImage.style.opacity = __currentOpacity/100;
		//__currentImage.style.filter = "alpha(opacity=" + __currentOpacity + ")";
		__currentImage.style.filter = "progid:DXImageTransform.Microsoft.Alpha (style=0, opacity="+__currentOpacity+");"
		setTimeout("fadeIt()",__millis);
	}
	else
	{
		__currentOpacity = 0;
		setTimeout("nextImage()",__pause);
		//fadeIt();
	}
}
