function slider (a_init, a_tpl)
{
this.f_setValue = f_sliderSetValue;
this.f_getPos = f_sliderGetPos;

// register in the global collection
if (!window.A_SLIDERS)
{
window.A_SLIDERS = [];
}
//this.n_id = window.A_SLIDERS.length;
//window.A_SLIDERS[this.n_id] = this;//uz nepotrebuju tohle this n id pac jsem dal svoje id
window.A_SLIDERS[0] = this;//uz nepotrebuju tohle this n id pac jsem dal svoje id
// save config parameters in the slider object
var s_key;
if (a_tpl)
{
for (s_key in a_tpl)
{
this[s_key] = a_tpl[s_key];
}
}
for (s_key in a_init)
{
this[s_key] = a_init[s_key];
}

this.n_pix2value = this.n_pathLength / (this.n_maxValue - this.n_minValue);
if (this.n_value == null)
{
this.n_value = this.n_minValue;
}



// generate the control's HTML
document.write(
'<div id="proslide" onmousedown="f_sliderMouseDown(0);" onselectstart="return false;" style="-moz-user-select: none;">'+
'<img src="img/slider_handle.gif" onmouseover="this.src =\'img/slider_handle_over.gif\'" onmouseout="this.src =\'img/slider_handle.gif\'" width="' + this.n_sliderWidth + '" height="' + this.n_sliderHeight + 
'" border="0" style="left:' + this.n_pathLeft + 'px;top:' + this.n_pathTop + 'px;" name="slider" id="slider" onmousedown="return f_sliderMouseDown(0)" alt="slider"/></div>'
);
this.e_base = get_element('proslide');
this.e_slider = get_element('slider');

// safely hook document/window events
if (document.onmousemove != f_sliderMouseMove) {
window.f_savedMouseMove = document.onmousemove;
document.onmousemove = f_sliderMouseMove;
}
if (document.onmouseup != f_sliderMouseUp) {
window.f_savedMouseUp = document.onmouseup;
document.onmouseup = f_sliderMouseUp;
}



this.e_slider.style.visibility = 'visible';
}

function f_sliderSetValue (n_value) {
if (n_value == null)
n_value = this.n_value == null ? this.n_minValue : this.n_value;
if (isNaN(n_value))
return false;
// round to closest multiple if step is specified
if (this.n_step)
n_value = Math.round((n_value - this.n_minValue) / this.n_step) * this.n_step + this.n_minValue;
// smooth out the result
if (n_value % 1)
n_value = Math.round(n_value * 1e5) / 1e5;

if (n_value < this.n_minValue)
n_value = this.n_minValue;
if (n_value > this.n_maxValue)
n_value = this.n_maxValue;

this.n_value = n_value;

// move the slider
this.e_slider.style.left = (this.n_pathLeft + Math.round((n_value - this.n_minValue) * this.n_pix2value)) + 'px';

window.scrollTo(n_value,0);
//document.body.style.backgroundPosition= (n_value/10)+"px 0px";
//scroluj
//window.location.hash = "#"+(n_value+pulsirkaOkna);
}

// get absolute position of the element in the document
function f_sliderGetPos (b_vertical, b_base) {
var n_pos = 0,
s_coord = (b_vertical ? 'Top' : 'Left');
var o_elem = o_elem2 = b_base ? this.e_base : this.e_slider;

while (o_elem) {
n_pos += o_elem["offset" + s_coord];
o_elem = o_elem.offsetParent;
}
o_elem = o_elem2;

var n_offset;
while (o_elem.tagName != "BODY") {
n_offset = o_elem["scroll" + s_coord];
if (n_offset)
n_pos -= o_elem["scroll" + s_coord];
o_elem = o_elem.parentNode;
}
return n_pos;
}

function f_sliderMouseDown (n_id) {
document.getElementById("slider").ondragstart = function() { return false; };//ie prevent drag image
window.n_activeSliderId = n_id;
return false;
}

function f_sliderMouseUp (e_event, b_watching) {
if (window.n_activeSliderId != null) {
var o_slider = window.A_SLIDERS[window.n_activeSliderId];
o_slider.f_setValue(o_slider.n_minValue + (o_slider.b_vertical
? (o_slider.n_pathLength - parseInt(o_slider.e_slider.style.top) + o_slider.n_pathTop)
: (parseInt(o_slider.e_slider.style.left) - o_slider.n_pathLeft)) / o_slider.n_pix2value);
if (b_watching) return;
window.n_activeSliderId = null;
//idecko = -(lastOne - Math.round(((o_slider.n_maxValue-o_slider.n_value)+(document.getElementById('0').offsetLeft))/300))-4;
//document.getElementById('contr').innerHTML = idecko;
}
if (window.f_savedMouseUp)
return window.f_savedMouseUp(e_event);
}

function f_sliderMouseMove (e_event) {

if (!e_event && window.event) e_event = window.event;

// save mouse coordinates
if (e_event) {
window.n_mouseX = e_event.clientX;
window.n_mouseY = e_event.clientY;
}

// check if in drag mode
if (window.n_activeSliderId != null) {
var o_slider = window.A_SLIDERS[window.n_activeSliderId];

var n_pxOffset;

var n_sliderLeft = window.n_mouseX - o_slider.n_sliderWidth / 2 - o_slider.f_getPos(0, 1) - 3;
// limit the slider movement
if (n_sliderLeft < o_slider.n_pathLeft)
n_sliderLeft = o_slider.n_pathLeft;
var n_pxMax = o_slider.n_pathLeft + o_slider.n_pathLength;
if (n_sliderLeft > n_pxMax)
n_sliderLeft = n_pxMax;
o_slider.e_slider.style.left = n_sliderLeft + 'px';
n_pxOffset = n_sliderLeft - o_slider.n_pathLeft;

if (o_slider.b_watch)
f_sliderMouseUp(e_event, 1);

return false;
}

if (window.f_savedMouseMove)
return window.f_savedMouseMove(e_event);
}

// get the scroller positions of the page
/*function f_scrollLeft() {
return f_filterResults (
window.pageXOffset ? window.pageXOffset : 0,
document.documentElement ? document.documentElement.scrollLeft : 0,
document.body ? document.body.scrollLeft : 0
);
}
function f_scrollTop() {
return f_filterResults (
window.pageYOffset ? window.pageYOffset : 0,
document.documentElement ? document.documentElement.scrollTop : 0,
document.body ? document.body.scrollTop : 0
);
}

function f_filterResults(n_win, n_docel, n_body) {
var n_result = n_win ? n_win : 0;
if (n_docel && (!n_result || (n_result > n_docel)))
n_result = n_docel;
return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
*/
function f_sliderError (s_message) {
alert("Slider Error:\n" + s_message);
window.n_activeSliderId = null;
}

get_element = document.all ?
function (s_id) { return document.all[s_id] } :
function (s_id) { return document.getElementById(s_id) };
