window.addEvent('domready', function(){
        HistoryManager.initialize();
        
        // устанавливаем в первоначальную позицию
        var firstPage = 'frame/portpholio.html';
        var pagi = new PaginationClass(firstPage);

        $$('a').addEvent('click', function(e) {
                e.stop();
                pagi.to(this.href);
        });
        
        HistoryManager.start();

});


var PaginationClass = new Class({
        
        initialize: function(firstPage, loadFirst) {
                
                this.historyKey = '';
                this.history = HistoryManager.register(
                        this.historyKey,
                        [firstPage],
                        function(values) {
                                this.to(values[0]);
                        }.bind(this),
                        function(values) {
                                return [this.historyKey, values[0]].join('');
                        }.bind(this),
                        this.historyKey + '(.+)'
                );
        },

        to: function(page) {
                if (page === undefined || page === null /*|| dCond*/) return;

                page = page.replace(/^http:\/\/[^\/]+/, '');
                this.page = page;
                
                var req = new Request.HTML({url:page,update:'textbox'}).get(page);
                
                this.history.setValue(0, this.page);
        }
});

