/*  Window.iGrowl, version 1.0: http://icebeat.bitacoras.com
 *  Daniel Mota aka IceBeat <daniel.mota@gmail.com>
--------------------------------------------------------------------------*/
var iGrowl = {
  init: function(img,duration) {
    iGrowl.src = img;
    iGrowl.msg = [];
    iGrowl.active = false;
    iGrowl.duration = (duration || 2)*1000;
    Window.onDomReady(iGrowl.create);
  },
  create: function() {
    var imgiGrowl = new Image();
    imgiGrowl.onload = iGrowl.box.pass(imgiGrowl);
    imgiGrowl.src = iGrowl.src;
  },
  box: function(img) {
    iGrowl.height = img.height/2;
    iGrowl.width = img.width/2;
    new Element('div').setProperty('id','growl').setStyles({
      'height':img.height+'px','width':img.width+'px',
  	  'display':'none','position':'absolute','opacity':'0','z-index':'999',
  	  'background': 'transparent url('+iGrowl.src+') no-repeat'
  	}).injectInside(document.body);
  	new Element('p').setProperty('id','growlmsg').setStyles({
  	  'width':img.width+'px',
  	  'display':'none','position':'absolute','opacity':'0','z-index':'1000','padding-top':'35px',
      'font':'14px/22px "Lucida Grande", Arial','color':'#fff','text-align':'center'
  	}).injectBefore($('growl'));
  },
  queue: function() {
    var msg = iGrowl.msg.pop();
    if(msg) iGrowl.show(msg);
  },
  show: function(msg) {
    if(iGrowl.active) {
      iGrowl.msg.push(msg);
      return;
    }
    iGrowl.active = true;
    var top = Window.getScrollTop(), left = Window.getScrollLeft(), h = Window.getHeight()/2 , w = Window.getWidth()/2;
		var he = top+h-iGrowl.height, we = left+w-iGrowl.width;
		$('growlmsg').setStyles({'top':he+'px','left':we+'px','display':'block'}).setHTML(msg).setOpacity(1);
		$('growl').setStyles({'top':he+'px','left':we+'px','display':'block'}).setOpacity(0.8);
		iGrowl.hide.delay(iGrowl.duration);
  },
  hide: function() {
    $('growlmsg').effect('opacity',{onComplete:iGrowl.display}).custom(1,0);
    $('growl').effect('opacity',{onComplete: function(e) {
      iGrowl.display(e);
      iGrowl.active = false;
      iGrowl.queue.delay(200);
    }}).custom(0.8,0);
  },
  display: function(e) {
    e.setStyle('display','none');
  }
};

iGrowl.init('http://www.thecitadelle.org/images/2007/growl.png',4);
window.extend({Growl:iGrowl.show});