function BrieFixPopup(options) {
	var pop = this;
	
	this.defaults = {
		title: '',
		message: '',
		width: '-1',
		height: 'auto',
		modal: true,
		modalColor: 'rgba(0,0,0,0.6)',
		showCloseBtn: true,
		closeOnScreenClick: true,
		closeOnEsc: true,
		divContent: '',
		clone: true,
		transition: { 'speed': 300, 'easing': 'linear' },
		zIndex: 9999,
		overflow: 'hidden',
		frame: { 'size': '10px', 'color': 'white', 'border': 'solid 1px black', radius: '0px' },
		content: { 'color': '#e1e1e1', 'border': 'none', radius: '0px' },
		frameRatio: -1, 
		mode: 'message', //string: message|dialog|screen
		buttons: [{ caption: 'OK', value: 'ok' },
			{ caption: 'Cancel', value: 'cancel' } // btn values: ok|cancel|yes|no|yestoall|notoall|abort|retry|ignore|userclose
		],
		inputs: [],
		
		// events
		onBeforeShow: function() {  },
		onShown: function() {  },
		onBeforeHide: function() {  },
		onHide: function() {  },
		onBtnClick: function() {  }
	}
	
	this.initButtons = function(buttons) {
		for (i=pop.buttons.length-1; i>=0; i--) pop.buttons[i].element.remove();
		pop.buttons.length = 0;
		
		//if (typeof(buttons) != 'Array') buttons = new Array();
		if (buttons.length == 0) buttons.push({ caption: 'OK', value: 'ok' });
		for (i=0; i<buttons.length; i++) {
			var new_btn = new Object();
			new_btn = {
				caption: buttons[i].caption,
				value: buttons[i].value,
				onclick: buttons[i].onclick
			}
			if ((new_btn.value == null) || (typeof(new_btn.value) == 'undefined')) new_btn.value = 'cancel';
			if ((new_btn.onclick == null) || (typeof(new_btn.onclick) !== 'function')) new_btn.onclick = function() {  };
			new_btn.element = $('<div />', { 'class': 'bfx-popup-button green-button' }).text(new_btn.caption);
			if ( (new_btn.value == 'cancel') || (new_btn.value == 'no') || (new_btn.value == 'notoall') || (new_btn.value == 'abort') || (new_btn.value == 'ignore') )
				new_btn.element.addClass('red-button');
			pop.btn_container.append(new_btn.element);
			pop.buttons.push(new_btn);
			new_btn.element.bind('click.bfxpopup', function (event) {
				pop.onButtonClick($(event.target));
			});
		}
	}
	
	this.initInputs = function(inputs) {
		for (i=pop.inputs.length-1; i>=0; i--) pop.inputs[i].container.remove();
		pop.inputs.length = 0;
		
		if (inputs.length == 0) return ;
		for (i=0; i<inputs.length; i++) {
			var new_input = new Object();
			new_input = {
				caption: inputs[i].caption,
				value: inputs[i].value,
				type: inputs[i].type,
				placeholder: inputs[i].placeholder,
				required: inputs[i].required,
				regex: inputs[i].regex
			}
			new_input.container = $('<div />', { 'class': 'bfx-popup-input-container' });
			new_input.label = $('<div />', { 'class': 'bfx-popup-input-label' }).html(new_input.caption);
			if (inputs[i].type == 'textarea') new_input.element = $('<textarea />', { 'class': 'bfx-popup-input', 'placeholder': new_input.placeholder }).val(new_input.value);
			else new_input.element = $('<input />', { 'type': 'text', 'class': 'bfx-popup-input', 'placeholder': new_input.placeholder }).val(new_input.value);
			new_input.container.append(new_input.label).append(new_input.element);
			pop.input_container.append(new_input.container);
			pop.inputs.push(new_input);
		}
	}
	
	this.initMessage = function() {
		//pop.frame.css({ 'min-width': '25%' });
		pop.frame.css({ 'max-width': '70%', 'min-width': '25%' });
		pop.content.css({ 'width': 'auto', 'height': 'auto' });
		pop.initButtons([{ caption: 'OK', value: 'ok' }]);
		pop.content.append(pop.title.show());
		pop.content.append(pop.message.show());
		pop.content.append(pop.btn_container.show());
		pop.input_container.detach();
	}
	
	this.initDialog = function() {
		//pop.frame.css({ 'max-width': '70%', 'min-width': '25%' });
		pop.frame.css({'min-width': '25%' });
		pop.content.css({ 'width': pop.defaults.width, 'height': 'auto' });
		pop.initButtons(pop.defaults.buttons);
		pop.initInputs(pop.defaults.inputs);
		pop.content.append(pop.title.show());
		pop.content.append(pop.message.show());
		pop.content.append(pop.input_container.show());
		pop.content.append(pop.btn_container.show());
	}
	
	this.initScreen = function() {
		pop.content.css({ 'width': pop.defaults.width, 'height': pop.defaults.height });
		pop.initButtons(pop.defaults.buttons);
		pop.initInputs(pop.defaults.inputs);
		pop.content.append(pop.title.hide());
		pop.content.append(pop.message.hide());
		pop.content.append(pop.input_container.hide());
		pop.content.append(pop.btn_container.hide());
		if (pop.defaults.clone) pop.content.css({ 'overflow': pop.defaults.overflow}).append($(pop.defaults.divContent).clone().show());
		else pop.content.css({ 'overflow': pop.defaults.overflow}).append($(pop.defaults.divContent).show());
	}
	
	this.reposition = function() {
		var left = Math.floor(($(window).width() - pop.frame.outerWidth()) / 2);
		var top = Math.floor(($(window).height() - pop.frame.outerHeight()) / 2);
		if (left < 0) left = 0;
		if (top < 0) top = 0;
		pop.frame.css({ 'left': left+'px', 'top': top+'px' });
		pop.smoke.css({ 'width': $(document).width()+'px', 'height': $(document).height()+'px' });
	}
	
	this.show = function () {
		if (pop.defaults.mode == 'message') pop.defaults.showCloseBtn = false;
		pop.reset(pop.defaults);
		pop.smoke.css({ 'width': $(document).width()+'px', 'height': $(document).height()+'px' }).fadeIn(pop.defaults.transition.speed);
		if (pop.defaults.message == '') pop.message.hide();
		if (pop.defaults.title == '') pop.title.hide();
		pop.reposition();
		pop.btnClose.hide();
		pop.frame.show().css({ 'opacity': 0 }).animate({ 'opacity': 1 }, { 'duration': pop.defaults.transition.speed, 'easing': pop.defaults.transition.easing, 'complete': function () {
			if (pop.defaults.showCloseBtn) pop.btnClose.fadeIn(pop.defaults.transition.speed); 
		}});
		pop.content.css({ width: pop.content.width()+'px' });
		
		$(window).bind('resize.bfxpopup', pop.reposition).bind('keyup.bfxpopup', function (event) {
			if ((event.which == 27) && (pop.defaults.closeOnEsc)) {
				pop.onUserClose();
			} else if ((event.which == 13) && (pop.defaults.mode != 'screen')) {
				for (i=0; i<pop.inputs.length; i++)
					if ((pop.buttons[i].value == 'ok') || (pop.buttons[i].value == 'yes') || (pop.buttons[i].value == 'yestoall') || (pop.buttons[i].value == 'retry')) {
						pop.buttons[i].element.click();
						return;
					}
				pop.buttons[0].element.click();
			}
		});
		
		return pop;
	}
	
	this.hide = function() {
		if (!pop.frame.is(':visible')) return false;
		pop.defaults.onBeforeHide();
		$(window).unbind('resize.bfxpopup').unbind('keyup.bfxpopup');
		pop.frame.fadeOut(pop.defaults.transition.speed, function () { pop.defaults.onHide(pop) });
		pop.smoke.fadeOut(pop.defaults.transition.speed);
		
		return pop;
	}
	
	this.onButtonClick = function (clicked) {
		var btn = null;
		for (x=0;x<pop.buttons.length;x++)
			if (pop.buttons[x].element[0] == clicked[0]) btn = pop.buttons[x];
		if (btn == null) return ;
		
		var stop = false;
		if ((btn.value == 'ok' || btn.value == 'yes' || btn.value == 'yestoall' || btn.value == 'retry')) {
			for (i=0; i<pop.inputs.length; i++) {
				if (pop.inputs[i].required === true) {
					if (pop.inputs[i].element.val().match(pop.inputs[i].regex) == null) {
						stop = true;
						pop.inputs[i].element.effect('highlight', { }, 1000);
					}
				}
			}
			if (stop === true) return ;
		}
		
		pop.hide();
		if (typeof(this.defaults.onBtnClick) == 'function') 
			this.defaults.onBtnClick(btn.value, pop.inputs);
		
	}
	
	this.onUserClose = function () {
		pop.hide();
		if (typeof(this.defaults.onBtnClick) == 'function') 
			this.defaults.onBtnClick('userclose', pop.inputs);
	}
	
	this.reset = function (new_options) {
		return ;
		$.extend(pop.defaults, new_options);
		pop.title.html(pop.defaults.title);
		pop.message.html(pop.defaults.message);
	
		pop.smoke.addClass('bfx-popup-screen').hide();
	}
	
	$.extend(this.defaults, options); 
	//if (this.defaults.content.radius == 'auto') this.defaults.content.radius = this.defaults.frame.radius;
	
	this.buttons = new Array();
	this.inputs = new Array();
	this.title = $('<div />', { 'class': 'bfx-popup-title' }).html(this.defaults.title).hide();
	this.message = $('<div />', { 'class': 'bfx-popup-message' }).html(this.defaults.message).hide();
	this.btn_container = $('<div />', { 'class': 'bfx-popup-buttons' }).css({ "text-align": "center" }).hide();
	this.input_container = $('<div />', { 'class': 'bfx-popup-inputs' }).hide();
	
	this.smoke = $('<div />', { 'class': 'bfx-popup-screen', 'style': 'background: '+this.defaults.modalColor }).css({ 'z-index': this.defaults.zIndex }).hide().bind('click.bfxpopup', function (event) {
		if (($(event.target).hasClass('bfx-popup-screen')) && (pop.defaults.closeOnScreenClick == true)) pop.onUserClose();
	});
	this.frame = $('<div />', { 'class': 'bfx-popup-frame' }).hide();
	this.content = $('<div />', { 'class': 'bfx-popup-content' })
	
	this.frame.append(this.content);
	this.smoke.append(this.frame);
	this.btnClose = $('<div />', { 'class': 'bfx-popup-close' }).bind('click.bfxpopup',function () { pop.onUserClose() }).hide();
	this.frame.append(this.btnClose);
	$('body').append(this.smoke);
	if (this.defaults.mode == 'dialog') this.initDialog();
	else if (this.defaults.mode == 'screen') this.initScreen();
	else this.initMessage();
	
	return this;
}
