function Slider(name) {
this.leftValue = 0;
this.rightValue = 10;
this.defaultValue = 5;
this.offsetX = 1;
this.offsetY = -1;
this.maxSlide = 60;
this.buttonWidth = 10;
this.buttonHeight = 15;
this.buttonImg =  "slider4button2.gif";
this.buttonHiliteImg = "slider4hibutton2.gif";
this.buttonHoverImg = "slider4hobutton2.gif";
this.imgPath = "/player2/image/";
this.orientation = "h";
this.writeSlider = Slider.writeSlider;
this.placeSlider = Slider.placeSlider;
this.makeEventHandler = Slider.makeEventHandler;
this.isPrototype = Slider.isPrototype;
this.getValue = Slider.getValue;
this.setValue = Slider.setValue;
this.MouseOver = Slider.MouseOver;
this.MouseOut =  Slider.MouseOut;
this.MouseDown = Slider.MouseDown;
this.MouseUp = Slider.MouseUp;
this.MouseSlide = Slider.MouseSlide;
this.onmouseover = null;
this.onmouseout = null;
this.onmousedown = null;
this.onmouseup = null;
this.onslide = null;
this.onchange = null;
this.onclick = null;
if (!window.sliders)  window.sliders = new Array();
this.name = name || "slider"+window.sliders.length;
window.sliders[window.sliders.length] = this;
window.sliders[this.name] = this;
if (!window.sliderDrag)
window.sliderDrag = new Object();}

function Slider.writeSlider () {var proto = this.prototype || this;
if (!proto.loImg) {
proto.loImg = new Image(proto.buttonWidth,proto.buttonHeight);
proto.loImg.src = proto.imgPath + proto.buttonImg;
if (proto.buttonHiliteImg) {
proto.hiImg = new Image(proto.buttonWidth,proto.buttonHeight);
proto.hiImg.src = proto.imgPath + (proto.buttonHiliteImg || proto.buttonImg);
}
if (proto.buttonHoverImg) {
proto.hoImg = new Image(proto.buttonWidth,proto.buttonHeight);
proto.hoImg.src = proto.imgPath + proto.buttonHoverImg;}
}
if (proto != this) {this.loImg = proto.loImg;
if (proto.hiImg)  this.hiImg = proto.hiImg;
if (proto.hoImg)  this.hoImg = proto.hoImg;
this.orientation = proto.orientation;
this.maxSlide = proto.maxSlide;}
var style = '<STYLE TYPE="text/css"><!--\n' + '#'+this.name+'Button {visibility:hidden; position:absolute; width:'+ proto.buttonWidth + 'px; height:'+ proto.buttonHeight +'px; z-index:1; }\n' + '--></STYLE>';
var content = '<DIV ID="'+this.name+'Button">'+ '<IMG ID="'+this.name+'ButtonImg" SRC="'+proto.loImg.src+'" WIDTH='+proto.buttonWidth+' HEIGHT='+proto.buttonHeight+'>'+ '</DIV>';
if (document.getElementById || document.layers || document.all) {document.writeln(style); document.writeln(content);}
if (document.layers) {
this.button = document.layers[this.name+"Button"];
this.button.img = this.button.document.images[0];
this.button.clip.width = proto.buttonWidth;
this.button.clip.height = proto.buttonHeight;
this.button.captureEvents(Event.MOUSEOVER|Event.MOUSEDOWN|Event.MOUSEOUT);
this.button.onmousedown = this.MouseDown;
this.button.onmouseout = this.MouseOut;
this.button.onmouseover = this.MouseOver;}
else if (document.all) {
this.button = document.all[this.name+"Button"];
this.button.img = document.all[this.name+"ButtonImg"];
this.button.style.pixelWidth = proto.buttonWidth;
this.button.style.pixelHeight = proto.buttonHeight;
this.button.onmousedown = this.MouseDown;
this.button.onmouseout = this.MouseOut;
this.button.onmouseover = this.MouseOver;}
else if (document.getElementById) {
this.button = document.getElementById(this.name+"Button");
this.button.img = document.getElementById(this.name+"ButtonImg");
this.button.style.width = proto.buttonWidth + 'px';
this.button.style.height = proto.buttonHeight + 'px';
this.button.addEventListener("mousedown",this.MouseDown,false);
this.button.addEventListener("mouseout",this.MouseOut,false);
this.button.addEventListener("mouseover",this.MouseOver,false);}
this.onmouseover = this.makeEventHandler(this.onmouseover);
this.onmouseout  = this.makeEventHandler(this.onmouseout);
this.onmousedown = this.makeEventHandler(this.onmousedown);
this.onmouseup   = this.makeEventHandler(this.onmouseup);
this.onslide = this.makeEventHandler(this.onslide);
this.onchange = this.makeEventHandler(this.onchange);
this.onclick = this.makeEventHandler(this.onclick);
this.button.slider = this;
if (document.all || document.getElementById) this.button = this.button.style;}

