//--Check namespaces
if (typeof Widget == "undefined") {
  var Widget = new Object();
}
Widget.SlidePanel = Class.create({
  initialize: function(element, duration){
    this.element = $(element);
    if(!this.element){return false;}
    this.duration = Object.isNumber(duration) ? duration : 0.8;
    this.state = "closed"
    this.closeRatio = "75%";//this.element.getStyle("left");
    this.element.observe("click", this.toggle.bind(this));
  },
  toggle: function(){
    if(this.state == "running"){return;}
    var effectOptions = this.state == "closed" ? {leftPos: "0%", state: "opened"} : {leftPos: this.closeRatio, state: "closed"};   
    this.state = "running";
    new Effect.Morph('slidePanel', {
      style: 'left: '+effectOptions.leftPos,
      duration: this.duration,
      afterFinish: function(){this.state = this.element.className = effectOptions.state;}.bind(this)
    });
  }
});

