// Krollis API - Taskline

function Taskline (height, img) 
{
	this.height = height;
	if(Taskline.arguments.length > 1)
	{
		var entryimg = new Image();
		entryimg.src = img;
	}

	this.frame = document.createElement("div");
	this.frame.style.position = "absolute";
	this.frame.style.width = "100%";
	this.frame.style.height = this.height;
	this.frame.style.bottom = "0px";
	this.frame.style.zIndex = "1000";
	this.frame.style.backgroundImage = "url(bilder/taskleiste.png)";
	this.frame.style.backgroundRepeat = "repeat-x";
	this.taskmenu = document.createElement("div");
	this.taskmenu.style.width = "0px";
	this.taskmenu.style.position = "relative";
	this.taskmenu.style.margin = "0px auto";
	this.frame.appendChild(this.taskmenu);
};

Taskline.prototype.insert = function(dom) 
{
    dom.appendChild(this.frame);
};

Taskline.prototype.space = function()
{
	var space  = document.createElement("div");
	space.style.position = "relative";
	space.style.backgroundImage = "url(bilder/taskmenu-space.png)";
	space.style.backgroundRepeat ="repeat-x";
	space.style.height = "44px";
	space.style.width = "10px";
	setFloat(space,"left");
	return space;
}	

Taskline.prototype.clear = function()
{
	var clear = document.createElement("div");
	clear.style.clear = "both";
	return clear;
}

Taskline.prototype.mouseover = function(e)
{
	var obj;
	if(IsIE)
	{
		obj = e.srcElement;
	}
	else
	{
		obj = this;
	}
	var old = obj.style.backgroundPosition;
	var old2 = old.split(' ');
	obj.style.backgroundPosition = old2[0] + " -44px";
}

Taskline.prototype.mouseout = function(e)
{
	var obj;
	if(IsIE)
	{
		obj = e.srcElement;
	}
	else
	{
		obj = this;
	}
	var old = obj.style.backgroundPosition;
	var old2 = old.split(' ');
	obj.style.backgroundPosition = old2[0] + " 0px";

}

Taskline.prototype.mouseclick = function(e)
{
	var obj;
	if(IsIE)
	{
		obj = e.srcElement;
	}
	else
	{
		obj = this;
	}
	var target = obj.parentNode.getAttribute("wnd");
	var site =   obj.parentNode.getAttribute("id");
	eval(target + ".load('" + site + "');");
}

Taskline.prototype.addButton = function(code,width,left,frame)
{
	var temp = document.createElement("div");
	setFloat(temp,"left");
	temp.setAttribute("id",code);
	temp.setAttribute("wnd",frame);
	temp.appendChild(this.space());

	var entry = document.createElement("div");
	entry.style.textDecoration = "none";
	entry.style.height = "44px";
	entry.style.backgroundImage = "url(bilder/menu.png)";
	entry.style.backgroundPosition = "-" + left + "px 0px";
	entry.style.backgroundRepeat = "no-repeat";
	entry.style.width =  width + "px";
	setFloat(entry,"left");	
	AddEvent(entry,"mouseover",this.mouseover);
	AddEvent(entry,"mouseout", this.mouseout)
	AddEvent(entry,"click", this.mouseclick);
	temp.appendChild(entry);
	temp.appendChild(this.space());
	temp.appendChild(this.clear());
	temp.style.width = (width + 20) + "px";
	
	if(!this.taskmenu.hasChildNodes())
	{
		var tmp = document.createElement("div");
		tmp.style.position = "relative";
		tmp.style.backgroundImage="url(bilder/taskmenu-links.png)";
		tmp.style.backgroundRepeat = "no-repeat";
		tmp.style.width = "24px";
		tmp.style.height = "44px";
		setFloat(tmp,"left");
		this.taskmenu.appendChild(tmp);
		tmp = document.createElement("div");
		tmp.style.height = "44px";
		setFloat(tmp,"left");
		tmp.setAttribute("id","menuentry");
		tmp.appendChild(this.clear());
		this.taskmenu.appendChild(tmp);
		tmp = document.createElement("div");
		tmp.style.position = "relative";
		tmp.style.backgroundImage = "url(bilder/taskmenu-rechts.png)";
		tmp.style.backgroundRepeat = "no-repeat";
		tmp.style.width = "24px";
		tmp.style.height = "44px";
		setFloat(tmp,"left");
		this.taskmenu.appendChild(tmp);
		this.taskmenu.appendChild(this.clear());
		this.taskmenu.style.width = "48px";
	}
	document.getElementById("menuentry").insertBefore(temp,document.getElementById("menuentry").lastChild);
	this.taskmenu.style.width = ((this.taskmenu.offsetWidth + temp.offsetWidth) + "px");
};
