/**
 * Incapsulates functionality of the
 * System Updates widget
 */
var SystemUpdates = {

    /**
     * Initiates widget
     */
    init: function() {
        $('.sys_updates_pager a').live('click', function() {
            SystemUpdates.getPage($(this))
            return false;
        });
    },

    /**
     * Get specific page via ajax request
     */
    getPage: function(link) {
        $.ajax({
            'url': '/system-updates.html',
            'data': {
                'do': 'get_more',
                'page': link.attr('rel')
            },
            'dataType': 'html',

            'beforeSend': function (xhr) {
                $('.sys_updates_loading')
                    .height($('.sys_updates_area').height())
                    .css('top', $('.sys_updates_area').position().top)
                    .css('left', $('.sys_updates_area').position().left)
                    .show();
            },

            'success': function (data) {
                $('#sysupdatesWrapper').replaceWith(data);
            },
            
            'complete': function () {
                $('.sys_updates_loading').hide();
            }

        });
    }
};

$(document).ready(function(){
    SystemUpdates.init();
});
