/*
 * This file is part of the mgWidgets package.
 * (c) 2008 Qarmaq 
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

function userHistories(){
  // this global attributes  
  this.wuid = null;
  this.widget = null;
  
  // widget attributes
  // this.field1 = null;
  //
}

userHistories.prototype = new mgWidgetObject();

// this method is call when the object is created
userHistories.prototype.init = function(wuid) {
  // common code
  this.wuid = wuid;
  this.widget = jQuery('#' + wuid);
  jQuery(window).bind('load.userHistories', [this, 'load']);
  
  // extra params
  // place here your extra init information
  
}

// this method is call when the DOM / window is loaded
userHistories.prototype.load = function()
{
  // add here your load event
  // always use jQuery's namespace event
  //jQuery(window).bind('click.userHistories', [this, 'onClickButton']);
  
  // reload depend on the user settings

  this.loadHistories();
}

userHistories.prototype.loadHistories = function()
{
  var url = Portal.linkToAction('userHistories', 'retrieveHistoriesList', this.wuid, {});

  // this is not great
  var widget = this;
  
  jQuery.getJSON(url, function(object_histories) {
    
    var html = '';
    
    for(var object in object_histories)
    {
      var histories = object_histories[object];
      html += ' <ul class="view-mode-list-first-col">';
      for(var pos in histories)
      {
        var history = histories[pos];
        
        html += '<li class="item-view-mode-list">';

        html += '  <div class="item-list-picture">';
        html += '    <a href="' + history.link + '" title="' + history.name + '">' + history.image + '</a>';
        html += '  </div>';
         
        html += '  <div class="item-list-info">';
        html += '    <a href="' + history.link + '" title="' + history.name + '">' + history.truncated_name + '</a>';
        html += '    <div class="item-list-stars"><p class="stars star-' + parseInt(history.note) + '">&nbsp;</p></div>';
        html += '    <div class="clear"></div>';
        html += '  </div>';
        
        html += '  <div class="clear"></div>';
        html += '</li>';
      }
      
      html += ' </ul>';
    }
    
    jQuery('div.widget-results-list', '#' + widget.wuid).html(html);
  });
}

userHistories.prototype.unload = function()
{

}

userHistories.prototype.resize = function(size)
{
  
}


// set javascript for this widget as loaded 
WIDGET_LOADED['userHistories'] = true;
