var layers, timeout, iteration;

//Needs fixing.

var announcement = {
	layers: 3,
	timeout: 20000,
	iteration: 1,
	currentiteration: 1,
	timer: null,
	
	init: function( layers, timeout, iteration ) {
		this.layers = layers;
		this.timeout = timeout;
		this.iteration = iteration;
		return this;
	},
	
	count: function()
	{
		var t = 0;
		for(var i = 0; i < document.getElementById('announcement').childNodes.length; i++) if ( document.getElementById('announcement').childNodes.item(i).id && document.getElementById('announcement').childNodes.item(i).id.match(/announcement\d+/i) ) t++;
		return t;
	},
	
	start: function()
	{
		this.show(this.layers, this.timeout, this.iteration);
	},
	
	show: function( layers, timeout, iteration) {
		announcement.currentiterations = iteration;
		
		for(var j = 1; j <= layers; j++)
		{
			document.getElementById('announcement' + j).style.display = 'none';
			document.getElementById('announcement' + j).style.visibility = 'hidden';
		}
		
		document.getElementById('announcement' + iteration).style.display = 'block';
		document.getElementById('announcement' + iteration).style.visibility = 'visible';
		
		if( iteration != layers )
        {
		   iteration++;
		}
		else
		{
			iteration = 1;
		}
		announcement.timer = setTimeout(  function() { announcement.show(layers, timeout, iteration); }, timeout);		
		
		//this.timer = setTimeout( this.start, this.timeout, 'layers, timeout, iteration');		
	},
	
	next: function(){
		clearTimeout(this.timer);
		if( this.currentiterations != this.layers )
        {
			this.currentiterations++;
		}
		else
		{
	 		this.currentiterations = 1;
		}
		this.show(this.layers, this.timeout, this.currentiterations);
	},
	
	previous: function(){
		clearTimeout(this.timer);
		if( this.currentiterations != 1 )
        {
			this.currentiterations--;
		}
		else
		{
	 		this.currentiterations = this.layers;
		}
		this.show(this.layers, this.timeout, this.currentiterations);
	}
};