function bounds()
{
	this.doc = (document.compatMode && document.compatMode!="BackCompat" ? document.documentElement : document.body);
	this.left = (document.all && !window.opera ? this.doc.scrollLeft : window.pageXOffset);
	this.top = (document.all && !window.opera ? this.doc.scrollTop : window.pageYOffset);
	this.right = (document.all && !window.opera ? this.left+window.clientWidth-15 : this.left+window.innerWidth-15);
	this.bottom = (document.all && !window.opera ? (this.top+window.clientHeight)-15 : (this.top+window.innerHeight)-15); //-18
};

bounds.prototype.getOffset = function(object, offsetType)
{
	var result = ((offsetType = (offsetType ? offsetType : "left"))!="left" ? object.offsetTop : object.offsetLeft);
	while((object=object.offsetParent))result+=(offsetType!="left" ? object.offsetTop : object.offsetLeft);
	return result;
};

function TSlider(visible, width, height, parent, rounding)
{
	this.iStep = 1;
	this.itWidth = 9;
	this.iPosition = 0;
	this.iMinimum = 0;
	this.iMaximum = 100;
	this.iWidth = width;
	this.bActive = false;
	this.iHeight = height;
	this.oAttachment = null;
	this.autoUpdate = false;
	this.windowBounds = new bounds();
	this.oParent = (parent ? parent : null);
	this.rounding = (rounding ? true : false);

	this.BaseObject = document.createElement('div');
	this.BaseObject.style.width = (width ? width : "100") + "px";
	this.BaseObject.style.height = (height ? height : "10") + "px";
	this.BaseObject.style.background = "url(images/slider.gif)";
	this.BaseObject.style.visibility = (visible ? "visible" : "hidden");

	this.ThumbObject = document.createElement('div');
	this.ThumbObject.style.width = "9px";
	this.ThumbObject.style.height = "20px";
	this.ThumbObject.style.left = "0px";
	this.ThumbObject.style.background = "url(images/thumb.gif)";
	this.ThumbObject.style.position = "relative";
	this.BaseObject.appendChild(this.ThumbObject);

	this.BaseObject.container = this;
	this.BaseObject.onmouseup = this.onMouseUp;
	this.BaseObject.onmousedown = this.onMouseDown;
	this.BaseObject.onmousemove = this.onMoving;
	this.BaseObject.onmouseover = this.onMouseOver;
	this.BaseObject.onmouseout = this.onMouseOut;

	this.mouseup = null;
	this.mouseout = null;
	this.mouseover = null;
	this.mousemove = null;
	this.mousedown = null;
	this.onupdate = null;

	if(this.oParent)this.oParent.appendChild(this.BaseObject); else document.body.appendChild(this.BaseObject);

	return this;
};

// functionality

TSlider.prototype.attachTo = function(Object, Max, osX, osY, iDefault)
{
	if((this.oAttachment = Object))
	{
		this.iMaximum = (Max*2);
		this.bActive = false;
		this.autoUpdate = true;
		this.oAttachment.MaxValue = Max;
		this.iMinimum = (this.iMaximum/2);
		this.BaseObject.style.position = "absolute";
		this.Position((Object.value && Object.value!="" ? Number(Object.value)+this.iMinimum : (iDefault!=null ? iDefault : 0)));
		this.topLeft(this.windowBounds.getOffset(Object,"top")+(osY ? osY : 0), this.windowBounds.getOffset(Object)+(osX ? osX : 0));
	};
};

TSlider.prototype.Visible = function(value)
{
	this.BaseObject.style.visibility = (value!=null ? (value ? "visible" : "hidden") : this.BaseObject.style.visibility);
	return (this.BaseObject.style.visibility != "hidden");
};

TSlider.prototype.Position = function(value)
{
	if(value!=null)
	{
		this.iPosition = (value < 0 ? 0 : (value > this.iMaximum ? this.iMaximum : value));
		if(this.oAttachment && this.autoUpdate)this.oAttachment.value = (this.rounding ? Math.round(this.iPosition-this.iMinimum) : (this.iPosition-this.iMinimum).toFixed(0));
		if(this.onupdate)this.onupdate(this.iPosition);
		this.updateThumb();
	};
	return this.iPosition;
};

TSlider.prototype.onProcessEvent = function(e)
{ 
	var posx = ((e = (e ? e : window.event)).pageX ? e.pageX : e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft);
	var itwid = this.toNumber(this.ThumbObject.style.width);
	posx-=(this.windowBounds.getOffset(this.BaseObject)+(itwid/2)).toFixed(0);
	posx = (posx<0 ? 0 : ( posx > this.bodyArea() ? this.bodyArea() : posx));
	posx = (this.iMaximum/this.bodyArea())*posx;
	this.Position(posx);
};


TSlider.prototype.toNumber = function(value){ return Number(String(value).replace(/px/, "")); };

TSlider.prototype.Width = function(value){ return (this.iWidth = (value ? value : this.iWidth)); };
TSlider.prototype.Height = function(value){ return (this.iHeight = (value ? value : this.iHeight)); };
TSlider.prototype.Maximum = function(value){ return (this.iMaximum = (value ? value : this.iMaximum)); };
TSlider.prototype.setTimeout = function(command, time){ this.timeout = setTimeout(command, (time ? time : 1000)); };
TSlider.prototype.BackgroundImage = function(value){ if(value)this.BaseObject.style.background = "url("+value+")"; };
TSlider.prototype.ThumbtrackImage = function(value){ if(value)this.ThumbObject.style.background = "url("+value+")"; };
TSlider.prototype.topLeft = function(Top, Left){ this.BaseObject.style.top = Top+'px'; this.BaseObject.style.left = Left+'px'; };
TSlider.prototype.updateThumb = function(value){ this.ThumbObject.style.left = ((this.bodyArea()/this.iMaximum)*this.iPosition)+"px"; };
TSlider.prototype.bodyArea = function(){ return this.toNumber(this.BaseObject.style.width)-this.toNumber(this.ThumbObject.style.width); };

// callbacks
TSlider.prototype.onMouseOut = function(e){ if(this.container.mouseout)this.container.mouseout(this.container, e); };
TSlider.prototype.onMouseOver = function(e){ if(this.container.mouseover)this.container.mouseover(this.container, e); };
TSlider.prototype.onMouseUp = function(e){ this.container.bActive = false; if(this.container.mouseup)this.container.mouseup(this.container, e); };
TSlider.prototype.onMoving = function(e){ if(this.container.bActive)this.container.onProcessEvent(e); if(this.container.mousemove)this.container.mousemove(this.container, e); };
TSlider.prototype.onMouseDown = function(e){ this.container.onProcessEvent(e); this.container.bActive = true; if(this.container.mousedown)this.container.mousedown(this.container, e); };



