var switchList = new Array;
var switchCount=0;
var autoswitch_blocked;
var switchTime = 5000;
var switchSpeed= 100;

bodyload_list.push(setup_switches);
bodyload_list.push(autoSwitchItem);

function setup_switches()
{
	var tList = document.getElementsByTagName('a');
	var scnt=0;
	for( cnt=0; cnt<tList.length; cnt++ )
	{
		tItem = tList[cnt];
		if(tItem.className == 'switch_normal')
		{
			switchList.push(tItem);
			tItem.onclick = function(){autoswitch_blocked=true;switchItem(this,0);return false;};
			//tItem.onmouseover = function(){autoswitch_blocked=true;switchItem(this,0);return false;};
			tItem.onmouseout = function(){autoswitch_blocked=false;return false;};
		}
	}
}

function autoSwitchItem()
{
	if( ! autoswitch_blocked )
	{
		switchCount--;
		if( switchCount <0)
		{
			switchCount = switchList.length-1;
		}
		switchItem(switchList[switchCount],true);
	}
	setTimeout("autoSwitchItem()",switchTime);
}

function switchItem(obj,auto_switch)
{
	if( auto_switch && autoswitch_blocked ) // blocked autoswitch
	{
		return false;
	}
	else if (! auto_switch ) // setup manual switch
	{

	}

	// setup_switch
	relAtt=obj.getAttribute('rel');
	if( relAtt && (target=document.getElementById(relAtt) ) )
	{
		for( cnt=switchList.length; cnt;cnt--)
		{
			if( sItem = switchList[cnt-1] )
			{
				if( relAtt=sItem.getAttribute('rel'))
				{
					if(tItem=document.getElementById(relAtt) )
					{
						sItem.className='switch_normal';
						tItem.style.display='inline';
						tItem.style.position='absolute';
						tItem.style.zIndex--;
					}
				}
				if( sItem==target )
				switchCount=cnt;
			}
		}
		obj.className='switch_selected';
		target.style.display = 'inline';
		target.style.position= 'absolute';
		target.style.zIndex = switchList.length;

		crossFade(target.id,0,100);
	}
}

function crossFade(id,cur,end)
{
	cur=end-((end-cur)*0.80);

	//cur += 10;
	if( cur < (end-1) )
	{
		setTimeout('crossFade(\''+id+'\','+cur+','+end+')',60);
	}
	else cur=100;

	if(target=document.getElementById(id) )
	{
		target.style.opacity=cur/100;
		target.style.filter='alpha(opacity='+cur+')';
	}
}

