$(function(){
	jQuery.fn.popupW = function( options ){
		options = jQuery.extend({
			width: '500px',
			height: '300px',
			color: '#F8EFD0',
			content: 'no-content'
		}, options);
	
		return this.each(function(){
			e = $( this );
			
			var html2 = '';
			html2 += '<div id="popupModal">';
			html2 += '</div>';
			e.append( html2 );

			e.find('#popupModal').css({
				background:options.color,
				position:'fixed',
				top:'0px',
				left:'0px',
				width: $( window ).width(),
				height: $( window ).height(),
				opacity: 0,
				zIndex:1000
			});
			e.find('#popupModal').bind('click', function(){
				$('body').popupWClose();
			});
			e.find('#popupModal').animate({
				opacity: 0.5
			},700);
			e.find('#popupModal');
			$(window).bind('resize', function(){
				$('body').find('#popupModal').css({
					width: $(window).width(),
					height: $(window).height()
				});
			});
			
			var html = '';
			html += '<div id="popup">';
			html += options.content;
			html += '</div>';
			e.append( html );
			
			e.find('#popup').css({
// 				'border-radius':'10px',
// 				'-moz-border-radius':'10px',
// 				'-webkit-border-radius':'10px',
// 				background:'#F8EFD0',
				width: options.width,
				height:options.height,
				position:'absolute',
// 				border:'1px solid #E2ECEF',
				top:'0px',
				left:'0px',
				'box-shadow':'0px 0px 17px #1A3457',
				'-webkit-box-shadow':'0px 0px 17px #676767',
				'-moz-box-shadow':'0px 0px 17px #1A3457',
				opacity:0,
				zIndex:1000
			});
			e.find('#popup').animate({
				opacity:1
			},100).center();
		});
	}
	jQuery.fn.center = function(){
		this.each(function(){
			e = $( this );
			function getBodyScrollTop(){
			  return self.pageYOffset || 
			    (document.documentElement && document.documentElement.scrollTop) || 
			    (document.body && document.body.scrollTop);
			}
			var sTop = getBodyScrollTop();
			function center(){
				if( (($(window).height() - e.height()) / 2 + sTop ) < 0 ) var top = 20;
				else top = ($(window).height() - e.height()) / 2 + sTop;
				e.css({
					left: ($(window).width() - e.width()) / 2,
					top: top
				});
			}
			$(e).bind('resize', center);
			$(window).bind('resize', center);
			center();
		});
	}
	jQuery.fn.popupWClose = function(){
		$('#popup').remove();
		$('#popupModal').remove();
		return this;
	}
});
