function ProductMenuHandler(allItems, expandedItems) {
  this.allItems = allItems;
  this.expandedItems = expandedItems;
  //show expanded
  for (var j=0; j<this.expandedItems.length; j++) {
    this.expandItem(this.expandedItems[j], true);
  }
  //set handlers
  for (var i=0; i<allItems.length; i++) {
    var itemBtn = this.getItemButton(allItems[i]);
    if (itemBtn != null) {
      itemBtn.handler = this;
      itemBtn.itemId = allItems[i];
      itemBtn.onclick = this.onItemButtonClick;
    }
  }
  this.updateCookie(this.expandedItems);
}

ProductMenuHandler.prototype.getItemHolder = function(id) {
  return document.getElementById("menu-item-block-" + id);
}

ProductMenuHandler.prototype.getItemButton = function(id) {
  return document.getElementById("menu-item-icon-" + id);
}

ProductMenuHandler.prototype.expandItem = function(id, expanded) {
  if (this.getItemHolder(id) == null) return;
  this.getItemHolder(id).style.display = expanded ? 'block' : 'none';         
  this.getItemButton(id).src = expanded ? '/img/icon.collapse.gif' : '/img/icon.expand.gif';
}

ProductMenuHandler.prototype.turnItem = function(id) {
  var newExp = [];
  var d = false;
  for (var i=0; i<this.expandedItems.length; i++) {
    if (this.expandedItems[i] == id) {
      this.expandItem(id, false);
      d = true;
    }
    else {
      newExp[newExp.length] = this.expandedItems[i];
    }
  }
  if (!d) {
    newExp[newExp.length] = id;
    this.expandItem(id, true);
  }
  this.expandedItems = newExp;
  this.updateCookie(newExp);
}

ProductMenuHandler.prototype.updateCookie = function(newExp) {
  var c = "0";
  for (var k=0; k < newExp.length; k++) {
      c = c + ',' + newExp[k];
  }
  this.setCookie("expandedItem", c, "/");
}

//handlers
ProductMenuHandler.prototype.onItemButtonClick = function() {
  this.handler.turnItem(this.itemId);
}

ProductMenuHandler.prototype.setCookie = function(name, value, path) {
      document.cookie = name + "=" + value + ((path) ? "; path=" + path : "");
}