/**
 * 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]);
	
	if (Browser.Engine.trident) {
		// IE Hack
		scroll_y		=	0;
	}
	else {
		scroll			=	body.getScroll();
		scroll_y		=	scroll.y;
	}
	
	
	// Open layer
	backlayer		=	new Element('div', {
		id:			'messaging_backlayer',
		styles:	{
			'z-index':		99999998,
			'position':		'absolute',
			'top':			scroll_y + 'px',
			'left':			0,
			'background':	'#000',
			'width':		'100%',
			'height':		'100%',
			'opacity':		0.8
		}
	});
	
	
	contentlayer	=	new Element('div', {
		id:			'messaging_contentlayer',
		styles:	{			
			'z-index':		99999999,
			'position':		'absolute',
			'top':			scroll_y + 'px',
			'left':			0,
			'background':	'none',
			'width':		'100%',				
			'height':		'100%',
			'textShadow':	'none'				
		}
	});
	
	
	floater	=	new Element('div', {
		className:	'messaging-floater',
		id:		'floater-' + this.id,
		styles:	{				
			width:			'508px',			
			margin:			'40px auto',
			opacity:		0,
			lineHeight:		'24px',
			fontSize:		'14px'
		}
	});
	
	floater_top	=	new Element('div', {
		html:	'<a style="padding: 10px 0 0 0;float: right; color: #999; text-decoration: none; border: none" class="messaging_message_close" id="close-' + this.id + '" href="#">schließen</a>',
		id:		'map',
		styles:	{				
			width:			'468px',
			height:			'30px',
			padding:		'0 20px 0 20px',
			background:		'url(' + serverpath + '/cms/javascript/images/floater-top.png)',
			lineHeight:		'14px',
			fontSize:		'12px'
		}
	});
	
	floater_bottom	=	new Element('div', {
		id:		'map',
		styles:	{				
			width:			'508px',
			height:			'30px',
			background:		'url(' + serverpath + '/cms/javascript/images/floater-bottom.png)'
		}
	});
	
	floater_body	=	new Element('div', {
		html:	this.message,
		id:		'map',
		styles:	{				
			'width':		'468px',
			background:		'url(' + serverpath + '/cms/javascript/images/floater-body.png)',
			padding:		'0 20px 0 20px',
			color:			'#666'
		}
	});
	
	
	if (!$('messaging_backlayer')) {
		contentlayer.inject(body);
		floater.inject(contentlayer);
		floater_top.inject(floater);
		floater_body.inject(floater);
		floater_bottom.inject(floater);
		backlayer.inject(body);
		body.setStyle('height', '400px');
		body.setStyle('overflow', 'hidden');		
	}
	else {
		
		$('floater-' + (this.id - 1)).destroy(); 	
	
		floater.inject($('messaging_contentlayer'));
		floater_top.inject(floater);
		floater_body.inject(floater);
		floater_bottom.inject(floater);		
	}

	floater.fade(1);
	
	$$('a.messaging_message_close').addEvent('click', function (e) {		
		id	=	this.id.split('-')[1];		
		$('floater-' + id).fade(0);		
		window.setTimeout("Messaging_Message_FloaterShow()", 500);
		e.stop();
	});	
}

var Messaging	=	new Messaging();

