// JavaScript Document
function taskBar()
{
	this.targetObject = false;
	this.openObject = false;
	this.openMode = false;
	this.locked = false;
	this.o;
	this.os = 0;
	this.j = '';
	
	this.x = 0;
	this.y = 0;

	this.click = function(t, id, j, os)
	{
		if(this.locked)
			return;
			
		me = this;
		o = document.getElementById(id);
		
		if(this.openObject != o)
		{
			this.change();
		}
		else if(this.openMode)
		{
			return;
		}
		
		//this.openMode = true;
		
		this.targetObject = t;
		this.openObject = o;
		this.os = os;
		this.j = j;
		
		this.resize();
		
		this.openObject.style.visibility = 'visible';
		window.event.cancelBubble = true;
		
	}
	
	this.resize = function()
	{
		
		if(!this.openObject)
		{
			return;
		}
		
		par = this.targetObject;
		this.x = this.os;
		this.y = this.targetObject.offsetHeight;
		
		this.targetObject.className = 'taskbuttoncurrent';
		
		while(par)
		{
			this.x += parseInt(par.offsetLeft);
			this.y += parseInt(par.offsetTop);
			par = par.offsetParent;		
		}

		if(this.j == 'right')
		{
			this.openObject.style.left = '';
			this.openObject.style.right = (document.body.offsetWidth - this.x - this.targetObject.offsetWidth) + 'px';
			this.x = this.x + this.targetObject.offsetWidth - this.openObject.offsetWidth;
		}
		else
		{
			this.openObject.style.left = this.x + 'px';
		}

		this.openObject.style.top = this.y + 'px';
	}
	
	this.hover = function(t, id, j, os)
	{
		if(this.openMode && !this.closing)
		{
			this.click(t, id, j, os);	
		}
	}
	
	this.close = function()
	{
		if(window.popup)
		{
			window.popup.close();	
		}
		this.openMode = false;
		this.change();
	}
	
	this.lock = function()
	{
		this.close();
		this.locked = true;	
	}
	
	this.unlock = function()
	{
		this.locked = false;	
	}
	
	this.change = function()
	{
		if(this.openObject)
		{	
			this.targetObject.className = 'taskbutton';
			this.openObject.style.visibility = 'hidden';
		}
	}
	
}

var tb = new taskBar();

if (document.addEventListener)
	document.addEventListener('click', function(e){ window.click(e) }, true);
else
	document.attachEvent('onclick', function(e){ window.click(e) });
	
	
var controls = Array();

window.click = function(e)
{
	
	if(!window.tb.openObject || window.tb.openObject.style.visibility == 'hidden')
		return;
		
	if(e.target == '[object HTMLOptionElement]')
	{
		return;	
	}

	s = document.body.scrollTop;

	if (s == 0)
	{
		if (window.pageYOffset)
			s = window.pageYOffset;
		else
			s = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	
	if(e.clientX < window.tb.x || e.clientX > window.tb.x + window.tb.openObject.offsetWidth || e.clientY + s < window.tb.y || e.clientY + s > window.tb.y + window.tb.openObject.offsetHeight)
	{
		p = document.getElementById('popup');
		if(p && p.style.visibility == 'visible')
		{
			
			if(e.clientX < window.popup.x || e.clientX > window.popup.x + p.offsetWidth || e.clientY + s < window.popup.y || e.clientY + s > window.popup.y + p.offsetHeight)
			{
				window.tb.close();
				window.popup.close();			
			}
		}
		else
		{
			window.tb.close();
		}
	}
}
