/**
 * @constructor
 */
function NotificationManager(){
	$.extend($.modal.defaults, {
		close:false,
		position: ["20%"],
		overlayId:'notificationsOverlay',
		containerId:'notificationsContainer',
		onOpen: function (dialog) {
			var title = $(".usersettings-title");
			var storedTitle = title.html ();
			$(".gcms_confirm_header_field").html ("Laden...");
			dialog.overlay.fadeIn (400);
			dialog.container.fadeIn (400, function () {
				dialog.data.fadeIn (400, function () {
					title.html(storedTitle);
				});
			});
		},
		onClose: function (dialog) {
			dialog.data.fadeOut (400, function () {
				dialog.container.fadeOut (400);
				dialog.overlay.fadeOut (400, function () {
					$.modal.close ();
				});
			});
		}
	});
	
	var confirm = $('<div class="gcms_confirm" style="display:none;">'+
					'<table class="gcms_confirm_header"><tr><td></td>' + 
					'<td class="gcms_confirm_header_field">Confirm</td>' + 
					'<td><a href="#" title="Close" class="modalCloseX simplemodal-close"  style="visibility:hidden;"><img class="modalCloseImg" src="'+gcmsData.config.urlBase+'images/cross.gif" alt="X" /></a></td>'+
					'</tr></table>'+
					'<div class="gcms_confirm_message"></div>'+
					'<div class="gcms_confirm_buttons">'+
					'</div></div>');

	
	
	this.confirm = function(options) {
		if(!options) options = {};
		confirm.modal({
			onShow: function (dialog) {
				dialog.data.find('.gcms_confirm_header_field').html(options.title || "Confirm");
				dialog.data.find('.gcms_confirm_message').html(options.message || "");

				dialog.data.find('.modalCloseX').css("visibility",(options.close)?"visible":"hidden");
				
				var buttonContainer = $(".gcms_confirm_buttons",dialog.data).empty();
				$.each(options.buttons || [{label:"Ok"}],function(){
					var button=this;
					$(document.createElement("div"))
					.text(button.label || "Schließen")
					.click(function (e) {
						// call the callback
						var close=true;
						if (button.onClick && $.isFunction(button.onClick)) {
							close = button.onClick(e);
						}
						// close the dialog
						if(close!==false)
							$.modal.close();
					})
					.appendTo(buttonContainer);
				});
			}
		});
	};
	
	this.showUserSettings = function(){
		//load html and javascript
		$.ajax({
			data:{
				handlerClass:"UserSettingsDialog"
			},
			type: "GET",
			success: function(response) {
				eval(response.script);
				var html = $(response.html);
				new UsersettingsProcessor(html);
				html.modal({onShow:function(dialog){
					dialog.data.find('.gcms_confirm_header_field').text("Benutzereinstellungen");										
				}});

			}
		});
		return false;
	};	
	
	
	var infoPanel = $("<div id=\"gcms_infoPanel\">abc</div>").appendTo('body');
	this.info = function(infoText, time) {
		var Msg = "<p style='text-align: center; vertical-align: middle; padding: 5px;'>" + infoText + "</p>";
		infoPanel.html (Msg).fadeIn ('slow');
		setTimeout (function(){infoPanel.fadeOut ('slow');}, time || 3000);
	}
};
