
var Popup = function(id) {

	var win_id = id, that = this, onclose = null, handle = null;

	this.onclose = function(f) {
		onclose = f;
	};

	this.closehandle = function(e) {
		e.bind('click', that.close);
	};

	this.open = function(html) {

		var size = {
			width: $(window).width(),
			height: $(document).height()
		};

		var overlay = $('<div>').css({
			'background': '#000',
			'position': 'absolute',
			'top': 0,
			'left': 0,
			'width': size.width,
			'height': size.height,
			'opacity': 0.6,
			'z-index': 1000
		}).attr({
			'id': win_id + '_overlay'
		}).bind('click', that.close);

		var win_size = arguments[1] || {width: 600, height: 400};
		var left = (size.width / 2) - (win_size.width / 2);

		var win = $('<div>').css({
			'background': '#fff',
			'position': 'absolute',
			'top': 50,
			'left': left,
			'width': win_size.width,
			'height': win_size.height,
			'z-index': 1001,
			'overflow': 'hidden'
		}).attr({
			'id': win_id + '_win'
		}).html(html);

		$('body').append(overlay).append(win);
	};

	this.close = function() {
		$('#' + win_id + '_overlay').remove();
		$('#' + win_id + '_win').remove();
		if(typeof onclose == 'function') {
			onclose();
		}
		return false;
	};
};


