function Popup(options){
	var frameTemplate = '<iframe src="[#=opt.frame#]" class="myiframe" frameborder="0" style="border:0;" width="100%" height="100%"></iframe>',
	template = '<div class="mask"></div>'+
	'<div class="popup" style="z-index: [#=opt.zIndex#]; ">'+
		'<div class="title">'+
			'<strong>[#=opt.title#]</strong>'+
			'<span class="close-tag"></span>'+
			'<span class="restore-tag"></span>'+
			'<span class="max-tag"></span>'+
		'</div>'+
		'<div class="popup-content">'+
			'[#=opt.html#]'+
		'</div>'+
	'</div>';
	this.opt = $.extend({
		masker: true,
		width:'54%',
		height:'50%',
		title:'',
		zIndex: 110,
		forceRemove:false
	},options);
	if (this.opt.frame) {
		this.opt.html = RenderTemplate(frameTemplate,this.opt,'opt');
	}
	var html;
	if (!this.opt.html.constructor || this.opt.html.constructor != String) {
		html = this.opt.html;
		this.opt.html = '';
	};
	var ele = $(RenderTemplate(template,this.opt,'opt')).appendTo(document.body);
	if (html) {
		ele.find('.popup-content').append(html);
	};
	this.mask = $(ele[0]);
	this.popup = $(ele[1]);
	this.content = this.popup.find('.popup-content');
	this.iframe = this.content.find('iframe');
	this.close = this.popup.find('.close-tag');
	this.max = this.popup.find('.max-tag');
	this.restore = this.popup.find('.restore-tag');
	var reposition = function (skipResizeEvent){
		if (this.opt.width.toString().indexOf('%') == -1) {
			if (!this.maximized) {
				this.popup.css({
					width:this.opt.width,
					left:($(window).width() - Int(this.opt.width))/2 + 'px'
				});
			}
			if (skipResizeEvent) {
				$(window).trigger('resize');
			}else{
				$(window).resize(function(){
					if (!this.maximized) {
						this.popup.css({
							left:($(window).width() - Int(this.popup.width()))/2 + 'px'
						});
					}else{
						this.popup.css({width:'100%'});
					}
				}.bind(this));
			}
		}else{
			if (!this.maximized) {
				this.popup.css({
					width:this.opt.width,
					left:(100 - Int(this.opt.width))/2 + '%'
				});
			};
		}
		if (this.opt.height.toString().indexOf('%') == -1) {
			if (!this.maximized) {
				this.popup.css({
					height:this.opt.height,
					top:($(window).height() - Int(this.opt.height))/3 + 'px'
				});
			};
			if (skipResizeEvent) {
				$(window).trigger('resize');
			}else{
				$(window).resize(function(){
					if (!this.maximized) {
						this.popup.css({
							top:($(window).height() - Int(this.opt.height))/3 + 'px'
						});
					}else{
						this.popup.css({
							height:$(window).height() + 'px'
						});
					}
				}.bind(this));
			}
		}else{
			if (!this.maximized) {
				this.popup.css({
					height:this.opt.height,
					top:(100 - Int(this.opt.height))/3 + '%'
				});
			};
		}
	}.bind(this);
	reposition();
	this.mask.show();
	this.popup.show();
	$(this.content).add(this.iframe).css({
		height:this.popup.height() -
				this.popup.find('.title:first').height() -
				Int(this.popup.find('.title:first').css('paddingTop')) -
				Int(this.popup.find('.title:first').css('paddingBottom')) -
				Int(this.popup.css('paddingTop')) -
				Int(this.popup.css('paddingBottom')) +
				'px'
	});
	$(window).resize(function(){
		$(this.content).add(this.iframe).css({
			height:this.popup.height() -
					this.popup.find('.title:first').height() -
					Int(this.popup.find('.title:first').css('paddingTop')) -
					Int(this.popup.find('.title:first').css('paddingBottom')) -
					Int(this.popup.css('paddingTop')) -
					Int(this.popup.css('paddingBottom')) +
					'px'
		});

	}.bind(this));

	this.close.click(function(){
		this.hide();
		if ($.isFunction(this.opt.onClose)) {
			this.opt.onClose();
		};
	}.bind(this));
	if (this.opt.maximizable) {
		this.max.click(function(){
			this.popup.css({
				top:'0px',
				left:0
			});
			this.maximized = true;
			$(document.body).css({
				overflow:'hidden'
			});
			reposition(true);
			$(document.body).hide();
			setTimeout(function(){$(document.body).show();},1)
			$(document).trigger('popup-maximized');
		}.bind(this));
		this.restore.click(function(){
			this.popup.css({
				width:this.opt.width,
				height:this.opt.height
			});
			this.maximized = false;
			$(document.body).css({overflow:'auto'});
			reposition(true);
			$(document).trigger('popup_restored');
		}.bind(this));
	}else{
		this.max.hide();
		this.restore.hide();
	}
	this.hide = function(){
		if (this.opt.forceRemove) {
			this.popup.empty().remove();
			this.mask.empty().remove();
		}else{
			this.popup.hide();
			this.mask.hide();
		}
		$(document.body).css({overflow:'auto'});
	};
	this.show = function(){
		this.popup.show();
		this.mask.show();
	}
	this.remove = function(){
		this.popup.remove();
		this.mask.remove();
	}
}