/*
 * Copyright 2006 OST-SYSTEMS. All rights reserved.
 */

function ServerFavourites(dir, callback) {
  this.dir = dir;
  this.callback = callback;
  var _self = this;
  
  this.loaded = function(list) {
    _self.setAll(list);
    if (_self.callback) {
      _self.callback(list);
    }  
  }
  
  this.addWidget = function(title, path) {
    _self.dir.widgetAdded(path);  
    return CookieFavourites.prototype.add.call(this, title, path);
  }
  
  this.removeFavourite = function(path) {
    _self.dir.favouriteRemoved(path);  
    return CookieFavourites.prototype.remove.call(this, path);
  }
  
  this.reload(this.loaded);
}

ServerFavourites.prototype = new CookieFavourites(this.dir, this.callback);

ServerFavourites.prototype.add = function(title, path) {
  return this.addWidget(title, path);
}

ServerFavourites.prototype.remove = function(path) {
  this.removeFavourite(path);
}

ServerFavourites.prototype.reload = function(callback) {
  var _self = this;
  this.dir.getPathList(function(list) {
    CookieFavourites.prototype.setAll.call(_self, new Array());
    for (var i = 0; i < list.length; i++) {
    	_self.add(list[i].title, list[i].path);
    }
    callback(list);
  }, "Favourites");
}

    
