/* 
 * This versatile 1kb horizontal accordion script can be used for menus, images, presentation content and more.
 * The script will automatically adjust to the number of elements in the accordion and the dimensions of the accordion.
 * The first parameter is the id of the unordered list you would like to bind the accordion to. 
 * The second is the width you would like the accordion selection to expand to. 
 * The third is the timeout variable to control how quickly the sliding function is called. 
 * The fourth is the speed of the accordion with 1 being the fastest. 
 * The last is optional and is the integer that corresponds to the section you would like to be expanded when the accordion is loaded.
 */
 
/**
 * @constructor
 */
function Slider( sm, sw, mt, s, sl, h) {
	this.sp = s; 
	this.st = sw; 
	this.t = mt;
	this.m = document.getElementById( sm);
	this.sa = this.m.getElementsByTagName( 'li');
	this.l = this.sa.length; 
	this.w = this.m.offsetWidth; 
	this.sw = this.w / this.l;
	this.ot = Math.floor(( this.w - this.st)/( this.l - 1)); 
	this.timer = function( self, s) {
		s.onmouseover = function(){ clearInterval( self.m.timer); self.m.timer = setInterval( function() { self.slide( self, s)}, self.t)}
		};
	this.slide = function( self, s){
		var cw = parseInt( s.style.width, '10');
		if( cw < self.st) {
			var owt = 0; 
			var i = 0;
			for( i; i < self.l; i++) {
				if( self.sa[ i] != s) {
					var o, ow;
					var oi = 0;
					o = self.sa[ i];
					ow = parseInt( o.style.width, '10');
					if( ow > self.ot) {
						oi = Math.floor(( ow - self.ot) / self.sp); 
						oi = (oi > 0) ? oi : 1;
						o.style.width = (ow - oi) + 'px';
					}
					owt = owt + (ow - oi);
				}
			}
			s.style.width = (self.w - owt) + 'px';
		} else {
			clearInterval( self.m.timer);
		}
	};
	var i = 0;
	for( i; i < this.l; i++) {
		s = this.sa[ i];
		s.style.width = this.sw + 'px'; 
		this.timer( this, s)
	}
	if( sl != null) {
		var self = this;
		this.m.timer = setInterval( function(){ self.slide( self, self.sa[ sl - 1])}, self.t);
	}
}

