$(document).ready(function() {
//    $().ajaxStart(function() {Growl.show('<span id="loading"></span><br />loading...');});
    Growl.init(336,154,2);
});
var Growl = {
    init:function(width,height,duration) {
	Growl.msg = [];
	Growl.active = false;
	Growl.duration = (duration || 2)*1000;
	Growl.height = height/2;
	Growl.width = width/2;
	$("#growlmsg").remove();
	$("#growl").remove();
	$(document).ready(function() {Growl.create();});
    },
    create:function() {
	$('body').append('<p id="growlmsg"></p><div id="growl" class="growl"></div>');
    },
    queue:function() {
	var msg = Growl.msg.pop();
	if(msg) Growl.show(msg, true);
    },
    show:function(msg,timer) {
	if(Growl.active) {
    	    Growl.msg.push(msg);
	    return;
	}
	Growl.duration = ((timer*1000) || Growl.duration);
	Growl.active = true;
	var top = document.documentElement.scrollTop || window.pageYOffset || 0;
	var left = document.documentElement.scrollLeft || window.pageXOffset || 0;
	var h = (window.innerHeight || document.documentElement.clientHeight || 0)/2;
	var w = (window.innerWidth || document.documentElement.clientWidth || 0)/2;
	var he = top+h-Growl.height, we = left+w-Growl.width;
	$('#growlmsg').css({top: he+'px', left: we+'px'}).show().html(msg).fadeTo(800,1);
	$('#growl').css({top: he+'px', left: we+'px'}).show().fadeTo(800,0.8);
	setTimeout(function() {Growl.hide();}, Growl.duration);
    },
    hide: function() {
	$('#growlmsg').fadeOut("slow",function() {Growl.display($(this));});
	$('#growl').fadeOut("slow",function() {
	    Growl.display($(this));
	    Growl.active = false;
	    setTimeout(function() {Growl.queue();}, 200);
	});
    },
    display: function(e) {
	e.hide();
    }
};
