function PastelAlertManager() {
	var $container = null;
	var $alert = null;
 
	var elements = {
		title: {selector:"p.id_title", element: null},
		subtitle: {selector:"div.id_subtitle", element: null},
		extSubtitle: {selector:"div.id_subtitle_ext", element: null},
		extSubtitleName: {selector:"div.id_subtitle_ext p", element: null},
		extSubtitleUrl: {selector:"div.id_subtitle_ext span", element: null}, 
		error: {selector:"div.id_error", element: null}, 
		text: {selector:"p.id_text", element: null},
		textCenter: {selector:"p.id_text_center", element: null},
		email: {selector:"div.id_mail_cont", element: null},
		password: {selector:"div.id_password_cont", element: null},
		passwordMail: {selector:"span.id_password_mail", element: null},
		feedback: {selector:"div.id_feedback_cont", element: null}
	};
	
	//desc: {selector:"p.id_title", element: null},
	var getElement = function(desc) {
		var $element = desc.element;
		if ($element == null) {
			$element = $(desc.selector, $container);
		}
		desc.element = $element;
		return $element;
	};
 
	var defaultConfig = {
		title: translate('Attention'),
		subtitle: "",
		extSubtitle: null,//{name:"", url: ""},
		error: "",
		text: "",
		textPosition: "left",
		email: false,
		password: false,
		passwordMail: "",
		feedback: false,
		buttons: ["ok","cancel"], //ok,cancel,continue,login,logout,yes,no
		onAction: function(type, data){},
		payload: {}
	};
	
	var setupTitle = function(config) {
		var $title = getElement(elements.title);
		$title.html(config.title);
		$title.css("display", "block");
	};
	
	var setupSubtitle = function(config){
		var $subtitle = getElement(elements.subtitle);
		$subtitle.css("display", "none");
		var $extSubtitle = getElement(elements.extSubtitle);
		$extSubtitle.css("display", "none");
		
		if (config.subtitle != "") {
			var $subtitle = getElement(elements.subtitle);
			$subtitle.html(config.subtitle);
			$subtitle.css("display", "block");
		} else if (config.extSubtitle != null) {
			var $extSubtitle = getElement(elements.extSubtitle);
			$extSubtitle.css("display", "block");
			
			var $extSubtitleName = getElement(elements.extSubtitleName);
			$extSubtitleName.html(config.extSubtitle.name);		
			
			var $extSubtitleUrl = getElement(elements.extSubtitleUrl);
			$extSubtitleUrl.html(config.extSubtitle.url);
		}
	};
	
	var setupError = function(config) {
		var $error = getElement(elements.error);
		$error.html(config.error);
		$error.css("display", config.error != "" ? "block" : "none");
	};
	
	var setupText = function(config) {
		$text = getElement(elements.textCenter);
		$text.css("display", "none");
		$text.html("");
		$text = getElement(elements.text);
		$text.css("display", "none");
		$text.html("");
		
		if (config.text != "") {
			var $text = null;
			if (config.textPosition == "center") {
				$text = getElement(elements.textCenter);
			} else {
				$text = getElement(elements.text);
			}
			$text.html(config.text);
			$text.css("display", "block");
		}
	};
	
	var setupMail = function(config) {
		var $mail = getElement(elements.email);
		$mail.css("display", config.email ? "block" : "none");
		$("input.id_mail", $container).val("");
	};
	
	var setupPassword = function(config) {
		var $passwordMail = getElement(elements.passwordMail);
		$passwordMail.html(config.passwordMail);
		
		var $password = getElement(elements.password);
		$password.css("display", config.password ? "block" : "none");
		
		$("input.id_password", $container).val("");
	};
	
	var setupFeedback = function(config) {
		var $feedback = getElement(elements.feedback);
		$feedback.css("display", config.feedback ? "block" : "none");
		
		$("textarea.id_feedback", $container).val("");
	};
	
	var sender = this;
	var setupButtons = function(config) {
		var buttons = config.buttons;
 
		$("a[class*='id_btn_']", $container).css("display", "none");
 
		for (var i = 0; i<config.buttons.length; i++) {
			var buttonName = buttons[i];
			var $button = $("a.id_btn_"+buttonName, $container);
			$button.css("display", "block");
			(function(buttonName) {
				$button.unbind("click");
				$button.click(function(event){
					var data = {payload: config.payload};
					if (config.email) {
						data.email = $("input.id_mail", $container).val();
					}
					if (config.password) {
						data.password = $("input.id_password", $container).val();
					}
					if (config.feedback) {
						data.feedback = $("textarea.id_feedback", $container).val();
					}
					var res = config.onAction(buttonName, data, sender);
					if (res !== false) {
						sender.hide();
					}
				});
			})(buttonName);
		}
		
		$("a.a_close", $container).unbind("click");
		$("a.a_close", $container).click(function(){
			var data = {payload: config.payload};
			var res = config.onAction("close", data, sender);
			if (res !== false) {
				sender.hide();
			}
		});
	};
	
	var centerAlert = function() {
		var $window = $(window);
		$alert.css("top", ( $window.height() - $alert.height() ) / 2+$window.scrollTop() + "px");
		$alert.css("left", ( $window.width() - $alert.width() ) / 2+$window.scrollLeft() + "px");
	};
	
	this.setError = function(errorMessage) {
		var config = {error: errorMessage};
		setupError(config);
	};
	
	this.hide = function() {
		if ($container == null) {
        	$container = $("div.id_alert");
		}
		$container.css("display", "none");
		var $window = $(window);
		$window.unbind("resize.alertManager");
		$window.unbind("scroll.alertManager");
		
		$(document).unbind("keydown.alertManager");
	};
	
	this.show = function(config) {
		if ($container == null) {
        	$container = $("div.id_alert");
        }		
		$alert = $("div.alert", $container);
		 
		var $window = $(window);
		$window.unbind("resize.alertManager");
		$window.bind("resize.alertManager", function(){
			centerAlert();
		});
		$window.unbind("scroll.alertManager");
		$window.bind("scroll.alertManager", function(){
			centerAlert();
		});
		
		$(document).unbind("keydown.alertManager");
		$(document).bind("keydown.alertManager", function(event) {
			var keyCode = 0;
	        if (event.which != "") {
	            keyCode = event.which;
	        } else if (event.charCode != "") {
	            keyCode = event.charCode;
	        } else if (event.keyCode != "") {
	            keyCode = event.keyCode;
	        }

	        if (keyCode == 27) { // escape
	        	if ($container == null) {
	        		$container = $("div.id_alert");
	        	}
	        	$("a.a_close", $container).click();
	        } else if (keyCode == 13) { // enter
	        	if ($container == null) {
	        		$container = $("div.id_alert");
	        	}
	        	$("a.id_enter:visible", $container).click();
	        }
		});
		
		var configClone = $.extend({}, defaultConfig);
		
		// merge options
		for (var prop in config) {
			configClone[prop] = config[prop]; 
		}
		config = configClone;
 
		setupTitle(config);
		
		setupSubtitle(config);
		
		setupError(config);
		
		setupText(config);
  
		setupMail(config);
		
		setupPassword(config);
		
		setupFeedback(config);
		
		setupButtons(config);

		$container.css("display", "block");
		centerAlert();
	};
}
