Dashboard = new Class({
    initialize: function () {
        this.stocklist = $('winelist-wrapper');
        this.pagination_events();
    },
    
    pagination_event: function (direction) {
        if ($(direction)) {
            this.next = $(direction);
            this.next.addEvent('click',function(e){
                e.stop();
                this.retrieve_stock(e.target.get('href').substr(1));
            }.bind(this));
        }
    },
    
    pagination_events: function () {
        this.pagination_event('next');
        this.pagination_event('previous');
    },
    
    retrieve_stock: function (page) {
        new Request({
                url: "/portfolio/api/stock/",
                onRequest: function(){
                    this.stocklist.setStyle('background','url(/media/img/loader.gif) no-repeat center');
                    $('winelist').fade('out');
                    $('pager').fade('out');
                }.bind(this),
                onSuccess: function(html){ 
                    (function(){
                    this.stocklist.set('html',html).setStyle('background','none');
                    this.pagination_events();
                    $('winelist').fade('hide').fade('in');
                    $('pager').fade('hide').fade('in');
                    }.bind(this)).delay(500);
                }.bind(this)
            }).get({'page':page})
    }
})

