var swapTime = 6000;
var events;
var countEvents;
var curEvent;
var curNum;
var noClick;


function startSwap()
{
	//Set flag
	noClick = true;
	
	//Get events
	events = $("#events").children();
	
	//Get number of events
	countEvents = events.size();
	
	//Set first event
	curEvent = events[0];
	curNum = 0;
	
	//Flash the event to simulate click
	$('#events>a>div>div:eq('+curNum+')').fadeTo('normal',.5);
	$('#events>a>div>div:eq('+curNum+')').fadeTo('normal',1);
	
	//Get event link
	var eventLink = curEvent.toString().substr(curEvent.toString().indexOf('html=')+5);
	
	//Visit ling
	window.location = '#'+eventLink+"?swap=true";
	
	//Set timeout for next event swap
	setTimeout('nextEvent();', swapTime);	
}

function nextEvent()
{
	if(noClick)
	{
		//Advance the event
		curNum++;
				
		if(curNum != countEvents)
		{
			//Current event = next event
			curEvent = events[curNum];
			
			//Flash the event to simulate click
			$('#events>a>div>div:eq('+curNum+')').fadeTo('normal',.5);
			$('#events>a>div>div:eq('+curNum+')').fadeTo('normal',1);
			
			//Get event link
			var eventLink = curEvent.toString().substr(curEvent.toString().indexOf('html=')+5);
			
			//Visit link
			window.location = '#'+eventLink+"?swap=true";
			
			//Set timeout for nextt event swap
			setTimeout('nextEvent()', swapTime);
		}
		else
		{
			//Restart
			startSwap();
		}
	}
	
}