
function SubMenu(sectionID, subMenuDivId, mainMenuItemID)
{
	//creo le dimensioni dinamiche dei div che contengono i submenu
	//debugger;
	
	//nome degli oggetti html relativi al submenu
	var submenuID = 'menu' + sectionID;
	
	//puntatore all'istanza della clase JS
	this.instanceID = 'sm' + sectionID;
	//puntatore all'oggetto DOM (runat="server") sul main Menu
	this.mainMenuItemPtr = document.getElementById(mainMenuItemID);
	//puntatore all'oggetto DOM (runat="server") che è il menu a scomparsa
	this.subMenuDivPtr = document.getElementById(subMenuDivId);
	
	//se il menu è nascosto (l'utente non ha i permessi necessari) esco
	if (this.mainMenuItemPtr == null)
		return;
	
	//alert(sectionID + ' Started');
	
	//se è un sottomenu (e non la finestrella di Login)
	//cioè se esiste la lista dei sottomenu (_menuitems)
	//### lo centro rispetto al menuItem ####
	if (document.getElementById(submenuID + "_menuitems"))
	{
		//alert(window.document.getElementById("li_" + submenuID).offsetLeft);
		//debugger;
		//alert(sectionID + ' 1.1');
	
		var myMenuLeft = this.mainMenuItemPtr.offsetLeft;
		var myMenuWidth = this.mainMenuItemPtr.offsetWidth - 4;
		var myTotalWidth = document.getElementById("menucontainer").offsetWidth;
		var mySubmenu = document.getElementById(submenuID + "_menuitems");
		var mySubmenuWidth = 0;
		
		//alert(sectionID + ' 1.2');
	
		for(var i=0; i<mySubmenu.childNodes.length;i++)
			mySubmenuWidth = mySubmenuWidth + mySubmenu.childNodes[i].offsetWidth;
		
		//alert(sectionID + ' 1.3');
	
		window.document.getElementById(submenuID + "_sx").style.left = '0px';
		window.document.getElementById(submenuID + "_sx").style.width = myMenuLeft + 'px';
		
		//alert(sectionID + ' 2');
			
		//in base al tipo di browser setto le coordinate giusto dei resize del submenu
		var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
		
		if (rslt != null && Number(rslt[1]) >= 5.0)
		{
			window.document.getElementById(submenuID + "_centro").style.left = myMenuLeft + 'px';
			window.document.getElementById(submenuID + "_centro").style.width = myMenuWidth +  'px';
			window.document.getElementById(submenuID + "_dx").style.left =  (myMenuLeft + myMenuWidth) + 'px';
			window.document.getElementById(submenuID + "_dx").style.width =  (myTotalWidth - myMenuLeft - myMenuWidth) + 'px';
		}
		else
		{
			window.document.getElementById(submenuID + "_centro").style.left = myMenuLeft + 'px';
			window.document.getElementById(submenuID + "_centro").style.width = myMenuWidth  + 2 + 'px';
			window.document.getElementById(submenuID + "_dx").style.left =  (myMenuLeft + myMenuWidth) + 3 + 'px';
			window.document.getElementById(submenuID + "_dx").style.width =  (myTotalWidth - myMenuLeft - myMenuWidth) - 3 + 'px';
		}
		
		//alert(sectionID + ' 3');
		
		window.document.getElementById(submenuID + "_navmenu").style.width = mySubmenuWidth + 50 + 'px';
		window.document.getElementById(submenuID + "_navmenu").style.position = 'relative';
		window.document.getElementById(submenuID + "_navmenu").style.left = (myMenuLeft + myMenuWidth / 2 - mySubmenuWidth / 2 - 20) + 'px';
		//window.document.getElementById(submenuID + "_navmenu").style.margin.left = - mySubmenuWidth;
		//alert(submenuID + ": " + mySubmenuWidth);
		//alert(submenuID + "_navmenu" + "_left " + ": " + window.document.getElementById(submenuID + "_navmenu").style.left);
	
	};
	
	
	//ipotizzo che il div sia posizionato nell'HTML nel luogo nel quale deve apparire
	this.ShowPos = this.subMenuDivPtr.offsetTop;
	//offsetHeight: Mozilla lo legge = 0 in questo caso, non capisco perché, ho dovuto fare questo IF
	if (this.subMenuDivPtr.offsetHeight > 0)
		this.Height = this.subMenuDivPtr.offsetHeight;	
	else
		this.Height = parseInt(this.subMenuDivPtr.style.height);	//ciò implica che l'height sia espressamente indicato nello style (e non nella class!)
		
	this.HidePos = this.subMenuDivPtr.offsetTop - this.Height;
	
	//this.HidePos = this.subMenuDivPtr.offsetTop - this.subMenuDivPtr.style.height.replace(/px/g,'');
	
	//lo nascondo
	this.Showed = false;
	this.subMenuDivPtr.style.visibility = 'hidden';
	this.subMenuDivPtr.style.top = this.HidePos;
	
	//alert(sectionID + ' hidden');
	
	this.Scrolling = false;			//forse non serve neanche più, potrà forse tornare utile...
	
	
	
	this.Toggle = function ()
	{
		if (this.Showed)
			this.Hide(0);
		else
			this.Show(0);
	}
	
	this.Show = function(StartDelay)
	{
		this.Showed = true;
		this.GoTo(this.ShowPos, StartDelay);
	};
	
	this.Hide = function(StartDelay){
		this.Showed = false;
		this.GoTo(this.HidePos, StartDelay);
		//setTimeout('HideExt(' + this.instanceID + ')',2000);
	};

	this.GoTo = function(pos, StartDelay) {
		//if (this.Scrolling){
			clearInterval(this.ScrollTimer);
		//};
		var now = new Date();
		this.Scrolling = true;
		this.subMenuDivPtr.style.visibility = 'visible';
		this.ScrollTimer = setInterval('Scroll(' + this.instanceID + ',' + this.subMenuDivPtr.offsetTop + ',' + pos + ',' + (now.getTime() + StartDelay) + ', 500)',50);
	}
	
	
}

function Scroll(instanceID, StartPos, TargetPos, StartTime, Duration)
{
	var mySubMenu = instanceID;
	var now = new Date();

	if (now.getTime()>=StartTime) 
		if (now.getTime()-StartTime < Duration && Math.abs(TargetPos - StartPos) > 3 )
			mySubMenu.subMenuDivPtr.style.top = '' + (StartPos + (TargetPos - StartPos) * (now.getTime()-StartTime) / Duration) + 'px';
		else	//lo scroll è finito
		{	
			mySubMenu.subMenuDivPtr.style.top = '' + TargetPos + 'px';
			if (!mySubMenu.Showed) {mySubMenu.subMenuDivPtr.style.visibility = 'hidden'};
			mySubMenu.Scrolling = false;
			clearInterval(mySubMenu.ScrollTimer);
		}
}
	
function Nothing() {

}
//---------------------------------------------------------------

