window.addEventListener?window.addEventListener("load",so_setup,false):window.attachEvent("onload",so_setup);

var so_tds = new Array();
var so_fg = null;
var so_bg = null;
var so_fgt = null;
var so_bgt = null;
var so_actual_text = 0; // currently shown text
var so_actual_bg_text = 0; // currently shown text
var so_current = 0;
var so_last = null;
var so_fx = null;
var so_fxt = null;
function so_setup()
{
	var o = document.getElementById('lmf-pagination');
	so_tds = o.getElementsByTagName('td');
	so_fg = document.getElementById('lmf-imageContainerFg');
	$(so_fg).fade('hide');
	so_bg = document.getElementById('lmf-imageContainerBg');
	so_bg.style.backgroundImage = "url('" + so_imgs[0] + "')";
	so_fgt = document.getElementById('lmf-slideshowtextFg');
	$(so_fgt).fade('hide');
	so_bgt = document.getElementById('lmf-slideshowtextBg');
	so_bgt.innerHTML = so_texts[so_actual_text];
	so_fx = new Fx.Morph(so_fg, {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
	so_fxt = new Fx.Morph(so_fgt, {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
	so_last_timeout = setTimeout(so_xfade, 5000);
	so_tds[0].style.backgroundColor = '#ccc';
	for (var i=0; i<so_tds.length; i++)
		so_tds[i].set('tween', {duration: 'long'});
}
function so_dofade()
{
	// set backgrounds & z-indexes
	so_bg.style.zIndex = 1;
	so_bg.style.backgroundImage = "url('" + so_imgs[so_last] + "')";
	so_bgt.style.zIndex = 2;
	so_bgt.innerHTML = (so_text_hover_active) ? so_texts[so_actual_bg_text] : so_texts[so_last];
	so_fg.style.zIndex = 3;
	so_fg.style.backgroundImage = "url('" + so_imgs[so_current] + "')";
	$(so_fg).fade('hide');
	so_fgt.style.zIndex = 4;
	so_fgt.innerHTML = (so_text_hover_active) ? so_texts[so_actual_text] : so_texts[so_current];
	$(so_fgt).fade('hide');
	so_fx.start({'opacity': 1})
	so_fxt.start({'opacity': 1})
	if (so_last != so_current)
	{
		$(so_tds[so_last]).tween('background-color', '#fff');
		$(so_tds[so_current]).tween('background-color', '#ccc');
	}
}
function so_xfade()
{
	if (so_pause)
	{
		so_last_timeout = setTimeout(so_xfade, 500);
		return;
	}
	// find next slide
	so_last = so_current;
	so_current++;
	if (so_current >= so_imgs.length)
		so_current = 0;
	so_dofade();
	so_last_timeout = setTimeout(so_xfade, 5000);
}
var so_last_timeout = null;
var so_text_hover_active = false;
var so_pause = false;
function ToggleSlideshow(sender) 
{
	so_pause = !so_pause;
	if (so_pause) 
	{
		sender.innerHTML = sender.innerHTML.replace(/anhalten/g, 'fortsetzen').replace(/pause/g, 'play');
	}
	else 
	{
		sender.innerHTML = sender.innerHTML.replace(/fortsetzen/g, 'anhalten').replace(/play/g, 'pause');
	}
}
function so_hover(which)
{
	so_text_hover_active = true;
	so_actual_text = which - 1;
	so_last = so_current;
	so_actual_bg_text = so_last;
	so_dofade(true);
	so_actual_bg_text = which - 1;
//	so_tds[which - 1].get('tween').duration = 250;
	if (which - 1 != so_current)
		so_tds[which - 1].style.backgroundColor = '#eee';
	so_tds[which - 1].tween('background-color', '#d7d7d7');
//	so_tds[which - 1].set('tween', {duration: 'long'});
}
function so_out(which)
{
	so_actual_bg_text = which - 1;
	so_actual_text = so_current;
	so_last = so_current;
	so_dofade(true);
	so_text_hover_active = false;
	$(so_tds[which - 1]).tween('background-color', (which - 1 == so_current) ? '#ccc' : '#fff');
}
function so_click(which)
{
	clearTimeout(so_last_timeout);
	so_last = so_current;
	so_current = which - 1;
	so_dofade();
	so_last_timeout = setTimeout(so_xfade, 5000);
}
