/**
 * @author Fabien
 */

var aEffects = new Array();
aEffects["fade"] = "appear";
aEffects["slideUp"] = "slideDown";
aEffects["dropOut"] = "slideDown";
aEffects["shrink"] = "grow";

function goTeaser(teaserId, aItems, effect, actualIndex, duration)
{
	if(actualIndex < (aItems.length - 1)) {
		actualIndex++;
	}
	else {
		actualIndex = 0;
	}
	var rowTeaser = aItems[actualIndex];
	
	if($(teaserId + '_img')) {
		
		if (effect.length > 0) {
			var func = "$(teaserId + '_div')." + effect + "({ " +
							" afterFinish: function() { " + 
											"changeContent(teaserId, rowTeaser); " +
											"$(teaserId + '_div')." + aEffects[effect] +"(); " +
										" } " +
							"}); ";
			eval(func);
		}
		else {
			changeContent(teaserId, rowTeaser);
		}
		
		window.setTimeout(function() {
			goTeaser(teaserId, aItems, effect, actualIndex, duration);
		}, (duration*1000));
		
	}
}

function changeContent(teaserId, rowTeaser)
{
	$(teaserId + '_img').src = rowTeaser.logoUrl;
			
	if(rowTeaser.linkTo.length > 0) {
		var zLink = rowTeaser.linkTo;
		if (PHP_session.length > 0) {
			zLink = (rowTeaser.linkTo.indexOf('?') > 0) ? (rowTeaser.linkTo + '&session=' + PHP_session) : (rowTeaser.linkTo + '?session=' + PHP_session);
		}
		$(teaserId + '_link').href = zLink;
	}
	else {
		$(teaserId + '_link').href = '#';
	}
	
	if (rowTeaser.title) {
		if (rowTeaser.title.length > 0) {
			$(teaserId + '_img').title = rowTeaser.title;
			$(teaserId + '_img').alt = rowTeaser.title;
		}
	}
}
