function StoryCycler()
{
	// fields
	this.headlines = new Array();
	this.images = new Array();
	this.bodies = new Array();
	this.urls = new Array();
	this.isExternals = new Array();
	
	this.index = 0;
	
	// methods
	this.addArticle = function(headline, image, body, url, isExternal)
	{
		this.headlines.push(headline);
		this.images.push(image);
		this.bodies.push(body);
		this.urls.push(url);
		this.isExternals.push(isExternal);
	}
	
	this.updateDOM = function()
	{
		// map some elements
		var headlineElem = document.getElementById("story-cycler-headline"); 
		var imageElem = document.getElementById("story-cycler-image");
		var bodyElem = document.getElementById("story-cycler-body");
		var linkElem = document.getElementById("story-cycler-link");
		
		// headline
		headlineElem.innerHTML = this.headlines[this.index];
		headlineElem.href = this.urls[this.index];
		headlineElem.rel = (this.isExternals[this.index] ? "external" : "");
		
		// image
		imageElem.src = this.images[this.index];
		
		// body
		bodyElem.innerHTML = this.bodies[this.index];
		
		// read more link
		linkElem.href = this.urls[this.index];
		linkElem.rel = (this.isExternals[this.index] ? "external" : "");
	}
	
	this.showNextArticle = function()
	{
		this.index++;
		
		if (this.index >= this.headlines.length)
		{
			this.index = 0;
		}
		
		this.updateDOM();
	}
	
	this.showPreviousArticle = function()
	{
		this.index--;
		
		if (this.index < 0)
		{
			this.index = this.headlines.length - 1;
		}
		
		this.updateDOM();
	}
}

StoryCycler.isPaused = true;
StoryCycler.cyclerTimeout = null;
StoryCycler.handle = null;
StoryCycler.delay = 8000;

StoryCycler.startAutomaticCycle = function(obj)
{
	StoryCycler.isPaused = false;
	StoryCycler.handle = obj;
	window.setTimeout("StoryCycler.setTimeout()", StoryCycler.delay);
}

StoryCycler.setTimeout = function()
{
	StoryCycler.cyclerTimeout = window.setTimeout("StoryCycler.setTimeout()", StoryCycler.delay);
	StoryCycler.handle.showNextArticle();
}

StoryCycler.stopAutomaticCycle = function()
{
	storyCycler.isPaused = true;
	window.clearTimeout(StoryCycler.cyclerTimeout);
}

StoryCycler.toggleAutomaticCycle = function(obj)
{
	if (StoryCycler.isPaused)
	{
		StoryCycler.startAutomaticCycle(obj);
	}
	else
	{
		StoryCycler.stopAutomaticCycle();
	}
}

StoryCycler.resetAutomaticCycle = function(obj)
{
	if (!StoryCycler.isPaused)
	{
		StoryCycler.stopAutomaticCycle();
		StoryCycler.startAutomaticCycle();
	}
}