oSliders=new Object();
API.sliders=oSliders;

oSliders.length=0;
oSliders.New=function(sliderElement,sliderAttribute,sliderTrans,sliderFreq,basePosition,increment,equation,hideEquation) {
	API.sliders[this.length]=new Slider(this.length,sliderElement,sliderAttribute,sliderTrans,sliderFreq,basePosition,increment,equation,hideEquation);
	this.length++;
	return API.sliders[this.length-1];

}
oSliders.Get=function(id) {
	for(i=0;i<this.length;i++) {
		if(API.sliders[i].id==id) {
			return API.sliders[i];
		}
	}
	return false;
}

function Slider(id,sliderElement,sliderAttribute,sliderTrans,sliderFreq,basePosition,increment,equation,hideEquation) {
	this.element=sliderElement;
	this.id=id;
	this.element.slider=this;
	this.interval=null;
	this.step=0;
	this.basePosition=basePosition;
	this.increment=increment;
	this.equation=equation;
	if(hideEquation)
		this.hideEquation=hideEquation;
	else
		this.hideEquation=equation;
	this.position=0;

	this.attribute=sliderAttribute;

	if(sliderTrans)
		this.trans=sliderTrans*1000;
	else
		this.trans=500;

	if(sliderFreq)
		this.freq=sliderFreq;
	else
		this.freq=50;

	this.setPosition=function(slideDirection) {
		if(this.step>100)
			this.step=100;
		if(this.step<0)
			this.step=0;
		this.getPosition(slideDirection);
		switch(this.attribute) {
			case 'top':
				this.element.style.top=(this.basePosition+this.position)+'px';
				break;
			case 'bottom':
				this.element.style.bottom=(this.basePosition+this.position)+'px';
				break;
			case 'left':
				this.element.style.left=(this.basePosition+this.position)+'px';
				break;
			case 'right':
				this.element.style.right=(this.basePosition+this.position)+'px';
				break;
			case 'width':
				this.element.style.width=(this.basePosition+this.position)+'px';
				break;
			case 'height':
				this.element.style.height=(this.basePosition+this.position)+'px';
				break;
			case 'margin-top':
				this.element.style.marginTop=(this.basePosition+this.position)+'px';
				break;
			case 'margin-bottom':
				this.element.style.marginBottom=(this.basePosition+this.position)+'px';
				break;
			case 'margin-left':
				this.element.style.marginLeft=(this.basePosition+this.position)+'px';
				break;
			case 'margin-right':
				this.element.style.marginRight=(this.basePosition+this.position)+'px';
				break;
			case 'padding-top':
				this.element.style.paddingTop=(this.basePosition+this.position)+'px';
				break;
			case 'padding-bottom':
				this.element.style.paddingBottom=(this.basePosition+this.position)+'px';
				break;
			case 'padding-left':
				this.element.style.paddingLeft=(this.basePosition+this.position)+'px';
				break;
			case 'padding-right':
				this.element.style.paddingRight=(this.basePosition+this.position)+'px';
				break;
		}
	}
	this.getPosition=function(slideDirection) {
		if(this.equation && slideDirection=='in')
			this.position=Math.round(this.equation(this.step,this.increment));
		else if(this.hideEquation && slideDirection=='out')
			this.position=Math.round(this.hideEquation(this.step,this.increment));
		else
			this.position=Math.round((this.step/100) * this.increment);

	}

	this.slideIn=function(sliding) {
		if(this.interval)
			window.clearInterval(this.interval);

		/*
		if(!sliding) {
			this.step=0;
			this.setPosition();
		}
		if(this.element.style.display=='none')
			this.element.style.display='inline';
		*/

		this.step=this.step + 100 / (this.trans/this.freq);

		this.setPosition('in');
		if(this.step!=100)
			this.interval=window.setInterval('API.sliders['+this.id+'].slideIn(true);',this.freq);
	}
	this.slideOut=function() {
		if(this.interval)
			window.clearInterval(this.interval);

		this.step=this.step - 100 / (this.trans/this.freq);
		this.setPosition('out');
		if(this.step>0)
			this.interval=window.setInterval('API.sliders['+this.id+'].slideOut(true);',this.freq);
			/*
		else {
			//this.step=100;
			this.setPosition();
		}*/
	}
}