function Slider.placeSlider(imgName,layer) {
var proto = this.prototype || this;
var doc = (document.layers && layer)? ((typeof(layer) == 'string')? document.layers[layer].document : layer.document) : document;
imgName = imgName || this.name+'RailImg';
this.rail = (typeof(imgName) == 'string')? doc.images[imgName] : imgName;
var x = proto.offsetX;
var y = proto.offsetY;
if (this.rail.offsetParent) {
var parent = this.rail;
while (parent) {
x += parent.offsetLeft;
y += parent.offsetTop;
parent = parent.offsetParent;}
if (navigator.userAgent.indexOf("MSIE")+1 && navigator.userAgent.indexOf("Mac")+1) {
x += parseInt(document.body.currentStyle.marginLeft);
y += parseInt(document.body.currentStyle.marginTop);}}
else {
x += (typeof(this.rail.pageX) == 'number')? this.rail.pageX : this.rail.x;
y += (typeof(this.rail.pageY) == 'number')? this.rail.pageY : this.rail.y;
if (layer && document.layers) {
x += layer.pageX;
y += layer.pageY;}}
if (document.layers) {
this.button.left = x;
this.button.top = y;}
else if (document.all || document.getElementById) {
this.button.left = x + 'px';
this.button.top = y + 'px';}
this.offset = (proto.orientation == "v")? y : x;
this.setValue(this.defaultValue,true);
this.button.visibility = 'inherit';}

function Slider.isPrototype () {for (var i=0; i<window.sliders.length; i++)
window.sliders[i].prototype = window.sliders[i].prototype || this;}
Slider.MouseOver = function (e) {
window.sliderDrag.isOver = true;
if (this.slider.hoImg && !window.sliderDrag.isDown)  this.img.src = this.slider.hoImg.src;
if (this.slider.onmouseover)  this.slider.onmouseover(e);}

function Slider.MouseOut(e) {
window.sliderDrag.isOver = false;
if (this.slider.hoImg && !window.sliderDrag.isDown)  this.img.src = this.slider.loImg.src;
if (this.slider.onmouseout)  this.slider.onmouseout(e);}

function Slider.MouseDown(e) {
var slider = this.slider;
window.sliderDrag.dragLayer = this;
window.sliderDrag.dragged = false;
window.sliderDrag.isDown = true;
var evtX = evtY = 0;
if (!e) e = window.event;
if (typeof(e.pageX) == 'number') {
evtX = e.pageX;
evtY = e.pageY;}
else if (typeof(e.clientX) == 'number') {
evtX = e.clientX + (document.body.scrollLeft | 0);
evtY = e.clientY + (document.body.scrollTop | 0);}
if ((e.which && e.which == 3) || (e.button && e.button == 2)) return true;
if (document.layers) {
window.sliderDrag.offX = evtX - this.left + slider.offset;
window.sliderDrag.offY = evtY - this.top + slider.offset;}
else if (document.all || document.getElementById) {
window.sliderDrag.offX  =  evtX - parseInt(this.style.left) + slider.offset;
window.sliderDrag.offY  =  evtY - parseInt(this.style.top) + slider.offset;
if (e.cancelable) e.preventDefault();
if (e.stopPropagation) e.stopPropagation();
e.cancelBubble = true;}
document.onmousemove = slider.MouseSlide;
document.onmouseup = slider.MouseUp;
if (document.captureEvents) document.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
if (slider.hiImg) this.img.src = slider.hiImg.src;
if (slider.onmousedown)  slider.onmousedown(e);
return false;}

