Notify = Class.create({
	initialize: function(options){
		this.showing = false;
		this.options = {
			id: 'zuiNotify',
			notification: '',
			iconURL: '',
			opacity: 0.8,
			effect: 'slide',
			effectDuration: 0.3,
			background: '#000000',
			color: '#ffffff',
			position: 'top',
			closeOnClick: true
		};
		Object.extend(this.options, options);
		document.body.insert("<div class=\"zuiNotify\" id=\""+this.options.id+"\" style=\"display: none;\">\
		<p>"+(this.options.iconURL != "" ? "<img src=\""+this.options.iconURL+"\" alt=\"icon\" />" : "")+
		this.options.notification+"</p></div>");
		$(this.options.id).setOpacity(this.options.opacity);
		var clone = this;
		Event.observe(window, 'resize', function(){
			clone.setPosition(clone.options.position);
		});
		Event.observe(window, 'keydown', function(e){
			if(e.keyCode == Event.KEY_ESC && clone.isShowing()) clone.hide();
		});
		if(this.options.closeOnClick)
			$(this.options.id).observe('click', function(){clone.hide()});
		delete clone;
		return this.setPosition(this.options.position);
	},
	setPosition: function(vertical){
		this.options.position = vertical;
		var vw = document.viewport.getWidth();
		var nw = $(this.options.id).getWidth();
		$(this.options.id).setStyle({
			left: ((vw-nw)/2)+"px"
		});
		if(vertical == "top") $(this.options.id).setStyle({top: '0'});
		else $(this.options.id).setStyle({bottom: '0'});
		return this;
	},
	update: function(text, icon){
		this.options.notification = text;
		this.options.iconURL;
		$(this.options.id).update("<p>"+
			(this.options.iconURL != "" ? "<img src=\""+this.options.icon+"\" alt=\"icon\" />" : "")+
			this.options.notification+"</p>");
		return this;
	},
	show: function(){
		if(this.showing) return this;
		if(this.options.effect != "none") {
			var clone = this;
			new Effect.toggle(this.options.id, this.options.effect, {duration: this.options.effectDuration,
			afterFinish: function(){
				clone.showing = true;
				return clone; 
			}});
		}
		else{
			$(this.options.id).show();
			this.showing = true;
			return this;
		}
		return this;
	},
	isShowing: function(){
		return this.showing;
	},
	hide: function(){
		if(!this.showing) return this;
		if(this.options.effect != "none"){
			var clone = this;
			new Effect.toggle(this.options.id, this.options.effect, {duration: this.options.effectDuration, 
			afterFinish: function(){
				clone.showing = false;
				return clone;
			}});
		}
		else{
			this.showing = false;
			$(this.options.id).hide();
			return this;
		}
	},
	hideIn: function(time){
		var clone = this;
		setTimeout(function(){
			if(clone.showing) clone.hide();
		}, time*1000);
		clone.showing = false;
		return clone;
	},
	toggle: function(){
		if(this.showing) return this.hide();
		else return this.show(); 
	},
	setStyle: function(newStyles){
		this.options.background = this.options.background;
		this.options.color = newStyles.color;
		Object.extend(newStyles);
		$(this.options.id).setStyle(styles);
		return this;
	}
});
