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;
	this.eventHandler=null;
	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.attachEvent=function(eventName,eventProcedure) {
		if(!this.eventHandler)
			API.eventHandlers.New(this);
		this.eventHandler.attachEvent(eventName,eventProcedure);
	}
	this.setPosition=function(slideDirection) {
		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;
		}
		if(this.eventHandler)
			this.eventHandler.triggerEvent('onSetPosition_'+slideDirection,this);
	}
	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);

	}
	// AF20080901:	Increment adjustment feature
	this.setIncrement=function(newIncrement) {
		if(newIncrement==this.increment)
			return;


			/*
		currentPosition=this.getPosition();
		if(this.equation && slideDirection=='in')
			newPosition=Math.round(this.equation(this.step,this.increment));
		else if(this.hideEquation && slideDirection=='out')
			newPosition=Math.round(this.hideEquation(this.step,this.increment));
		else */



		ratio=newIncrement/this.increment;
		this.step=Math.round(this.step/ratio);

		this.backStep=this.step;
		this.increment=newIncrement;
		if(!this.interval)
			this.slideIn();
	}


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

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

		// BC20080901:	We can also decrease step now after increment changes
		if(this.step<100) {
			this.step=this.step + 100 / (this.trans/this.freq);

			// BC20080901:	Overflow protection moved here for increment changes
			if(this.step>100)
				this.step=100;
		}
		else if (this.step>100) {
			this.step=this.step - (this.backStep- 100) / (this.trans/this.freq) ;
			// BC20080901:	Overflow protection moved here for increment changes
			if(this.step<100)
				this.step=100;
		}

		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.interval=null;
		}
		// BC20080901:	Step may be larget than 100, need to compensate
		if(this.step<=100)
			this.step=this.step - 100 / (this.trans/this.freq);
		else
			this.step=this.step - (this.backStep- 100) / (this.trans/this.freq) ;
		// BC20080901:	Overflow protection moved here for increment changes
		if(this.step<0)
			this.step=0;

		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();
		}*/
	}
}