

function changeTab (category, id)
{
	return false;
}

function Data_Rotator()
{

	//Configuration. These can be modified.
	this.data            = null;
	this.rotationDelay   = 2000; //milliseconds 
	
	//Internal vars. These should not be modified.
	this.current         = null;
	this.changeId        = Array();
	this.rotatorInterval = null;
	this.dataPosition    = null;
	this.start           = null;
	this.end             = null;
	this.rotator         = null;
	this.paused          = 0;
	
	//Registered on-action functions
	this.onPause         = null;
	this.onUnpause       = null;
	this.onRegister      = null;
	this.onChangeData    = null;
	this.onPreChangeData = null;
	this.onNext          = null;
	this.onPrevious      = null;
	
	//Oddball var
	var self             = null;
	
	//Method to save data (please send array!)
	this.registerData = function(data)
	{
		this.data    = data;
		this.start   = 0;
		this.end     = data.length - 1;
		this.current = 0;
		this.onRegister();
	}
	
	//Method to retrieve data
	this.getData = function(elementId)
	{
		return this.data[elementId];	
	}
	
	//Method to retrieve elements before a selected element
	this.getDataIdStepBackward = function(steps)
	{
		var reducer = steps % this.data.length;
		
		var stepPosition = this.current;
		
		for (var i = 0; i < reducer; ++i)
		{
			--stepPosition;
			if (stepPosition < 0)
			{
				stepPosition = this.end;
			}	
		}
		
		return stepPosition;
		
	}
	
	//Method to retrieve elements after a selected element
	this.getDataIdStepForward = function(steps)
	{
		var reducer = steps % this.data.length;
		
		var stepPosition = this.current;
		
		for (var i = 0; i < reducer; ++i)
		{
			++stepPosition;
			if (stepPosition > this.end)
			{
				stepPosition = this.start;
			}
		}
		
		return stepPosition;
	}
	
	this.getCurrentId = function()
	{
		return current;	
	}
	
	//This method actually does something
	//Oddball method that uses self (ie problem?) reference to this.
	this.rotateData = function()
	{
		var id = self.getNextId();
		self.changeData(id);
		self.onNext(id);
	}
	

	//Change data
	this.changeData = function(positionId)
	{
		//if (debug == 1) alert('changeData ->' + positionId);
		this.onPreChangeData(this.current);
		this.current = positionId;
		this.onChangeData(positionId);		
	}

	//Start data
	this.startRotator = function()
	{
		self = this;
		this.changeData(0);
		this.createInterval();
	}
	
	this.getPreviousId = function()
	{
		id = this.current - 1;
		if(id < this.start)
		{
			return this.end;
		}
		else
		{
			return id;
		}
	}
	
	this.getNextId = function()
	{
		id = this.current + 1;
		if(id > this.end)
		{
			return 0;
		}
		else
		{
			return id;
		}
	}
	
	this.resetInterval = function()
	{
		this.killInterval();
		this.createInterval();
	}
	
	this.killInterval = function()
	{
		clearInterval(this.rotator);	
	}
	
	this.createInterval = function()
	{
		//Kill interval just in case it exists;
		this.killInterval();
		this.rotator = setInterval(this.rotateData, this.rotationDelay);
	}
	
	this.changeSlide = function(positionId)
	{
		this.killInterval();
		this.changeData(positionId);
		if (this.paused == 0)
		{
			this.createInterval();
		}
	}
	
	this.previousSlide = function()
	{
		this.killInterval();
		var id = this.getPreviousId();
		this.changeData(id);
		this.onPrevious(id);
		if (this.paused == 0)
		{
			this.createInterval();
		}
	}
	
	this.nextSlide = function()
	{
		this.killInterval();
		var id = this.getNextId();
		this.changeData(id);
		this.onNext(id);
		if (this.paused == 0)
		{
			this.createInterval();
		}
	}
	
	
	/***************
	Un/pause functions
	***************/
	
	this.pause = function()
	{
		this.paused = 1;
		this.killInterval();
		this.onPause();
	}
	
	this.unpause = function()
	{
		this.paused = 0;
		this.createInterval();
		this.onUnpause();
	}
	
	this.togglePause = function()
	{
		if(this.paused == 1)
		{
			this.unpause();
		}
		else
		{
			this.pause();
		}
	}
	
	/***************
	On-action function registering.
	***************/
	
	this.resetFunctions = function()
	{
		this.onPause         = function(){};
		this.onUnpause       = function(){};
		this.onRegister      = function(){};
		this.onChangeData    = function(){};
		this.onPreChangeData = function(){};
		this.onPrevious      = function(){};
		this.onNext          = function(){};
	}
	
	/**************
	Pseudo-constructor
	**************/
	this.resetFunctions();

}

/*********
Custom onAction slideshow functions
*********/
function ssChangeTabLook (id)
{
	for (var i = 1; i <= 4; ++i)
	{
		
		var content = document.getElementById('ss_tabname_' + i); 

		if (i != slidetab)
		{   
			if (i == 1) {content.className = 'none first';}
			else {content.className = 'none';}			
		}
		else
		{
			if (i == 1) {content.className = 'selected first';}
			else {content.className = 'selected';}
		}
	}
	return false;
}


function ssPreviousSlide ()
{	
	--slidetab;
	if (slidetab == 0)
	{
		for (var i = 4; i >= 1; --i)
		{
			var elementId = slideshow.getDataIdStepBackward(4 - i);
			slideToId[i] = elementId;
			var tabElement = document.getElementById('ssshow_tab_title_' + i);
			tabElement.innerHTML = slideshow.getData(elementId)[1];
		}
		slidetab = 4;
	}
	ssChangeTabLook(slidetab);
}

function ssNextSlide ()
{
	++slidetab;
	if (slidetab == 5)
	{
		for (var i = 1; i <= 4; ++i)
		{
			var tabElement = document.getElementById('ssshow_tab_title_' + i);			
			var elementId = slideshow.getDataIdStepForward(i - 1);
			slideToId[i] = elementId;
			tabElement.innerHTML = slideshow.getData(elementId)[1];
		}
		
		slidetab = 1;
	}
	ssChangeTabLook(slidetab);
}

function ssPauseSlide ()
{
	var pauseElement = document.getElementById('pauseText');
	if (slideshow.paused == 1)
	{
		pauseElement.innerHTML = 'play';
	}
	else
	{
		pauseElement.innerHTML = 'pause';
	}
}

function ssChangeSlide (id)
{
	slidetab = id;
	slideshow.changeData(slideToId[id]);
	ssChangeTabLook(slidetab);
	slideshow.pause();
}

function ssRegister()
{
	for (var i = 1; i <= 4; ++i)
	{
		var tabElement = document.getElementById('ssshow_tab_title_' + i);
		var elementId = slideshow.getDataIdStepForward(i - 1);
		slideToId[i] = elementId;
		tabElement.innerHTML = slideshow.getData(elementId)[1];
	}
}

function ssChangeData (id)
{
	for (var i = slideshow.start; i <= slideshow.end; ++i)
	{
		if (id == i)
		{
			document.getElementById('ss_table_' + i).className = 'contentD';	
		}
		else
		{
			document.getElementById('ss_table_' + i).className = 'contentND';	
		}
	}

}