var dao_console = null; 

var w = {
	
	options: {	},
	header: null,
	title: null,
	buttons: null,
	body: null,
	prebody: null,
	messages: null,
	empty: true,
	is_visible: false,
		
	_init: function (options) {
		dao_console = this;
		$.extend(this.options, options);
		var self = this;
		var t = this.element.find('#console-messages');
		if (t.length == 0) { return null; }
		this.messages = t.css('border', 'none').css('display', 'block');
		var t = this.element.find('#console');
		if(t.css('display') !== undefined && t.css('display') != 'none') {
			this.is_visible = true;
			this.hide();
		}
	}, 

	toggle: function() {
		if(this.is_visible) {
			this.hide();
		} else {
			this.show();
		}
	},
	
	show: function() {
		if(this.is_visible) return;
		this.element.css('display', 'block');
		h = $('#absolute-middle').css('bottom');
		h = h.substr(0, h.length - 2);
		$('#absolute-middle').css('bottom', (Number(h) + this.element.height())+'px');
		this.is_visible = true;
	},
	
	hide: function() {
		if(!this.is_visible) return;
		h = $('#absolute-middle').css('bottom');
		h = h.substr(0, h.length - 2);
		$('#absolute-middle').css('bottom', (Number(h) - this.element.height())+'px');
		this.element.css('display', 'none');
		this.is_visible = false;
		
	},
	
	update_layout: function() {
		$('#absolute-middle').css('bottom', (this.is_visible ? this.element.height() : 0) + 5);
	},
	
	message: function (message, type) {
		if(!message) return;
		if(this.empty){
			this.empty = false;
//			this.show();
		}
		if(type == null) {
			type = 0;
		}
		var a_class = 'ui-widget-content';
		switch (type) {
			case 'alert':
				a_class += ' ui-state-alert';
				break;
			case 'error':
				a_class += ' ui-state-error';
				break;
			case 0:
			case 1:
			case 2:
			case 3:
			case 4:
			case 5:
				a_class += ' debug-level'+type;
				break;
		}
		$('<li class="'+a_class+'">'+message+'</li>')
			.appendTo(this.messages);
		this.messages.stop().scrollTo({top:'100%', left:'0%'}, 3000);

	}
};
$.widget('ui.dao_console', w);

$(document).ready(function () {
	var t = $(document).find('#absolute-console');
	if (t.length == 0) {
		return;
	}
	t.dao_console();
});

