var MySampleClass = Class.create();

//defining the rest of the class implmentation
MySampleClass.prototype = {

  initialize: function() {
              this.values = [];
            },
  putValue: function(element,value) {
              this.values[element] = value;
            },
  getValue: function(element) {
               return this.values[element];
             }
};

var myHash = new MySampleClass();

function mouseOver(elt){
    var oldEltId = myHash.getValue("clickedItem");
    if (!oldEltId || oldEltId != elt.id) {
      var originalBackground = myHash.putValue(elt.id, originalBackground) || Element.getStyle(elt, 'background-color');
      /* alert("Found backgrou:"+originalBackground+" for elt:"+elt.id); */
      if (!originalBackground) {
        originalBackground = "transparent";
      }
      myHash.putValue(elt.id, originalBackground);
      elt.style.backgroundColor = "#fc0";
    }
}

function mouseOut(elt) {
    var oldEltId = myHash.getValue("clickedItem");
    if (!oldEltId || oldEltId != elt.id) {
      elt.style.backgroundColor = myHash.getValue(elt.id);
    }
}

function mouseClick(elt) {
    /* alert("Click item "+elt.id+" => "+ _ctent[elt.id]);  */
    var target = $("viewer");
    target.innerHTML = _ctent[elt.id];
    /* on se positionne au milieu ecran */
    var posy = ( getWindowHeight() - Element.getHeight(target) ) / 2 + getScroll()[1];
    var posx = Position.page(elt)[0] + elt.offsetWidth + 10;

    target.style.position = 'absolute';
    target.style.top = posy + 'px';
    target.style.left = posx + 'px';
    var oldEltId = myHash.getValue("clickedItem");
    if (oldEltId) {
        $(oldEltId).style.backgroundColor = myHash.getValue(oldEltId);
    }
    myHash.putValue("clickedItem", elt.id);
    elt.style.backgroundColor = "#fe0";
}

function getScroll() {
    var deltaX =  window.pageXOffset 
                || document.documentElement.scrollLeft 
                || document.body.scrollLeft 
                || 0;
    var deltaY =  window.pageYOffset 
                || document.documentElement.scrollTop 
                || document.body.scrollTop 
                || 0;
    return [deltaX, deltaY];
}

function getWindowHeight() {
  var windowHeight=0;
  if (typeof(window.innerHeight)=='number') {
    windowHeight=window.innerHeight;
  }
  else {
    if (document.documentElement&&
        document.documentElement.clientHeight) {
      windowHeight=
        document.documentElement.clientHeight;
    }
    else {
      if (document.body&&document.body.clientHeight) {
        windowHeight=document.body.clientHeight;
      }
    }
  }
  return windowHeight;
}

function winopen(url, stuff, morestuff) {
  var popup = window.open(url, stuff, morestuff);
  popup.focus();
}
