var CompanyVideoList = function(id)
{
  this.id = null;
  this.urlTemplate = null;
  this.totalPages = 1;
  this.currentPage = 1;

  this.init = function(id)
  {
      this.id = id;
      this.getMoreButton().click(this.createHandler(this.handleMoreClick));
  }

  this.getMoreButton = function()
  {
      return $('#video-list-more-' + this.id);
  }

  this.getLoadingIndicator = function()
  {
      return $('#video-list-loading-' + this.id);
  }

  this.getItemsUl = function()
  {
      return $('#video-list-ul-' + this.id);
  }

  this.handleMoreClick = function()
  {
      this.getMoreButton().hide();
      this.getLoadingIndicator().show();
      this.currentPage++;
      var url = this.urlTemplate.replace("%s", this.currentPage);
      $.get(url, { page_no: this.currentPage }, this.createHandler(this.handleResponse));
  }

  this.handleResponse = function(content, status)
  {
      if (status == "success")
      {
	  this.getLoadingIndicator().hide();
	  if (this.currentPage < this.totalPages)
	  {
	    this.getMoreButton().show();
	  }
	  this.getItemsUl().append(content);
      }
  }

  this.createHandler = function(handlerFunction)
  {
      var thisObject = this;
      var handlerFunction = handlerFunction;

      var handler = function()
      {
	  handlerFunction.apply(thisObject, arguments);
	  return false;
      }
      
      return handler;
  }

  this.init(id);
};

