/**
 * Messaging class
 */
function Messaging ( ) {
	this.messages	=	[];
}


/**
 * Get messages
 */
Messaging.prototype.getMessages = function ( ) {
	return this.messages;
}


/**
 * Register new message
 * 
 * @param {Object} message
 */
Messaging.prototype.register = function ( message ) {
	
	message.id		=	this.messages.length + 1;
	this.messages.push(new Message(message));
}

function Message ( data ) {
	this.type		=	data.type;
	this.message	=	data.message;
	this.id			=	data.id;
}

Message.prototype.display = function ( ) {
	
	var body		=	$(document.getElementsByTagName('body')[0]);
	scroll			=	$(window).scrollTop();
	
	// Open geocode input layer
	backlayer		=	jQuery(document.createElement("div"));
	backlayer.attr('id', 'messaging_backlayer');
	
	backlayer.css('position', 'absolute');
	backlayer.css('height', '100%');
	backlayer.css('width', '100%');
	backlayer.css('background', '#000');
	backlayer.css('opacity', '0.8');
	backlayer.css('z-index', '99999999998');
	backlayer.css('top', scroll + 'px');
	
	
	contentlayer	=	jQuery(document.createElement("div"));
	contentlayer.attr('id', 'messaging_contentlayer');
	
	contentlayer.css('z-index', '99999999999');
	contentlayer.css('position', 'absolute');
	contentlayer.css('top', scroll + 'px');
	contentlayer.css('left', 0);
	contentlayer.css('background', 'none');
	contentlayer.css('width', '100%');
	contentlayer.css('height', '100%');
	contentlayer.css('textShadow', 'none');
	
	floater	=	jQuery(document.createElement("div"));
	floater.attr('class', 'messaging-floater');
	floater.attr('id', 'floater-' + this.id);
	
	floater.css('width', '508px');
	floater.css('margin', '40px auto');
	floater.css('opacity', 1);
	floater.css('lineHeight', '24px');
	floater.css('fontSize', '14px');
	
	
	floater_top	=	jQuery(document.createElement("div"));
	floater_top.attr('id', 'map');
	
	floater_top.css('width', '468px');
	floater_top.css('height', '30px');
	floater_top.css('padding', '0 20px 0 20px');
	floater_top.css('background', 'url(' + serverpath + '/cms/javascript/images/floater-top.png)');
	floater_top.css('lineHeight', '14px');
	floater_top.css('fontSize', '12px');
			
			
	link		=	jQuery(document.createElement("a"));
	link.attr('class', 'messaging_message_close');
	link.attr('id', 'close-' + this.id);
	link.attr('href', '#');
	link.text('Schließen');
	
	link.css('padding', '10px 0 0 0');
	link.css('float', 'right');
	link.css('color', '#999');
	link.css('textDecoration', 'none');
	link.css('border', 'none');
		
		
	floater_bottom	=	jQuery(document.createElement("div"));
	
	floater_bottom.css('width', '508px');
	floater_bottom.css('height', '30px');
	floater_bottom.css('background', 'url(' + serverpath + '/cms/javascript/images/floater-bottom.png)');
	
		
	floater_body	=	jQuery(document.createElement("div"));
	floater_body.text(this.message);
	
	floater_body.css('width', '468px');
	floater_body.css('background', 'url(' + serverpath + '/cms/javascript/images/floater-body.png)');
	floater_body.css('padding', '0 20px 0 20px');
	floater_body.css('color', '#666');
	
	if ($('#messaging_backlayer').length == 0) {
					
		contentlayer.prependTo(body);
		floater.appendTo(contentlayer);
		floater_top.appendTo(floater);
		link.appendTo(floater_top);
		floater_body.appendTo(floater);
		floater_bottom.appendTo(floater);
		backlayer.prependTo(body);	
		body.css('overflow', 'hidden');
	}
	else {
		
		$('#floater-' + (this.id - 1)).remove(); 	
	
		floater.appendTo($('#messaging_contentlayer'));
		floater_top.appendTo(floater);
		floater_body.appendTo(floater);
		floater_bottom.appendTo(floater);		
	}
	
	
	floater.fadeIn('fast');
	
	$('a.messaging_message_close').click(function (e) {		
		id	=	this.id.split('-')[1];		
		$('#floater-' + id).fadeIn('fast');		
		window.setTimeout("Messaging_Message_FloaterShow()", 500);
		e.stopImmediatePropagation();
	});
}

var Messaging	=	new Messaging();

