new Namespace("eu.mckinley.slider.search");
eu.mckinley.slider.search = Class.create({
    sliderlength : 615,
    pages : 0,
    active : 1,
    pageall : 0,
    initialize : function (slider) {
        var childs = slider.getElementsBySelector("ul.block");
        this.pages = childs.length;
        this.pageall = $('pageall').innerHTML;
        if (this.pages > 1) {
            $('resultslider').setStyle({
                width : (this.pages * this.sliderlength) + 'px'
            });
            $('pageprev').addClassName('lock');
            $('pagenext').focus();
        }
        else {
            $('pageend').update(this.pages);
            $('searchpage').hide();
        }
        this.update();
    },
    slidePrev : function () {
        if (this.active == 1) {
            return;
        }
        var startpos = - (this.active - 1) * this.sliderlength;
        var endpos = - (this.active - 2) * this.sliderlength;
        this.active --;
        this.update();
        $('pagestart').update(((this.active - 1) * 8) + 1);
        if (this.active == 1) {
            $('pageprev').addClassName('lock');
            $('pagenext').focus();
        }
        $('pagenext').removeClassName('lock');
        var ani = new Animator();
        ani.addSubject(new NumericalStyleSubject($('resultslider'), 'left', String(startpos) + 'px', String(endpos) + 'px'));
        ani.play();
    },
    slideNext : function () {
        if (this.active == this.pages) {
            return;
        }
        var startpos = - (this.active - 1) * this.sliderlength;
        var endpos = - (this.active) * this.sliderlength;
        this.active ++;
        this.update();
        if (this.active == this.pages) {
            $('pagenext').addClassName('lock');
            $('pageprev').focus();
            $('pageend').update(this.pageall);
        }
        $('pageprev').removeClassName('lock');
        var ani = new Animator();
        ani.addSubject(new NumericalStyleSubject($('resultslider'), 'left', String(startpos) + 'px', String(endpos) + 'px'));
        ani.play();
    },
    update : function () {
        $('pagestart').update(((this.active - 1) * 8) + 1);
        $('pageend').update((this.active) * 8);
    }
});

