var int_timeout_drop_down_div;
var obj_timeout_drop_down;

function drop_down_div_timeout() {
	if(obj_timeout_drop_down != null) {
		var obj_div_to_hide = document.getElementById("drop_down_div");
		document.body.removeChild(obj_div_to_hide);
		obj_timeout_drop_down = null;
		clearTimeout(int_timeout_drop_down_div);
	}
}

function drop_down () {
	this.bgcolor = "CCCCCC";
	this.offset_x = -5;
	this.offset_y = 5;
	this.onclick_function = "";
	
	this.tab_elements = new Array();
	
	this.add = function (str_text_element, int_id_element) {
		var tab_tmp = new Array();
		tab_tmp["text_element"] = str_text_element;
		tab_tmp["id_element"] = int_id_element;
		this.tab_elements[this.tab_elements.length] = tab_tmp;
	}

	this.show = function (e, str_html) {
		var str_code = "";
		if(obj_timeout_drop_down != null) {
			this.hide();
		}
		obj_timeout_drop_down = document.createElement("div");
		obj_timeout_drop_down.style.position = "absolute";
		//obj_timeout_drop_down.style.backgroundColor = "#" + this.bgcolor;
		obj_timeout_drop_down.id = "drop_down_div";
		
		obj_timeout_drop_down.className = "drop_down_div";
		obj_timeout_drop_down.style.border = "solid #000000 1px";
		obj_timeout_drop_down.style.backgroundColor = "#33CCFF";
		obj_timeout_drop_down.style.paddingLeft = "5px";
		obj_timeout_drop_down.style.paddingRight = "5px";
		obj_timeout_drop_down.style.fontFamily = "Arial, Helvetica, sans-serif";
		obj_timeout_drop_down.style.fontSize = "10px";
		obj_timeout_drop_down.style.width = "450px";
		
		obj_timeout_drop_down.innerHTML = str_html;

		obj_timeout_drop_down.onmouseover = function() {
			if(obj_timeout_drop_down != null) {
				clearTimeout(int_timeout_drop_down_div);
			}	
		}

		obj_timeout_drop_down.onmouseout = function() {
			if(obj_timeout_drop_down != null) {
				int_timeout_drop_down_div = setTimeout("drop_down_div_timeout()", 1000);
			}	
		}

		document.body.appendChild(obj_timeout_drop_down)
		
		//document.getElementById("drop_down_div").className = "drop_down_div";
		
		// Conseguir la position del cursor del mouse
		if(document.all)
		{
			if (event.pageX || event.pageY) 	{
				int_pos_x = event.pageX;
				int_pos_y = event.pageY;
			}
			else if (event.clientX || event.clientY) 	{
				int_pos_x = event.clientX + document.body.scrollLeft
					+ document.documentElement.scrollLeft;
				int_pos_y = event.clientY + document.body.scrollTop
					+ document.documentElement.scrollTop;
			}
		}
		else 
		{
			if (e.pageX || e.pageY) 	{
				int_pos_x = e.pageX;
				int_pos_y = e.pageY;
			}
			else if (e.clientX || e.clientY) 	{
				int_pos_x = e.clientX + document.body.scrollLeft
					+ document.documentElement.scrollLeft;
				int_pos_y = e.clientY + document.body.scrollTop
					+ document.documentElement.scrollTop;
			}
		}	
		
		var tab_pos_dim_div = this.get_pos_dim("drop_down_div");
		
		obj_timeout_drop_down.style.left = int_pos_x + this.offset_x + "px";
		obj_timeout_drop_down.style.top = (int_pos_y - tab_pos_dim_div["height"] + this.offset_y) + "px";
		//alert(tab_pos_dim_div["height"]);
		
		int_timeout_drop_down_div = setTimeout("drop_down_div_timeout()", 1000);
	}
	
	this.hide = function () {
		var obj_div_to_hide = document.getElementById("drop_down_div"); 
		document.body.removeChild(obj_div_to_hide);
		obj_timeout_drop_down = null;
		clearTimeout(int_timeout_drop_down_div);
	}
	
	this.get_pos_dim = function (id) {
		var curleft = curtop = 0;
		var res=Array();
		
		var curleft = curtop = 0;
		var res=Array();
		
		obj =document.getElementById(id);
		
		if (obj.offsetParent) {
			try {
				curleft_tmp = obj.offsetLeft;
			}
			catch(e) {
				curleft_tmp = 0;
			}
			curleft = curleft_tmp;
			try {
				curtop_tmp = obj.offsetTop;
			}
			catch(e) {
				curtop_tmp = 0;
			}
			curtop = curtop_tmp;
			valid = true;
			try {
				obj = obj.offsetParent;
			}
			catch(e) {
				valid = false;
			}
			
			while (valid) {
	
				try {
					curleft_tmp = obj.offsetLeft;
				}
				catch(e) {
					curleft_tmp = 0;
				}
				try {
					curtop_tmp = obj.offsetTop;
				}
				catch(e) {
					curtop_tmp = 0;
				}
	
	
				curleft += curleft_tmp;
				curtop += curtop_tmp;
				
				try {
					obj = obj.offsetParent;
				}
				catch(e) {
					valid = false;
				}
	
			}
		}
		
		try {
			var html_elemento = document.getElementById(id);
			curwidth = parseInt(html_elemento.offsetWidth,10);
		}
		catch(e) {
			curwidth = 0;
		}
		
		try {
			var html_elemento = document.getElementById(id);
			curheight = parseInt(html_elemento.offsetHeight,10);
		}
		catch(e) {
			curheight = 0;
		}
		
		res["left"]=curleft;
		res["top"]=curtop;
		res["width"]= parseInt(curwidth,10);
		res["height"]= parseInt(curheight,10);
		return res;
	}

}


