/*
*	EmotionBanner
*	
*	a class based on the scriptaculous library
*/
function EmotionBanner(layerId)
{
	this.layer = layerId;
	this.teaserList = new Array();
	this.currentAnimationId = null;
	this.count = 0;
	this.cBegin = '<div class="teaserGallery">';
	this.c = '';
	this.cEnd = '</div>';
	this.width = 970;
	this.height = 300;
	if(EmotionBanner.instanceCount == undefined)
	{
		EmotionBanner.instanceCount = 0;
		EmotionBanner.instances = new Array();
		EmotionBanner.instances.push(this);
	}
	else
	{
		EmotionBanner.instances.push(this);
	}
	this.instanceId = EmotionBanner.instanceCount;
	EmotionBanner.instanceCount ++;
}
EmotionBanner.duration = 10000;
EmotionBanner.speed = 1;
EmotionBanner.textSpeed = 2000;
EmotionBanner.fadeIn = function(imgId)
{
	new Effect.Opacity(document.getElementById(imgId), {duration:EmotionBanner.speed, fps:33, from:0.0, to:1.0});
}
EmotionBanner.fadeOut = function(imgId)
{
	new Effect.Opacity(document.getElementById(imgId), {duration:EmotionBanner.speed, fps:33, from:1.0, to:0.0});
}
EmotionBanner.fadeTeaser = function(instanceId)
{
	var newImg = null;
	var newTxt = null;
	var oldImg = null;
	var oldTxt = null;

	var link = EmotionBanner.instances[instanceId];

	if(link.count < link.teaserList.length - 1 && link.teaserList.length > 1)
	{
		oldImg = link.teaserList[link.count].id;
		oldTxt = link.teaserList[link.count].id + "_t";
		link.count++;
		newImg = link.teaserList[link.count].id;
		newTxt = link.teaserList[link.count].id + "_t";
	}
	else
	{
		link.count = 0;
		if(link.teaserList.length > 1)
		{
			oldImg = link.teaserList[link.teaserList.length - 1].id;
			oldTxt = link.teaserList[link.teaserList.length - 1].id + "_t";
		}
		newImg = link.teaserList[0].id;
		newTxt = link.teaserList[0].id + "_t";
	}
	EmotionBanner.fadeIn(newImg);
	
	var tId = link.teaserList[link.count].id + "_t";
	setTimeout("EmotionBanner.fadeIn('" + String(tId) + "')", EmotionBanner.textSpeed);
	setTimeout("EmotionBanner.fadeOut('" + String(tId) + "')", EmotionBanner.duration - EmotionBanner.textSpeed);
	
	if(link.teaserList.length > 1)
	{
		EmotionBanner.fadeOut(oldImg);
	}
}
// prototypes
var o = EmotionBanner.prototype;
o.addBanner = function (imageUrl, text, _x, _y)
{
	this.teaserList.push({url:imageUrl, txt:text, x:_x, y:_y, id:"teaserItem" + (this.teaserList.length + 1)});
	this.c += '<div class="item">';
	this.c += '<img id="' + this.teaserList[this.teaserList.length - 1].id + '"  src="' + this.teaserList[this.teaserList.length - 1].url + '" >';
	this.c += '<div id="' + this.teaserList[this.teaserList.length - 1].id + '_t" class="text" style="left:' + this.teaserList[this.teaserList.length - 1].x + ';top:' + this.teaserList[this.teaserList.length - 1].y + ';">';

	if(navigator.appName == "Microsoft Internet Explorer" && parseFloat(navigator.appVersion) == 4)
	{
		this.c += '<img width="' + this.width + '" height="' + this.height + '" src="images/emobanner/placeholder.gif" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + this.teaserList[this.teaserList.length - 1].txt + '\', sizingMethod=\'scale\')" >';
	}
	else
	{
		this.c += '<img width="' + this.width + '" height="' + this.height + '" src="' + this.teaserList[this.teaserList.length - 1].txt + '" >';
	}
	
	this.c += '</div></div>';
}
o.run = function()
{
	if(this.teaserList.length > 0)
	{
		this.layer.innerHTML = this.cBegin + this.c + this.cEnd;
		
		if(this.teaserList.length > 1) for(var i=0; i < this.teaserList.length; i++)
		{
			setOpacity(document.getElementById(this.teaserList[i].id), 0);
			setOpacity(document.getElementById(this.teaserList[i].id + "_t"), 0);
		}
		
		EmotionBanner.fadeIn(this.teaserList[0].id);
		setTimeout("EmotionBanner.fadeIn('teaserItem1_t')", EmotionBanner.textSpeed);
		setTimeout("EmotionBanner.fadeOut('teaserItem1_t')", EmotionBanner.duration - EmotionBanner.textSpeed);
		
		this.currentAnimationId = setInterval("EmotionBanner.fadeTeaser(" + this.instanceId + ")", EmotionBanner.duration);
	}
	else
	{
		Debugger.message("no teaser added to EmotionBanner.teaserList, use addTeaser:function before running EmotionBanner", Debugger.WARNING);
	}
}
