/*
*	DEBUGGING
*/
var Debugger = {};
Debugger.VERBOSE = false;
Debugger.NOTICE = "notice";
Debugger.WARNING = "notice";
Debugger.ERROR = "error";
Debugger.UNDEFINED_ERROR = "undefined error";
Debugger.message = function(messageString, messageType)
{
	if(messageType == undefined) var messageType = Debugger.UNDEFINED_ERROR;
	if(Debugger.VERBOSE) alert("\"" + messageType + "\": " + messageString);
}

/*
*	swaps image 
*	rollOver effect
*

*/
function swapImage(id, file)
{
	if(document.getElementById(id)) document.getElementById(id).src = file;
	else Debugger.message("swapImage: node " + id + " does not exist", Debugger.NOTICE);
}

function setVideoInfoDisplay(buttonId, infoId)
{
	if(document.getElementById(buttonId) && document.getElementById(infoId))
	{
		if(document.getElementById(infoId).style.display == "block")
		{
			document.getElementById(buttonId).src = "images/buttons/v_info_plus.jpg";
			showLayer(infoId, false);
		}
		else
		{
			document.getElementById(buttonId).src = "images/buttons/v_info_minus.jpg";
			showLayer(infoId, true);		
		}
	}
	else
	{
		Debugger.message("layer not available", Debugger.WARNING);
	}
}
/*
*	layer
*/
function showLayer(id, show)
{
	if(document.getElementById(id))
		if(show)
		{
			document.getElementById(id).style.display = "block";
		}
		else
		{
			document.getElementById(id).style.display = "none";
		}
}
/*
*	image opacity
*/
function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Moz andfox
  obj.style.MozOpacity = opacity/100;
  
  // newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

var JBroadcaster = {};
JBroadcaster.broadcastList = new Array();
JBroadcaster.addListener = function (functionName, objectName)
{
	JBroadcaster.broadcastList.push({func:functionName, obj:objectName});
}
JBroadcaster.removeListener = function (functionName, objectName)
{
	for(var i = 0; i < JBroadcaster.broadcastList.length; i++)
	{
		var cItem = JBroadcaster.broadcastList[i];
		if(cItem.func == functionName && cItem.obj == objectName) JBroadcaster.broadcastList.splice(i, 1);
	}
}
JBroadcaster.broadcastMessage = function(functionName)
{
	for(var i = 0; i < JBroadcaster.broadcastList.length; i++)
	{
		var cItem = JBroadcaster.broadcastList[i];
		if(cItem.func == functionName) cItem.obj[functionName]();
	}
}
/*
*	Emo-Banner
*/
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 = 479;
	this.height = 250;
	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);
	}
}

window.onload = function()
{
	JBroadcaster.broadcastMessage("siteLoaded");
}

function clearTextField(id)
{
	if(document.getElementById(id)) document.getElementById(id).value = "";
}
function checkOnTextInput(id, defaultText)
{
	if(document.getElementById(id))
	{
		if(document.getElementById(id).value !== defaultText && document.getElementById(id).value !== "") return true;
		else false;
	}
}
