// Window ENGINE
var wnd_count = 0;

// Constructor
function Select() {
	// Eigenschaften:
	this.title = "new select";
	this.width = 100;
	this.height = 25;
	var datum = new Date();
	this.id = "select_"+Date.UTC(datum.getFullYear(),datum.getMonth(),datum.getDate(),datum.getHours(),datum.getMinutes(),datum.getSeconds());
	this.cid = this.id+"_content";
	this.onLoad = null;
	this.onError = function(msg) {
		alert(msg);
	}
	
	var _this = this;
	
	this.timer = null;
	this.content_visible = false;
	
	this.showContent = function() {
	clearTimeout(_this.timer);
	_this.timer = null
	if(_this.content_visible == false) {
	$(_this.cid).style.left = absLeft($(_this.id)) + "px"
	$(_this.cid).style.top = absTop($(_this.id)) + "px" //+ _this.height + "px"	
	$(_this.cid).style.display = "block";
	$(_this.cid).style.visibility = "hidden";	
	changeOpac(0,_this.cid);
	$(_this.cid).style.visibility = "visible";
	opacity(_this.cid,0,100,500);
	_this.content_visible = true;
	}
	}

	this.initHideContent = function() {
	_this.timer = setTimeout(function(){ _this.hideSelectContent(); },250);
	}
					
	this.hideSelectContent = function() {
		_this.content_visible = false
		$(_this.cid).style.visibility = "hidden";
		$(_this.cid).style.display = "none";
	}
	
	this.addOption = function(name, setclick, active) {
	var list = document.createElement("li");
	var option = document.createElement("a");
	option.style.padding = "2px";
	option.style.display = "block";
	option.style.width = (_this.width-4) + "px";
	if(active == true) {
	option.className = "navElement_active";
	} else {
	option.className = "navElement";
	}
	option.appendChild(document.createTextNode(name));
	option.href=setclick;
	list.appendChild(option);
	
	$(_this.cid).style.position="absolute";
	$(_this.cid).style.zIndex=1;
	
	$(_this.cid).firstChild.appendChild(list);
	}
}

// New methods for constructor

Select.prototype.create = function() {
	var top_offset = 0;
	var left_offset = 0;
	
	wnd_count++;
	
	var new_select = document.createElement("a");
	new_select.id = this.id;
	new_select.href = "javascript:void null;";
	new_select.style.zIndex = 0;
	new_select.style.width = this.width + "px";
	new_select.style.height = this.height + "px";	
	new_select.style.border = "1px solid gray";
//	new_select.style.backgroundColor = "silver";
	new_select.style.color = "#FFF";
	new_select.style.display = "block";
	new_select.appendChild(document.createTextNode(this.title));
	addEvent(new_select,"mouseover",this.showContent,false);
	addEvent(new_select,"mouseout",this.initHideContent,false);
	
	var content = document.createElement("div");
	content.style.position = "absolute"
	content.style.width = (this.width)+"px";
	content.style.height = "auto";
	content.style.backgroundColor = "silver";
	content.style.color = "#FFF";
	content.style.border = "1px solid gray";
	content.id = this.cid
	addEvent(content,"mouseover",this.showContent,false);
	addEvent(content,"mouseout",this.initHideContent,false);
		
	content.style.visibility = "hidden";
	content.style.display = "none";
	
	document.body.appendChild(new_select);
	var list = document.createElement("ul");
	list.style.padding = "0";
	list.style.margin = "0";
	list.style.listStyleType = "none";
	content.appendChild(list);
	document.body.appendChild(content);
	
}


Select.prototype.createFromId = function() {
	var top_offset = 0;
	var left_offset = 0;
	
	wnd_count++;
	
	var new_select = document.getElementById(this.id);
	if(this.alwaysVisible != true) 	addEvent(new_select,"mouseover",this.showContent,false);
	if(this.alwaysVisible != true) addEvent(new_select,"mouseout",this.initHideContent,false);
	
	var content = document.createElement("div");
	content.style.position = "absolute"
	content.style.paddingTop = "20px";
	content.style.width = (this.width)+"px";
	content.style.height = "auto";
//	content.style.backgroundColor = "#FFF";
	content.style.color = "#000";
	content.style.borderLeft = "1px solid silver";
	content.id = this.cid
	if(this.alwaysVisible != true) 	addEvent(content,"mouseover",this.showContent,false);
	if(this.alwaysVisible != true) 	addEvent(content,"mouseout",this.initHideContent,false);
		
	if(this.alwaysVisible != true) 	content.style.visibility = "hidden";
	if(this.alwaysVisible != true) 	content.style.display = "none";
	
//	document.body.appendChild(new_select);
	var list = document.createElement("ul");
	list.style.padding = "0";
	list.style.margin = "0";
	list.style.listStyleType = "none";
	content.appendChild(list);
	document.body.appendChild(content);
	
	if(this.alwaysVisible == true) this.showContent()	
}