var Stepper = function()
{
	this.ms          = 50;
	this.intv        = null;
	this.speed       = .8;
	this.element     = null;
	this.pts         = [];
	this.idx         = 0;
	this.nav_id      = null;
}
Stepper.prototype.init = function(slideID, paneClass) 
{
	this.element   = $(slideID);
	window['stepper_'+this.element.id] = this; // global reference to this object 
	var panes      = document.getElementById(slideID).getElementsByTagName('div');
	var totalWidth = 0;
	for(i=0;i<panes.length;i++)
	{
		if(panes[i].className==paneClass)
		{
			this.pts.push(-(totalWidth));
			var d = Element.getDimensions(panes[i]);
			totalWidth += d.width;
			Element.setStyle(panes[i],{'width':d.width+'px','height':d.height+'px'});
		}
	}
	Element.setStyle(this.element,{'position':'absolute','display':'block','top':0,'left':0,'width':(totalWidth+10)+'px'});
	this.renderLinks();
}
Stepper.prototype.back = function()  
{
	this.step(this.idx-1);
}
Stepper.prototype.next = function() 
{
	this.step(this.idx+1);
}
Stepper.prototype.step = function(n) 
{
	if(n<0){ n=(this.pts.length-1); }
	if(n>=this.pts.length){ n=0; }
	if(this.intv==null) 
	{
		this.scroll_hide();
		this.idx = n;
		this.intv = window.setInterval("window['stepper_"+this.element.id+"'].move()",this.ms);
	}
	return;
}
Stepper.prototype.move = function() 
{
	var start = parseInt(this.element.style.left);
	var end   = this.pts[this.idx];
	var dist  = Math.floor((Math.abs(end-start)/2)*this.speed);
	dist = (dist<1)? 1 : dist ;
	if(start==end)
	{
		window.clearInterval(this.intv);
		this.intv = null;
		this.renderLinks();
		this.scroll_auto();
		return;
	}
	else if(start>end) // move left
	{
		start -= dist;
		start = (start<end)? end : start ;
	}
	else // move left
	{
		start += dist;
		start = (start > end)? end : start ;
	}
	Element.setStyle(this.element,{'left':start+'px'});
}
Stepper.prototype.renderLinks = function() 
{
	if($(this.nav_id)!=undefined)
	{
		var str='';
		for(var i=0;i<this.pts.length;i++)
		{
			//var lnk = "<a href=\"javascript:;\" onclick=\"window['stepper_"+this.element.id+"'].step("+i+")\">"+(i+1)+"</a>";
			var lnk = "<a href=\"javascript:;\" onclick=\"window['stepper_"+this.element.id+"'].step("+i+")\">&bull;</a>";
			if(i==this.idx)
			{
				lnk = "<strong>"+lnk+"</strong>";
			}
			str += lnk+" \n";
		}
		$(this.nav_id).innerHTML = str;
	}
}

// scab on functions for FireFox rendering issues with scroll bars.
// hide all scroll bars 
Stepper.prototype.scroll_hide = function() 
{
	var panes = this.element.getElementsByTagName('div');
	for(i=0;i<panes.length;i++)
	{
		if(panes[i].className=='copy')
		{
			Element.setStyle(panes[i],{'overflow':'hidden'});
		}
	}
}
// show scroll bar for selected index
Stepper.prototype.scroll_auto = function() 
{
	var x=0;
	var panes = this.element.getElementsByTagName('div');
	for(i=0;i<panes.length;i++)
	{
		if(panes[i].className=='copy')
		{
			if(x==this.idx)
			{
				Element.setStyle(panes[i],{'overflow':'auto'});
				break;
			}
			x++;
		}
	}
}