/*
*  Slidebar v1.0
*  Date: 2008-12-8
*/
function SlideBar(){
	this.maxValue=100;
	this.defaultValue = 0;
	this.Lang = new Array(new Array(), new Array());
	this.id = 0;
	this.curLValue = 0;
	this.curRValue = this.maxValue;
}

SlideBar.List = [];
SlideBar.getValue = function(id){
	return typeof id=="string" ? SlideBar.List[id].value : id.value;
}
SlideBar.setValue = function(id,evt){
	var v = typeof evt=="object"?(evt?evt:window.event):evt;
	var tid = id;
	var lineobj = $("line_" + tid);

	var bid = $(id + "_l");
	var eid = $(id + "_r");

	id = typeof id!="object" ? SlideBar.List[id] : id;

	if(typeof v != "object"){
		id.style.left = (id.parentNode.clientWidth-id.clientWidth-id.getStyle("border-left-width").cint()*2)*v/id.handle.maxValue + "px";
		id.style.right = id.handle.maxValue + "px";
		id.value = v;
	}else{
		if (v.x < id.parentNode.clientWidth/2)
		{
			var L = (v.layerX||v.x)-bid.clientWidth/2;
			bid.value = (L*bid.handle.maxValue/(bid.parentNode.clientWidth-bid.clientWidth-bid.getStyle("border-left-width").cint()*2)).toFixed(2);
			bid.style.left = L + "px";
			MaxPosition = $(tid + "_r").style.right.replace("px","");

			SlideBar.List[tid].curLValue = bid.value;

			lineobj.style.left = bid.style.left;
			lineobj.style.width = (bid.parentNode.clientWidth - MaxPosition - L) + "px";

			if(bid.handle.onmoving)bid.handle.onmoving.apply(bid);
			if(bid.handle.onend)bid.handle.onend.apply(bid);
		// RIGHT SLIDEBAR
		}else{
			var R = (v.layerX||v.x)-eid.clientWidth/2;
			eid.value = (R*bid.handle.maxValue/(eid.parentNode.clientWidth-eid.clientWidth-eid.getStyle("border-right-width").cint()*2)).toFixed(2);
			eid.style.right = eid.parentNode.clientWidth - R + "px";
			MaxPosition = $(tid + "_l").style.left.replace("px","");

			SlideBar.List[tid].curRValue = eid.value;

			lineobj.style.left = MaxPosition;
			lineobj.style.width = R - MaxPosition;

			if(eid.handle.onmoving)eid.handle.onmoving.apply(eid);
			if(eid.handle.onend)eid.handle.onend.apply(eid);
		}
	}
}
SlideBar.moveCursor = function(evt){
	evt = evt?evt:window.event;
	var me = $(this);
	var detlaX = evt.clientX - me.offsetLeft; //parseInt(me.style.left);

	if(document.all){
		me.attachEvent("onmousemove",move);
		me.attachEvent("onmouseup",up);
		me.setCapture();
	}else{
		document.addEventListener("mousemove",move,true);
		document.addEventListener("mouseup",up,true);
		evt.stopPropagation();
		evt.preventDefault();
	}

	var meWidth = me.parentNode.clientWidth - me.clientWidth - me.getStyle("border-left-width").cint()*2;	
	var onmoving = me.handle.onmoving;
	var onend = me.handle.onend;

	function move(evt){
		if(!document.all){evt.stopPropagation();}
		var w = evt.clientX - detlaX;
		var meid = me.id;
			meid = meid.replace("_r","").replace("_l","");
		var lineobj = $("line_" + meid);
		var MaxPosition;

		if(w<0 || w>meWidth){
			return;
		}

		if (me.id.indexOf("_l") > 0)
		{
			MaxPosition = $(meid + "_r").style.right.replace("px","");

			if (w < me.parentNode.clientWidth - MaxPosition - 10)
			{
				SlideBar.List[meid].curLValue = me.value;
				me.style.left = w + "px";
				lineobj.style.left = me.style.left;
				try{
					lineobj.style.width = me.parentNode.clientWidth - MaxPosition - w;
				}catch(e){;}
			}
		}else{
			MaxPosition = $(meid + "_l").style.left.replace("px","");

			if (w > MaxPosition)
			{
				SlideBar.List[meid].curRValue = me.value;
				me.style.right = meWidth - w + "px";
				lineobj.style.left = MaxPosition + "px";

				try{
					lineobj.style.width = me.parentNode.clientWidth - (meWidth - w) - MaxPosition;
				}catch(e){;}
			}
		}

		me.value = ((w/meWidth)*me.handle.maxValue).toFixed(2);

		if(onmoving){
			onmoving.apply(me);
		}
	}

	function up(evt){	
		if(document.all){
			me.detachEvent("onmousemove",move);
			me.detachEvent("onmouseup",up);
			me.releaseCapture();
		}else{
			document.removeEventListener("mousemove",move,true);
			document.removeEventListener("mouseup",up,true);
			evt.stopPropagation();
		}
		if(onend){onend.apply(me);}
	}
}
SlideBar.prototype.write = function(){
	var id = this.id;
	var t = this;

	SlideBar.id = this.id;
	var str = '<div class="slidebox">'
			+ '<div class="lineBox" onmousedown="SlideBar.setValue(\''+ SlideBar.id +'\',event)"><div id="line_'+ SlideBar.id +'" class="line"></div></div>'
			+ '<div class="cursor_l" id="'+ SlideBar.id +'_l"></div>'
			+ '<div class="cursor_r" id="'+ SlideBar.id +'_r"></div>'
			+ '<div class="lineText" id="lineText_'+ SlideBar.id +'" onmousedown="SlideBar.setValue(\''+ SlideBar.id +'\',event)"></div>';
			+ '</div>';
	document.write(str);

	setTimeout(function(){
		var e = $(id + "_l");
		SlideBar.List.push(e);
		SlideBar.List[id] = e;
		e.onmousedown = SlideBar.moveCursor;
		e.style.left = (e.parentNode.clientWidth-(e.clientWidth+e.getStyle("border-left-width").cint()*2))*t.defaultValue/t.maxValue + "px";
		e.value = c.defaultValue;
		if(t.onmoving){t.onmoving.apply(e)}
		e.handle = t;

		var e = $(id + "_r");
		SlideBar.List.push(e);
		SlideBar.List[id] = e;
		SlideBar.List[id].curLValue = 0;
		SlideBar.List[id].curRValue = t.maxValue;
		e.onmousedown = SlideBar.moveCursor;
		e.style.right = (e.parentNode.clientWidth-(e.clientWidth+e.getStyle("border-right-width").cint()*2))*t.defaultValue/t.maxValue + "px";
		e.value = t.defaultValue;
		if(t.onmoving){t.onmoving.apply(e)}
		e.handle = t;
	},0);
}

try{
	document.execCommand("BackgroundImageCache", false, true);
}catch(e){;}
