d = document;
w = window;

function checkAll(elm,name){
  for (var i = 0; i < elm.form.elements.length; i++)
  	if (elm.form.elements[i].name.indexOf(name) == 0)
	    elm.form.elements[i].checked = elm.checked;
}

function borderSlider(color, maxBorder, maxPadding, minBorder, delay)
{
	this.maxBorder = maxBorder;
	this.maxPadding = maxPadding;
	this.color = color || "#999";
	this.minBorder = minBorder;
	this.delay = delay || 20;
	this.count = borderSlider.count++;
	this.obj = "theBS" + this.count;
	this.total = this.minBorder + this.maxPadding;
	this.timer = null;
	this.slider = null;
	eval(this.obj + " = this");

	this.init = function()
	{
		
		if (d.addEventListener)
		{
			d.addEventListener("mouseover", this.overOut, true);
			d.addEventListener("mouseout", this.overOut, true);
		}
		else
		{
			//d.onmouseover = catchAllOver;//this.overOut;
			//d.onmouseout = catchAllOut;//this.overOut;
		}
	}

	this.overOut = function(e)
	{
		if (w.event)
		{
			e = window.event;
		}

		var obj = e.srcElement? e.srcElement : e.target;
	
		if (obj.tagName.toLowerCase() == "a" && obj.className.match(/slide/))
		{
			if (e.type == "mouseout")
			{
				slider.stopSlide();
			}
			else
			{
				slider.startSlide(obj);
			}
		}

	}
	
	this.startSlide = function(obj)
	{
		this.stopSlide();
		this.slider = obj;
		this.timer = setTimeout(this.obj + ".doSlide('left')", this.delay);
	}

	this.border = function(value)
	{
		if (!this.slider || !this.slider.style)
		{
			return 0;
		}

		if (!this.slider.style.borderLeft)
		{
			this.slider.style.borderLeft = this.minBorder + "px solid " + this.color;
		}

		if (typeof(value) != "undefined")
		{
			if (value < 0)
			{
				value = 0;
			}

			if (value > this.maxBorder)
			{
				value = this.maxBorder;
			}
			var result = value + "px solid " + this.color;
			this.slider.style.borderLeft = result;
		}
		return parseInt(this.slider.style.borderLeftWidth);
	}

	this.padding = function(value)
	{
		if (!this.slider || !this.slider.style)
		{
			return;
		}

		if (!this.slider.style.paddingLeft)
		{
			this.slider.style.paddingLeft = this.maxPadding + "px";
		}

		if (typeof(value) != "undefined")
		{
			if (value < 0)
			{
				value = 0;
			}

			this.slider.style.paddingLeft = value + "px";
		}
		return parseInt(this.slider.style.paddingLeft);
	}

	this.doSlide = function(direction)
	{
		var delta = 1;
		if (direction == "left")
		{
			this.border(this.border() - delta);	
			this.padding(this.total - this.border()); 
			if (this.border() == 0)
			{
				direction = "right";
			}
		}
		else
		{
			this.border(this.border() + delta);	
			this.padding(this.total - this.border()); 
			if (this.border() == this.maxBorder)
			{
				direction = "left";
			}
		}

		this.timer = setTimeout(this.obj + ".doSlide('" + direction + "')",
			this.delay + Math.pow(this.border(), 1.8) * 2);
	}

	this.stopSlide = function()
	{
		if (this.slider)
		{
			clearTimeout(this.timer);
			this.slider.style.paddingLeft = this.maxPadding + "px";
			this.slider.style.borderLeft = this.minBorder + "px solid " + this.color;
		}
	}

	return this;
}
borderSlider.count = 0;

slider = new borderSlider("#999", 9, 13, 1, 10);
slider.init();

