//oggetto apaDropDown
function aptDropDown(id)
{
	// proprietà
	this.id = id;
	this.disable = false;
	this.jsid = 'apa_dd_' + id;
	this.cursel = 0;
	this.clicked = false;
	this.hover = false;

	//oggetti associati
	this.ddl = document.getElementById('apa_ddl_' + id);
	this.ddr = document.getElementById('apa_ddr_' + id);
	this.ddi = document.getElementById('apa_ddi_' + id);
	this.ddd = document.getElementById('apa_ddd_' + id);

	// evento on mouse over
	this.OnMouseOver = function(right, over)
	{
		if (apa.working || this.disbled) return;
		
		if (this.clicked) {
			if (over) this.OnMouseOverDiv();
			else this.OnMouseOut();
			return;
		}
		
		if (over) {
			if (right) this.ddi.src = "img/apdd_rhover.jpg";
			else this.ddi.src = "img/apdd_lhover.jpg";
		} else this.ddi.src = "img/apdd.jpg";

	}

	// evento onclick
	this.OnClick = function(right)
	{
		if (apa.working || this.disbled) return;
		
		if (this.clicked) {
		
			this.hover = false;
			this.OnClose();
			this.OnMouseOver(right, 1);
			
		} else {
		
			var pos = new Pos(this.ddl);
			
			this.ddi.src = "img/apdd_clicked.jpg";
			
			this.ddd.style.height = "300px";
			this.ddd.style.width = "400px";
			this.ddd.style.top = pos.y + parseInt(this.ddl.height) + 2;
			this.ddd.style.left = pos.x;
			this.ddd.style.display = "block";
			
			this.clicked = true;
			this.hover = true;
			
			
		}
	}
	
	//evento mouse over
	this.OnMouseOverDiv = function()
	{
		this.hover = true;
	}

	//evento mouse out
	this.OnMouseOut = function()
	{
		if (this.clicked) {
			this.hover = false;
			window.setTimeout(this.jsid + ".OnClose()", 500);
		}
	}

	//chiusura della dropdown
	this.OnClose = function()
	{
		if (this.hover || !this.clicked) return;
		this.ddd.style.display = "none";
		this.clicked = false;
		this.OnMouseOver(0, 0);
	}

	// click sull'etichetta del treeview
	this.OnLabelClick = function(id, parent)
	{
		parent.cursel = id;
		parent.ddl.innerHTML = document.getElementById(parent.tv.jsid + 'l' + id).innerHTML;
		parent.ddd.style.display = "none";
		parent.clicked = false;
		parent.OnMouseOver(0, 0);
	}
	
	// costruttore...
	eval("this.ddl.onclick = function() { " + this.jsid + ".OnClick(0); }");
	eval("this.ddl.onmouseover = function() { " + this.jsid + ".OnMouseOver(0,1); }");
	eval("this.ddl.onmouseout = function() { " + this.jsid + ".OnMouseOver(0,0); }");
	eval("this.ddr.onclick = function() { " + this.jsid + ".OnClick(1); }");
	eval("this.ddr.onmouseover = function() { " + this.jsid + ".OnMouseOver(1,1); }");
	eval("this.ddr.onmouseout = function() { " + this.jsid + ".OnMouseOver(1,0); }");
	eval("this.ddd.onmouseover = function() { " + this.jsid + ".OnMouseOverDiv(); }");
	eval("this.ddd.onmouseout = function() { " + this.jsid + ".OnMouseOut(); }");
	//treeview
	eval("this.tv = apa_tv_" + this.id + ";");
	
	//sistema gli eventi del treeview associato
	this.tv.parent = this;
	this.tv.OnLabelClick = this.OnLabelClick;

}

