	DanfossPopup = function (el, config) {
		if (el) {
			this.init(el, config);
		} else {
		}
	}
	var Popup = DanfossPopup;
	
	Popup.prototype = {
		constructor: Popup,
		element: null,
		header: null,
		body: null,
		footer: null,
		id: null,
		config: {},
		visible: false,
		isIE6: false,
		
		init: function (el, userConfig) {
			var elId;
			this.element = el;
			
			if (el.id) {
                this.id = el.id;
            }
			
			this.createHeader();
			this.createBody();
			this.createFooter();
			
			this.initConfig(userConfig);
			
			this.setCentered(this);
			
			if ('width' in this.config) {
				$(el).width(this.config.width);
			}
			if ('height' in this.config) {
				$(this.body).height(parseInt(this.config.height - $(this.head).height() - $(this.foot).height()) - parseInt($(this.body).css('paddingTop')));
			}
			
			if (this.config.visible === false) {
				this.hide();
			} else {
				this.show();
			}
			
			if ($.browser.msie && parseInt($.browser.version) == 6) {
				this.isIE6 = true;
			}
			
			/*if ($(el).children('#close-button')) {
				closeButton = $(el).children('#close-button')[0];
				$(closeButton).click(this.hide);
			}*/			
		},
		
		initConfig: function (userConfig) {
			this.config = {
				visible: true,
				centered: false,
				modal: false
			};
			if (typeof(userConfig) == "object") {
				for (param in userConfig) {
					this.config[param] = userConfig[param];
				}
			}
		},
		
		createHeader: function () {
			if ($(this.element).children(".middle-box-head").length == 0) {
				var template = '<div class="middle-box-head">' +
									'<div class="middle-box-head-left"></div>' +
									'<span></span>' +
									'<div class="middle-box-head-right"></div>' +
								'</div>';
				$(this.element).prepend(template);
			}
			this.head = $(this.element).children(".middle-box-head")[0];
		},
		
		createBody: function () {
			if ($(this.element).children(".middle-box-body").length == 0) {
				var template = '<div class="middle-box-body">' +
								'</div>';
				if ($(this.element).children(".middle-box-head").length != 0) {
					$(this.element).children(".middle-box-head").after(template);
				} else {
					$(this.element).prepend(template);
				}
			}
			this.body = $(this.element).children(".middle-box-body")[0];
		},
		
		createFooter: function () {
			if ($(this.element).children(".middle-box-foot").length == 0) {
				var template = '<div class="middle-box-foot">' +
									'<div class="middle-box-foot-left"></div>' +
									'<span></span>' +
									'<div class="middle-box-foot-right"></div>' +
								'</div>';
				$(this.element).append(template);
			}
			this.foot = $(this.element).children(".middle-box-foot")[0];
		},
		
		setHeader: function (headerContent) {
			if (this.head) {
				$(this.head).children("span").html(headerContent);
			}
		},
		
		setBody: function (bodyContent) {
			if (bodyContent.nodeName) {
                $(this.body).html("");
                $(this.body).append(bodyContent);
            } else {
                $(this.body).html(bodyContent);
            }
		},
		
		setFooter: function (footerContent) {
			if (this.foot) {
				$(this.foot).children("span").html(footerContent);
			}
		},
		
		setCentered: function (popup) {
			if (popup.config.centered === true && popup.visible === true) {
				var doc_h = parseInt($(window).height());
				var doc_w = parseInt($(window).width());
				var top = parseInt((doc_h - parseInt($(popup.element).height()))/2) + parseInt($(window).scrollTop());
				var left = parseInt((doc_w - parseInt($(popup.element).width()))/2) + parseInt($(window).scrollLeft());
				$(popup.element).css('top', top);
				$(popup.element).css('left', left);
			}
		},
		
		show: function () {
			this.visible = true;
			this.setCentered(this);
			this.showMask();
			if (this.isIE6) {
				$('select').css('visibility', 'hidden');
			}
			$(this.element).show();
		},
		
		hide: function () {
			this.visible = false;
			$(this.element).hide();
			this.hideMask();
			if (this.isIE6) {
				$('select').css('visibility', 'visible');
			}
		},
		
		showMask: function () {
			if ('modal' in this.config && this.config.modal === true) {
				doc_h = $(document).height();
				if ($("body").children("#shadow_div").length == 0) {
					$(this.element).before('<div id="shadow_div"></div>');
				}
				if (this.isIE6) {
					$('#shadow_div').width($(document).width()-20);
				}
				$('#shadow_div').css('opacity', "0.5").height(parseInt(doc_h)).show();
			}
		},
		
		hideMask: function () {
			$('#shadow_div').hide();
		}
	}