function Slider(strId){
	this.background = null;
	this.foreground = null;
	this.objBackGround = null;
	this.objForeGround = null;
	this.button = null;
	this.buttonY = 0;
	this.initialValue = 0;
	this.valueField = null;
	this.objValue = null;
	this.x = 0;
	this.sliderActX = 0;
	this.height = 0;
	
	this.slider = null;
	this.isDrag = false;
	this.xOnSliderButton = 0;
	this.doClip = doClip;
	this.setValue = setValue;
	this.doDisable = false;
	this.setDisabled = 0.0;
	this.setDisabledValue = setDisabledValue;
	
	this.mouseDownSlider = mouseDownSlider;
	this.mouseMoveSlider = mouseMoveSlider;
	this.mouseUpSlider = mouseUpSlider;
	var oThis = this;
	
	this.init = initSlider;
	
	
	function initSlider(){
		this.slider = document.getElementById(strId);
		this.slider.style.top = this.buttonY;
		this.sliderWidth = parseInt(this.slider.width) +1;
		this.sliderParentWidth = parseInt(this.slider.parentNode.style.width);
		this.units = 100<this.sliderParentWidth?100 / (this.sliderParentWidth-this.sliderWidth):(this.sliderParentWidth-this.sliderWidth) / 100;
		this.slider.style.left = this.sliderParentWidth / 100 * this.initialValue + "px";
		this.objValue = document.getElementById(this.valueField);
		
		this.objBackGround = document.getElementById(this.background);
		this.objForeGround = document.getElementById(this.foreground);
		//this.setValue(parseInt(this.units * parseInt(this.slider.style.left)));
		this.doClip(parseInt(this.slider.style.left));
		
		this.slider.parentNode.onmousemove = this.mouseMoveSlider;
		this.slider.parentNode.onmouseup = this.mouseUpSlider;
		this.slider.onmousedown = this.mouseDownSlider;
		this.slider.onmousemove = this.mouseMoveSlider;
		this.slider.onmouseup = this.mouseUpSlider;
		if(oThis.setDisabled > 0){
			oThis.doDisable = true;
			oThis.setDisabledValue();
		}
	}
	
	function mouseDownSlider(e){
		oThis.isDrag = true;
		oThis.sliderActX = parseInt(oThis.slider.style.left);
		if (document.all) {
			oThis.xOnSliderButton = event.clientX + document.body.scrollLeft - oThis.sliderActX;
		}
		else {
			oThis.xOnSliderButton = e.pageX - oThis.sliderActX;
		}
		return false;
	}
	
	function mouseMoveSlider(e){
		//doDebug(strId + " X = " + oThis.isDrag);
		if (oThis.isDrag && !oThis.doDisable) {
			if (document.all) {
				oThis.x = event.clientX + document.body.scrollLeft;
			}
			else {
				oThis.x = e.pageX;
			}
			oThis.x = Math.max(-1, Math.min(oThis.x - (oThis.xOnSliderButton), oThis.sliderParentWidth-oThis.sliderWidth-1));
			
			oThis.doClip(oThis.x+1);
			oThis.setValue(parseInt(oThis.units * oThis.x+1));
			oThis.slider.style.left = oThis.x + "px";
		}
		return false;
	}
	
	function setValue(intValue) {
		oThis.objValue.value = intValue + " %";
	}
	
	function doClip(intVal) {
		oThis.objForeGround.style.clip = "rect(0px " + intVal + "px " + oThis.height + "px 0px)";
	}
	
	function mouseUpSlider(e) {
		oThis.isDrag = false;
	}
	
	function setDisabledValue(){
		oThis.slider.style.opacity = oThis.setDisabled;
		oThis.slider.style.filter = 'alpha(opacity=' + oThis.setDisabled*100 + ')';
		oThis.slider.parentNode.style.opacity = oThis.setDisabled;
		oThis.slider.parentNode.style.filter = 'alpha(opacity=' + oThis.setDisabled*100 + ')';
		oThis.slider.style.cursor = 'auto';
	}
}

//Hilfsfunktion
function doDebug(str){
	obj = document.getElementById("debug");
	obj.innerHTML = str;
}
