﻿// Costruttore
function contentsTreeMenu(id)
{
	var table,tbody,row,cells,div;
	var k;
	this.Items=[];
	table=document.getElementById(id);
	tbody=this._getFirstChild(table,"tbody")||table;
	row=this._getFirstChild(tbody,"tr");
	cells=this._getAllChild(row,"td");
	for(k=0;k<cells.length;k++)
	{
		if(div=this._getFirstChild(cells[k],"div"))
			new contentsTreeMenuItem(this, cells[k], div);
	}
	contentsTreeMenu.Menus[this.Index=contentsTreeMenu.Menus.length]=this;
}
// Proprietà statiche pubbliche
contentsTreeMenu.Menus=[];
// Metodi statici pubblici
contentsTreeMenu.Start=function(id)
{
	try
	{
		new contentsTreeMenu(id);
	}
	catch(e)
	{
		setTimeout("flashnewsscrollerStarter(\""+id+"\")",30);
	}
}
contentsTreeMenu.HideAll=function()
{
	var k;
	for(k=0;k<contentsTreeMenu.Menus.length;k++)
		contentsTreeMenu.Menus[k].HideItems();
};
// Prorpietà e metodi
contentsTreeMenu.prototype=
{
	_getAllChild:function(parent,tagName)
	{
		var k,c=parent.childNodes,R=[];
		tagName=tagName.toLowerCase();
		for(k=0;k<c.length;k++)
			if(c[k].tagName&&(c[k].tagName.toLowerCase()==tagName))
				R.push(c[k]);
		return R;
	},
	_getFirstChild:function(parent,tagName)
	{
		var L=this._getAllChild(parent,tagName);
		return L.length?L[0]:null;
	},
	HideItems:function()
	{
		var k;
		for(k=0; k<this.Items.length; k++)
			this.Items[k].Hide();
	}
}

function contentsTreeMenuItem(menu, cell, div)
{
	var c,k;
	this.Menu=menu;
	this.Cell=cell;
	this.Div=div;
	this.Div.Item=this.Cell.Item=this;
	this.Cell.onmouseover=function()
	{
		this.Item.Show();
	};
	this.Div.onmouseover=function(e)
	{
		this.Item.PassedOver=true;
	}
	this.Div.onmouseout=function(e)
	{
		this.Item.MouseOut(e||event);
	}
	c=this.Div.childNodes;
	for(k=0;k<c.length;k++)
	{
		c[k].onmouseout=function(e)
		{
			var e=e||event;
			e.cancelBubble=true;
			if(e.stopPropagation)e.stopPropagation();
			e.returnValue=false;
			return false;
		};
	}
	this.Visible=false;
	this.Menu.Items.push(this);
}
contentsTreeMenuItem.prototype=
{
	Hide:function()
	{
		if(!this.Visible)return;
		this.Div.style.display="none";
		this.Visible=false;
	},
	Show:function()
	{
		if(this.Visible)return;
		contentsTreeMenu.HideAll();
		this.Div.style.marginTop=parseInt(this.Cell.offsetHeight)+"px";
		this.PassedOver=false;
		this.Div.style.display="block";
		this.Visible=true;
	},
	MouseOut:function(e)
	{
		if(!this.PassedOver)return;
		this.Hide();
	}
};
