RequestsViewer = { 
  current: 0,
  type: '',
  
  initialize: function()
  {
    RequestsViewer.type = $('#RequestsTypeViewer span.requestType').text();
    $('#RequestsTypeViewer .close').click(RequestsViewer.close);
    $('#RequestsTypeViewer .previous, #RequestsTypeViewer .next').click(RequestsViewer.paginate);
  },
  
  close: function()
  {
    $.ajax({
      url: '/requests/removeAll',
      type: 'post',
      data: { type: RequestsViewer.type },
      success: function(data)
      {
        $('#RequestsTypeViewer').slideUp();
      }
    })
  },
  
  paginate: function()
  {
    var change = 1;
    if ( $(this).hasClass('previous') )
    {
      change = -1;
    }
    var page = RequestsViewer.current + change;
    
    
    $.ajax({
      url: '/requests/view',
      data: { type: RequestsViewer.type, page: page },
      type: 'post',
      dataType: 'json',
      success: function(data) 
      {
        RequestsViewer.current = RequestsViewer.current + change;
        $('#RequestsTypeViewer .content .Request').html(data.content);
      }
    });
  }
}

// Make Requests Work!
$(document).ready(RequestsViewer.initialize);