


function Slider(direction,hpos)
{
	this.name='slider';
	this.direction=direction;
	this.horiz=(this.direction=='right' || this.direction=='left');
	this.offset=hpos;
	
	this.base=document.createElement('div');
	this.base.style.position=("attachEvent" in document) ? 'absolute' : 'fixed';	//'absolute' for IE

	if("attachEvent" in document) {	//only IE
		var _this=this;
		if("attachEvent" in window) window.attachEvent('onresize',function() { _this.updatePosition(); });
		else if("addEventListener" in window) window.addEventListener('resize',function() { _this.updatePosition(); },false);

		if("attachEvent" in window) window.attachEvent('onscroll',function() { _this.updatePosition(); });
		else if("addEventListener" in window) window.addEventListener('scroll',function() { _this.updatePosition(); },false);
		}

	this.base.style[direction]='0px';
	if(this.horiz)	this.base.style.top=hpos+'px';
	else		this.base.style.left=hpos+'px';
	this.base.style.display='none';

	return this;
}


Slider.prototype.isOn=function()
{
	return(this.base.style.display!='none');

}


Slider.prototype.animation=function()
{
	if(!this.moving) return;

	var size=this.horiz ? this.base.offsetWidth : this.base.offsetHeight;

	var pos=(this.state - size).toFixed();
	this.base.style[this.direction]=pos+'px';
	this.base[this.direction]=pos;

	this.base.style.display='block';

	//finish
	if((this.moving>0 && this.state >= this.limit) || (this.moving<0 && this.state < this.limit)) {
		if(this.moving<0) this.base.style.display='none';	//hide if 'off'
		this.moving=0;
		return;
		}


	this.state+=this.moving;
	var speed=(size-this.state)/4;
	if(speed<1) speed=1;
	this.moving= (this.moving>0) ? speed : -speed;

	var keep_this=this;
	this.timer=setTimeout( function(){ keep_this.animation(); },10);
}




Slider.prototype.on=function()
{
	this.moving=+1;
	this.state=0;

	//move somewhere off screen and appear to get the right dimensions
	this.base.style[this.direction]='-1000px';
	this.base.style.display='';

	this.limit=(this.horiz) ? this.base.offsetWidth : this.base.offsetHeight;

	this.updatePosition(true);
	this.animation();
}



Slider.prototype.off=function()
{
	this.moving=-1;
	this.state=(this.horiz) ? this.base.offsetWidth : this.base.offsetHeight;
	this.limit=0;

	this.animation();
}



Slider.prototype.updatePosition=function(force)
{
	if(!this.isOn() && !force) return;

	var page_offset=0;
	if("attachEvent" in document) {	//only IE
		page_offset=self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
		}

	if(this.horiz)	this.base.style.top=(this.offset+page_offset)+'px';
	else		this.base.style.left=this.offset+'px';
}
