var BubbleMenuItem = new Class({
  initialize: function(coords, detailsElement){
    this.coordArray = coords.split(",");
    this.detailsElement = detailsElement;
    this.valid = (this.coordArray != true) && (this.coordArray instanceof Array) && (this.coordArray.length == 4) && (this.detailsElement != null);
  },
  isPointInItem: function(x, y){
    return (this.valid) && (x >= this.coordArray[0]) && (x <= this.coordArray[2]) && (y >= this.coordArray[1]) && (y <= this.coordArray[3]);
  }
});

var BubbleMenu = new Class({
  initialize: function(bubbleimage, menuItemList){
    this.bubbleimage = bubbleimage;
    this.menuItemList = menuItemList;
    this.current = null;
    this.bubbleimage.addEvent('mousemove', function(e){
      var ev = new Event(e);
      ev.stop();
      var x = ev.page.x - ev.target.getLeft([$('mainscrollouter')]);
      var y = ev.page.y - ev.target.getTop([$('mainscrollouter')]);
      var found = null;
      for (i = 1; i < this.menuItemList.length && found == null; i++) {
        if ((this.menuItemList[i] instanceof BubbleMenuItem) && this.menuItemList[i].isPointInItem(x, y)) {
          found = this.menuItemList[i];
        }
      }
      if (found != null) {
        this.bubbleimage.setStyle('cursor', 'pointer');
        this.showDetails(found.detailsElement);
      }
      else {
        this.bubbleimage.setStyle('cursor', 'default');
        this.showDetails(this.menuItemList[0].detailsElement);
      }

    }.bind(this));
  },
  showDetails: function(next) {
    if (this.current == null || this.current.id != next.id) {
      if (this.current != null) {
        this.current.setStyle('display','none');
      }
      next.setStyle('display','block');
      this.current = next;
    }
  }
});
BubbleMenu.implement(new Events);


function getUrlParam(name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regex = new RegExp("[\\?&]"+name+"=([^&#]*)");
	var results = regex.exec(window.location.href);
	return (results != null) ? results[1] : '';
}