/*  Window.iGrowl, version 1.0: http://icebeat.bitacoras.com
 *  Daniel Mota aka IceBeat <daniel.mota@gmail.com>
 *  Modif. by Arti
--------------------------------------------------------------------------*/

var iGrowl = 
{
	init: function(duration)
	{
		iGrowl.src = './images/bg-growl.gif';
		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': '9999', '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': '10000', 'padding-top': '35px', 'font': '18px/35px "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();
window.extend({Growl:iGrowl.show});

