function CategSlider(idx) {
    if (idx == undefined) idx = 0;
    this.idx = idx;
    this.slideTimer = null;
    this.steps = 40;
    this.ie = true;
    this.speed = 40;//timeout between steps
    this.nav = find_object('cat_slider_nav');
    this.frame = find_object('cat_slider_frame');
    this.content = find_object('cat_slider_content');
    if (this.frame.offsetWidth) {
        this.r = this.content.offsetWidth / this.frame.offsetWidth
        if (this.r > 1) {
            this.nav.style.display = 'block'; 
            this.button = find_object('cat_slider_button');
            this.buttonMove = false;
            var t = this;
            this.button.onmousedown = function(ev) {t.mousedown(ev);};
            document.onmouseup = function(ev) {t.buttonMove = false;};
            document.onmousemove = function(ev) {t.mousemove(ev);};
            this.prev = find_object('cat_slider_prev');
            this.prev.onclick = function() {t.slide(1);};
            this.next = find_object('cat_slider_next');
            this.next.onclick = function() {t.slide(-1);};
            this.stripe = find_object('cat_slider_stripe');
            this.stripe.onclick = function(ev) {t.stripeClick(ev);};
            this.setButtonPos(); 
        }
    }
}
CategSlider.prototype.setBounds = function() {
    this.minContentLeft = this.frame.offsetWidth - this.content.offsetWidth; 
    this.maxButtonLeft = this.stripe.offsetWidth - this.button.offsetWidth;
}
CategSlider.prototype.stripeClick = function(ev) {
    this.setBounds();
    var p = this.getPos(ev);
    var button_to = p[0] - findPosX(this.stripe) + (this.ie ? parseInt(this.button.offsetWidth/2) -15: -parseInt(this.button.offsetWidth/2));
    var content_to =   button_to * this.minContentLeft / (this.stripe.offsetWidth - this.button.offsetWidth);
    this.slide(undefined, undefined, 0, content_to);
}
CategSlider.prototype.setButtonPos = function() {
    this.setBounds();
    this.button.style.left = this.content.offsetLeft/this.minContentLeft * this.maxButtonLeft + 'px';
}
CategSlider.prototype.setContentPos = function() {
    this.setBounds();
    this.content.style.left = this.button.offsetLeft/this.maxButtonLeft * this.minContentLeft + 'px';
}
CategSlider.prototype.mousemove = function(ev) {
    if (this.buttonMove) {
        var p = this.getPos(ev);
        var l = this.button.offsetLeft + p[0] - this.dragFrom;
        this.setBounds();
        if (l < 0) {
            l = 0;
        } else if (l > this.maxButtonLeft) {
            l = this.maxButtonLeft;
        } else {
            this.dragFrom = p[0];
        }
        this.button.style.left = l + 'px';
        this.setContentPos();
    }
}
CategSlider.prototype.mousedown = function(ev) {
    this.buttonMove = true;
    var p = this.getPos(ev);
    this.dragFrom = p[0];
}
CategSlider.prototype.getPos = function(ev) {
    if (ev) {
        ev.preventDefault();
    } else {
        event.cancelBubble = true;
        event.returnValue = false;
    }
    var e = ev ? ev : event;
    this.ie = ev ? false : true;
    return [e.pageX ? e.pageX : e.x, e.pageY ? e.pageY : e.y];
    
}
CategSlider.prototype.slide = function(dir, from, curr, to, steps, speedstr) {
    if (from == undefined) {
        from = this.content.offsetLeft;
    }
    if (dir == undefined && to != undefined) {
        dir = to < from ? -1 : 1;
    }
    if (to == undefined) {
        to = from + dir * this.frame.offsetWidth * .5;
    }
    if (to > 0) {
        to = 0;    
    } else if (to < this.minContentLeft) {
        to = this.minContentLeft;
    }
    if (to == from) return false;
    if (curr == undefined) {
        curr = 0;
    }
    if (!curr) clearTimeout(this.slideTimer);
    if (steps == undefined) {
        steps = Math.abs(parseInt(this.steps*(to-from)/this.frame.offsetWidth));
        speedstr = '';
    }
    curr += Math.abs(to-from)/steps;
    if ((dir == -1) && ((from - curr) < to))  {
        curr=from-to;
    }
    if ((dir == 1) && ((from + curr) > to)) {
        curr = to-from;
    }
    var c = Math.abs(curr / (to-from));
    var speed = parseInt(this.speed - this.speed * (1 - c * c * c * c));
    speedstr += c + ', '+speed + '\n';
    var l  = parseInt(from + dir*curr);
    this.content.style.left=l+'px';
    if (dir*from +curr<dir*to) {
        var self = this;
        this.slideTimer = setTimeout(function(){ self.slide(dir, from, curr, to, steps, speedstr)},speed); 
    } else {
        //alert(speedstr);
    }
    this.setButtonPos();
}

