var as = [];
var _logos = [];
var curr_index = 0;

var duration = 700;
var stop_duration = 7000;

var start_o = 0;
var end_o = 1;
var _slideshowTimeout = false;

function initSlideShow()
{
	var _box = document.getElementById('visual-box');
	if(_box)
	{	

		var _as = _box.getElementsByTagName('li');
		var cnt = 0;
		var total_cnt = 0;

		for(i = 0; i < _as.length; i++)
		{
			if(_as[i].parentNode.id == "visual-box" && _as[i].className == "img" )
			{
				total_cnt++;
			}
		}
		
		for(i = 0; i < _as.length; i++)
		{
			if(_as[i].parentNode.id == "visual-box" && _as[i].className == "img")
			{
				as[cnt] = _as[i];
				as[cnt]._index = cnt;
				
				if(cnt == 0)
				{
					as[cnt].style.display = 'block';

					var ps = as[cnt].getElementsByTagName('p');
					var _p = document.getElementById('info');
						
					if(ps[0] && _p)
					{
						_p.innerHTML = ps[0].innerHTML;
					}

				}
				else
				{
					as[cnt].style.display = 'none';					
				}
				cnt++;
			}
		}

		curr_index = 0;
		
		initULTabset();
		
		_switch(true);
		
	}
}

if (window.addEventListener)
	window.addEventListener("load", initSlideShow, false);
else if (window.attachEvent)
	window.attachEvent("onload", initSlideShow);

function initULTabset()
{
	var as_cnt = as.length;
	var _tabs = document.getElementById('tabs');
	if(as_cnt > 0 && _tabs)
	{
		var _li = document.createElement("li");			
		var _a = document.createElement("a");

		_a.innerHTML = '';
		_a.href = 'javascript:;';
		_a.className = 'play';
		_a.onclick = function(){
			_switch(false,curr_index+2);
		}

		var __li = _tabs.appendChild(_li);
		var __a = __li.appendChild(_a);

		for(var i=0; i < as_cnt; i++)
		{

			var _li = document.createElement("li");			
			var _a = document.createElement("a");
			_a.innerHTML = i+1;
			_li._index = i+1;
			_a.href = 'javascript:;';
			_a.onclick = function(){
				_switch(false,this.parentNode._index);
			}
			if(i == curr_index)
			{
				_li.className += ' active';
			}
			if(i == as_cnt - 1)
			{
				_li.className += ' last';
			}
			var __li = _tabs.appendChild(_li);
			var __a = __li.appendChild(_a);
			
		}
	}
}

function setActiveLI(_index)
{
	var _tabs = document.getElementById('tabs');
	if(_tabs)
	{
		_as = _tabs.getElementsByTagName('li');
		for(var i = 0; i < _as.length; i++)
		{
			if(_as[i]._index == _index)
			{
				if(_as[i].className.indexOf('active') == -1)
				{
					_as[i].className += ' active';
				}
			}
			else
			{
				_as[i].className = _as[i].className.replace('active','');				
			}
		}
		
	}
}

function _switch(_start,_next_index)
{
	clearTimeout(_slideshowTimeout);
	var as_cnt = as.length;
	if(as_cnt > 1)
	{
		if(!_start)
		{

			if(_next_index)
			{
				var next_index = _next_index - 1;
			}
			else
			{			
				var next_index = curr_index + 1;
			}

			if(next_index >= as_cnt) next_index = 0;
		
			if(next_index != curr_index)
			{

				setActiveLI(next_index+1);

				var _opacity1 = new fx.Styles( as[curr_index], {duration: duration,
					
					onStart: function(){
						this.element.style.display = 'block';
					},
					onComplete: function(){this.element.style.display = 'none';}	
					
					});
			
				_opacity1.custom({'opacity': [end_o,start_o]});
		
				var _opacity2 = new fx.Styles( as[next_index], {duration: duration,
					
					onStart: function(){
						this.element.style.display = 'block';

						var ps = this.element.getElementsByTagName('p');
						var _p = document.getElementById('info');
						
						if(ps[0] && _p)
						{
							_p.innerHTML = ps[0].innerHTML;
						}
					},
					onComplete: function(){this.element.style.display = 'block';}		
					
					});
			
				_opacity2.set({'opacity': start_o});
				_opacity2.custom({'opacity': [start_o,end_o]});
		
				 curr_index = next_index;
			}
		}
		
		_slideshowTimeout = setTimeout('_switch(false)',duration + stop_duration);
		
	}
}