/*
 Copyright (c) 2009 Brian Kenn, Spiffy Internet
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

var Messenger = {
  autohide_message: null,
  
  showMessage: function(message){
    $('flash-message').innerHTML = "<div><div><p>" + message + "</p></div></div>";
    new Effect.BlindDown('flash-message', {
      duration: 1.0,
      queue: 'end'
    });
    
    if (this.autohide_message != null) {
      clearTimeout(this.autohide_message);
    }
    this.autohide_message = setTimeout(Messenger.fadeMessage.bind(this), 5000);
  },
  
  // Notice-level messages.  See Messenger.error for full details.
  notice: function(message){
    $('flash-message').removeClassName('flash-error');
    $('flash-message').addClassName('flash-notice');
    this.showMessage(message);
  },
  
  // When given an error message, wrap it in a list
  // and show it on the screen.  This message will auto-hide
  // after a specified amount of miliseconds
  error: function(message){
    $('flash-message').removeClassName('flash-notice');
    $('flash-message').addClassName('flash-error');
    this.showMessage(message);
  },
  
  // Responsible for fading the message in the dom
  fadeMessage: function(){
    new Effect.BlindUp('flash-message', {
      duration: 1.0,
      queue: 'end'
    });
    this.autohide_message = null;
  }
};
