(function($) {
	$.SMPopup = function() {
		$(document).ready(function(){
			$(document.body).prepend('<div id="SMPopup" style="position: absolute; z-index: 1000;"></div>');
			$('#SMPopup').append('<div id="SMPopupWindow" style="position: absolute; background-color: white; z-index: 1001;"></div>');
			$('#SMPopup').append('<div id="SMPopupBackground" style="width: 100%; height: 100%; background-color: #black;"></div>');
			$('#SMPopupWindow').append('<div id="SMPopupContent"></div>');
			$('#SMPopupWindow').append('<a id="SMPopupButton" href="#" style="position: absolute; display: block;">x</a>');
			$('#SMPopup').css('left',0);
			$('#SMPopup').css('top',0);
			$('#SMPopup').width($(window.parent).width());
			$('#SMPopup').height($(window.parent).height());
			$('#SMPopupWindow').width(400);
			$('#SMPopupWindow').height(400);
			$('#SMPopupButton').css('right',5);
			$('#SMPopupButton').css('top',0);
			$('#SMPopupButton, #SMPopupBackground').click(function(event){
				event.preventDefault();
				$.SMPopup.close();
			});
			$('#SMPopupBackground').css('opacity', .8);
			$('#SMPopup').hide();
			//$.SMPopup.open('contact_form.php');
			$('[rel=SMPopup]').each(function(){
				$(this).click(function(event){
					event.preventDefault();
					$.SMPopup.open($(this).attr('href'));
				});
			});
			$(window).scroll(function(){
				//$.SMPopup.position();
			});
		});
	}
	$.SMPopup.position = function() {
		
		$('#SMPopup').css('left',$(window.parent).scrollLeft());
		$('#SMPopup').css('top',$(window.parent).scrollTop());
		$('#SMPopup').width($(window.parent).width());
		$('#SMPopup').height($(window.parent).height());
		$('#SMPopupWindow').css('left',($(window.parent).width()-400)/2);
		$('#SMPopupWindow').css('top',($(window.parent).height()-400)/2);
	}
	$.SMPopup.open = function(path) {
		$.SMPopup.position();
		$('#SMPopupContent').html('<iframe src="'+path+'" style="width: 100%; height: 100%; border: none;" />');
		
		$('#SMPopup').fadeIn(250);
	}
	$.SMPopup.close = function() {
		$('#SMPopup').fadeOut(250);
	}
})(jQuery);
