
_slist = null;
_slides = null;
_steps = [];
_play = false;

var _curr = 0;

var duration = 1500;
var links = [];

function initSlideShow()
{
	_slist = $('tabset');
	_slides = $('tabholder');
	
	if (_slist && _slides)
	{
		_slides.className = _slides.className.replace("loader", "");
		
		links = _slist.getElements("a");
		links.each(function(link, i) {
			var c = document.getElementById(link.href.substr(link.href.indexOf("#") + 1)); 
			if (c)
			{
				link._tab = c;
				link._tab.fx = new Fx.Style(link._tab, 'opacity', {duration: duration, wait: true,onStart: function(){_play = true;},onComplete: function(){_play = false;}});

				_steps.push(link);
				link._index = _steps.length-1;
				
				link._tab.style.visibillity = "visible";
				if (i == 0)
				{
					link.parentNode.className += " active";
					link._tab.fx.set(1);
				}
				else
				{
					link._tab.fx.set(0);
				}
				
				link.onclick = function() {
					if (!_play && _curr != this._index) {
						links.each(function(lnk) {
							lnk.className = lnk.className.replace("active", "");
						});
						this.className += " active";
						change(this._index);
					}
					return false;
				}
			}
		});
	}
}

function change(_index) {
	if (typeof(_index) != "undefined")
	{
		_next = _index;
	}
	else
	{
		_next = _curr+1;
		if (!_steps[_next])
		{
			_next = 0;
		}
	}
	_steps[_curr]._tab.fx.start(0);
	_steps[_curr].parentNode.className = _steps[_curr].parentNode.className.replace("active", "");
	
	_steps[_next]._tab.fx.start(1);
	_steps[_next].parentNode.className += " active";
	_curr = _next;
}

if (window.addEventListener)
	window.addEventListener("load", initSlideShow, false);
else if (window.attachEvent && !window.opera)
	window.attachEvent("onload", initSlideShow);
