
var Popup = function() {

	var defaults = {
		'width': 300,
		'height': 'auto'
	};

	var options = arguments[0] || {} ;

	for(key in defaults) {
		this[key] = (typeof options[key] != "undefined") ? options[key] : defaults[key] ;
	}

	this.popup_id = 'popup_container';
	this.popup_overlay = 'popup_overlay';

	this.open = function() {

		var html = arguments[0] || 'Empty' ;
		var that = this;

		// hide swf
		$('embed').hide();

		// overlay
		var height = $(document).height();
		var overlay = $('<div>').attr({'id': this.popup_overlay}).css({
			'width': $(window).width() + 'px',
			'height': height + 'px',
			'z-index': '1000',
			'opacity': '0.6'
		}).bind('click', function() {
			that.close();
		});

		$('body').append(overlay);
		
		// container
		var container = $('<div>').attr({'id': this.popup_id}).css({
			'z-index': '2000',
			'top': 20 + $(window).scrollTop(),
			'left': ($(document).width() / 2) - (this.width / 2),
			'width': this.width,
			'height': this.height
		});
		container.append(html);

		// close button
		var close = $('<a>').attr({'id': 'popup_close_btn', 'href': '#'}).html('Close').bind('click', function() {
			that.close();
			return false;
		});
		container.append(close);
		$('body').append(container);
	};

	this.close = function() {
		$('#' + this.popup_id).remove();
		$('#' + this.popup_overlay).remove();

		// show swf
		$('embed').show();
	};

};