var Wishlist = Class.create();
Wishlist.prototype = {
  
  initialize: function() {
    this.key = Cookie.get('Wishlist_ID');
  },
  
  add: function(id) {
    new Ajax.Request('/add_to_wishlist', {
      onSuccess: function(transport) {
        this.key = transport.responseText;
        Cookie.set('Wishlist_ID', this.key, 30);
        document.location.href = '/wishlist?key=' + this.key;
      }.bind(this),
      parameters: {
        key: this.key,
        page_id: id
      }
    });
  },

  remove: function(id) {
    new Ajax.Request('/remove_from_wishlist', {
      onSuccess: function(transport) {
        this.key = transport.responseText;
        Cookie.set('Wishlist_ID', this.key, 30);
        if($("wish-item-"+id)){Effect.DropOut("wish-item-"+id)}
      }.bind(this),
      parameters: {
        key: this.key,
        page_id: id
      }
    });
  },
  
  exists: function() {
    return this.valid_key(this.key);
  },
  
  valid_key: function(key) {
    return String(key).match(/^[A-Z0-9]{32}$/) != null;
  }
  
};

var MyWishlist = new Wishlist();