var UnibetUpdates = new Class({
    Implements :[Options],
    options : {},
    initialize :function (options){
        this.setOptions(options);       
    },
    startUpdates : function(){
        //$('banner_bottom').innerHTML= inspect(this.processResponse);
        var myJSONRemote = new Request.JSON({
            url: "/UnibetJsonUpdates",
            onSuccess: this.processResponse.bind(this)
        });
        myJSONRemote.get({
            'unibetLastUpdate':unibet_initial_timestamp ,
            'date': unibet_date
        });
    },
    processResponse : function(response){
        var games = response.games;        
        var timestamp = response.timestamp;
        if(unibet_initial_timestamp != 0){
            unibet_initial_timestamp = timestamp;
        }
        games.each(this.process_game,this);
    },
    process_game : function(game,index){
        var unibet_id = game['unibetId'];
        try{
            var cell1 = $(String.concat('unibet1_',unibet_id));
            var cell2 = $(String.concat('unibet2_',unibet_id));
            var cellx = $(String.concat('unibetX_',unibet_id));
            var cell1Val = cell1.innerHTML.trim();
            var cell2Val = cell2.innerHTML.trim();
            var cellxVal = cellx.innerHTML.trim();
            if(game.oddHome != cell1Val){
                cell1.innerHTML = game.oddHome;
                cell1.addClass("yellbg");
            }
            if(game.oddAway != cell2Val){
                cell2.innerHTML = game.oddAway;
                cell2.addClass("yellbg");
            }
            if(game.oddDraw != cellxVal){
                cellx.innerHTML = game.oddDraw;
                cellx.addClass("yellbg");
            }
        }catch (err){            
            
        }
       
    }
});
window.addEvent('domready', function() {
    if(unibet_initial_timestamp && unibet_date){
        var updater = new UnibetUpdates();
        var twoMins = 1000 * 30;
        var intervalID = updater.startUpdates.periodical(twoMins,updater);
    }
});
