var pagi=null;

var PaginationClass = new Class({
    initialize: function(el, max) {
        this.element = $(el);
        this.max = max;

        this.historyKey = this.element.id;
        this.history = HistoryManager.register(
            this.historyKey,
            [1],
            function(values) {
                //this.to(parseInt(values[0]));
                for(i1=$('kritika').pages.length-1; i1>=0; --i1)
                    if($('kritika').pages[i1]==values[0]) {
                        this.go($('kritika').urls[i1],$('kritika').pages[i1]);
                        break;
                    }
            }.bind(this),
            function(values) {
                return [this.historyKey, '(', values[0], ')'].join('');
            }.bind(this),
            this.historyKey + '\\((\\w+)\\)');
    },

    by: function(dir) {
        this.to(this.page + dir);
    },
    
    to: function(page) {
/*alert("!");
        this.page = page;
        this.history.setValue(0, this.page);*/
    },
    
    go: function(script,page) {
        $('kritika').urls.push(script);
        $('kritika').pages.push(page);
        eval(script);
        this.page = page;
        this.history.setValue(0, this.page);
    },

    to_search: function(query) {
        this.cleanup();
        this.page = query;
        this.history.setValue(0, this.page);
    }
});

function my_click(script,page)
{
    if($('kritika').urls[$('kritika').urls.length-1]===script) {
        pagi.go(script,page);
        return;
    }
    pagi.go(script,page);
}