function Slider.MouseUp(e) {
var l = window.sliderDrag.dragLayer;
var slider = l.slider;
window.sliderDrag.isDown = false;
document.onmousemove = null;
document.onmouseup = null;
if (document.releaseEvents) document.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP);
window.sliderDrag.dragLayer = null;
if (slider.hiImg)
l.img.src = (window.sliderDrag.isOver && slider.hoImg)? slider.hoImg.src : slider.loImg.src;
if (slider.onmouseup)  slider.onmouseup(e);
if (window.sliderDrag.dragged) {
if (slider.onchange) slider.onchange(e);
document.player.settings.volume = (slider.getValue(1)*10);
}
else {
if (slider.onclick) slider.onclick(e);}
return false;}

function Slider.MouseSlide(e) {
var l = window.sliderDrag.dragLayer;
var slider = l.slider;
window.sliderDrag.dragged = true;
var evtX = evtY = 0;
if (!e) e = window.event;
if (typeof(e.pageX) == 'number') {
evtX = e.pageX;
evtY = e.pageY;}
else if (typeof(e.clientX) == 'number') {
evtX = e.clientX + (document.body.scrollLeft | 0);
evtY = e.clientY + (document.body.scrollTop | 0);}
var pos = (slider.orientation == "h")? Math.max(Math.min(evtX - window.sliderDrag.offX,slider.maxSlide),0) + slider.offset :Math.max(Math.min(evtY - window.sliderDrag.offY,slider.maxSlide),0) + slider.offset;
if (document.layers) {
if (slider.orientation == "h")  l.left = pos;
else  l.top = pos;}
else if (document.all || document.getElementById) {
if (slider.orientation == "h")  l.style.left = pos + 'px';
else  l.style.top = pos + 'px';
if (e.cancelable) e.preventDefault();
if (e.stopPropagation) e.stopPropagation();
e.cancelBubble = true;}
if (slider.onchange)  slider.onchange(e);
if (slider.onslide)  slider.onslide(e);
return false;}

Slider.getValue = function (n) {
var pos = (this.orientation == "h")? parseInt(this.button.left) : parseInt(this.button.top);
var val =  this.leftValue + (this.rightValue-this.leftValue) * (pos-this.offset) / this.maxSlide;
return (typeof(n) == 'number')?  toDecimals(val,n) :  val;}

function Slider.setValue(value,ignore) {
if (typeof(value) == 'string')  value = parseFloat(value);
if (isNaN(value))  value = this.defaultValue;
var rangeValue = (this.rightValue >= this.leftValue)? Math.min(Math.max(value,this.leftValue),this.rightValue) - this.leftValue :Math.max(Math.min(value,this.leftValue),this.rightValue) - this.leftValue;
var pos = this.maxSlide * rangeValue / (this.rightValue-this.leftValue) + this.offset;
if (document.layers) {
if (this.orientation == "h")  this.button.left = pos;
else  
this.button.top = pos;} 
else if (document.all || document.getElementById) {
if (this.orientation == "h")  this.button.left = pos;
else  this.button.top = pos;}
if (this.onchange && (!ignore))  this.onchange(null);}

Slider.makeEventHandler = function (f) {
return (typeof(f) == 'string')? new Function('e',f) : ((typeof(f) == 'function')? f : null);}

function toDecimals(val,n) {
if (isNaN(n)) return val;
for (var m=0; m<n; m++)  val *= 10;
for (var m=0; m>n; m--) val *= 0.1;
val = Math.round(val);
if (val < 0) {
val = -val;
var sgn = "-";}
else {
var sgn = "";}
var valstr = val.toString();
if (n>0) {
while (valstr.length<=n) valstr = "0"+valstr;
var len = valstr.length;
valstr = valstr.substring(0,len-n) +"."+ valstr.substring(len-n,len);}
else if (n<0) {
for (m=0; m>n; m--) valstr = valstr+"0";}
return sgn+valstr;}
