function TTTimer()
{
	this._callback = null;
	this._timer = null;
	this._delay = null;
}

TTTimer.prototype.setCallback = function(cb)
{
	this._callback = cb;
}

TTTimer.prototype.setDelay = function(delay)
{
	this._delay = delay;
}

TTTimer.prototype.start = function(context, cb, delay)
{
	if(cb == undefined || cb === null)
		cb = this._callback;
	if(delay == undefined || delay === null)
		delay = this._delay;
	
	if(cb === null || delay === null)
		return false;
	
	this.clear();
		
	var obj = this;
	this._timer = setTimeout(function()
	{
		obj._timer = null;
		cb.call(context, obj);
	}, delay);
}

TTTimer.prototype.clear = function()
{
	if(this._timer !== null)
	{
		clearTimeout(this._timer);
		this._timer = null;
	}
}


var TTLeftMenu = {
	_subnaviPrefix : 'subnavi',
	_delay : 200,
	
	prepareItem : function(id)
	{
		var elem = document.getElementById(this._subnaviPrefix + id);
		
		if(elem._timer == undefined)
			elem._timer = new TTTimer();
		if(elem._opened == undefined)
			elem._opened = false;
	},
	
	onItemOver : function(id)
	{
		var elem = document.getElementById(this._subnaviPrefix + id);
		
		this.prepareItem(id);
		
		elem._timer.start(this, function(timer)
		{
			this.show(id);
		}, this._delay);
	},
	
	onItemOut : function(id)
	{
		var elem = document.getElementById(this._subnaviPrefix + id);
		
		this.prepareItem(id);
		
		elem._timer.start(this, function(timer)
		{
			this.hide(id);
		}, this._delay);
	},
	
	show : function(id)
	{
		var elem = document.getElementById(this._subnaviPrefix + id);
		
		if(elem._opened == true)
			return;
		
		Effect.BlindDown(elem,
		{
			duration : 0.2,
			afterFinish : function()
			{
				elem._opened = true;
			},
			queue : 'end'
		});
	},
	
	hide : function(id)
	{
		var elem = document.getElementById(this._subnaviPrefix + id);
		
		if(elem._opened == false)
			return;
		
		Effect.BlindUp(elem,
		{
			duration : 0.2,
			afterFinish : function()
			{
				elem._opened = false;
			},
			queue : 'end'
		});
	}
};

var TTTopBanner = {
	_popupId : 'topbannerpopup',
	_timer : new TTTimer(),
	_visible : false,
	_clicked : false,
	
	onClick : function(bannername, docid)
	{
		if(!this._visible)
		{
			this.show(bannername, docid);
		}
	},
	
	onOver : function()
	{
		this._timer.clear();
		if(!this._visible)
		{
			this.show();
		}
	},
	
	onOut : function()
	{
		if(this._visible)
		{
			this._timer.start(this, function(timer)
			{
				this.hide();
			}, 500);
		}
	},
	
	show : function(bannername, docid)
	{
		var elem = document.getElementById(this._popupId);
		if(!elem)
			return;
		elem.style.display = "block";
		this._visible = true;
		
		if(this._clicked === false)
		{
			var ajax = new meAjax();
			ajax.requestPost('/webEdition/ajaxbanner.php', {}, {'name' : bannername, 'did' : docid}, true);
			
			this._clicked = true;
		}
		
		if(meFlvUtils)
		{
			setTimeout(function()
			{
				meFlvUtils.sendEvent('topbanneradflash', 'playpause');
			}, 500);
		}
	},
	
	hide : function()
	{
		if(meFlvUtils)
			meFlvUtils.sendEvent('topbanneradflash', 'stop');
		
		var elem = document.getElementById(this._popupId);
		if(!elem)
			return;
		elem.style.display = "none";
		this._visible = false;
	}
};