function p(obj){
  if (window.console){ //Firefox+Firebug, Safari
    window.console.log(obj);
  }else if (window.opera){ //Opera
    window.opera.postError(obj);
  }else{ //IE
    window.status= obj;
  }
}

function getBrowser(){
  agent= navigator.userAgent.toLowerCase();
  return {
    ie: ((agent.indexOf("msie") != -1) && (agent.indexOf("opera") == -1))
  };
}
var browser= getBrowser();

//Firefoxではなぜか最初だけbase.offsetWidthが取れない（0になる）ので、
//widthとheightは手動で与えることにした。
function overlapOn(elem, base, width, height){
  var pos= Position.cumulativeOffset(base);
  elem.style.position= "absolute";
  //p([elem, base, base.offsetWidth, base.clientWidth, base.scrollWidth, base.width]);
  elem.style.left= pos[0]+"px";
  elem.style.top= pos[1]+"px";
  elem.style.width= width+"px";
  elem.style.height= height+"px";
}

//CSSの:hoverが使えない要素をホバーに対応させる。
//:hoverの代わりに.hoverを使う。
function enableHover(eventTarget, effectTarget){
  Event.observe(eventTarget, "mouseover", function(){
    Element.addClassName(effectTarget, "hover");
  }, false);
  Event.observe(eventTarget, "mouseout", function(){
    Element.removeClassName(effectTarget, "hover");
  }, false);
}

var Timer= Class.create();
Timer.prototype= {
  
  initialize: function(proc, name){
    this.proc= proc;
    this.name= name;
    this.id= null;
  },
  
  enable: function(msec){
    if (!this.id){
      //p([new Date(), "Timer#enable", this.name, msec]);
      this.id= setTimeout(this.onTimeout.bind(this), msec);
    }
  },
  
  disable: function(){
    if (this.id){
      //p([new Date(), "Timer#disable", this.name]);
      clearTimeout(this.id);
      this.id= null;
    }
  },
  
  enabled: function(){
    return this.id!=null;
  },
  
  onTimeout: function(){
    this.id= null;
    this.proc();
  }
  
}


