(function($) {
	
	$.fn.center = function (data) {
	if(typeof data.x_offset == "undefined"){data.x_offset=0;}
	//data.x_offset outerwidth doesn't grab close icon size
    this.css("position","absolute");
    this.css("top", ( $(window).height() - (this.outerHeight()-data.x_offset) ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.outerWidth() ) / 2+$(window).scrollLeft() + "px");
    return this;
}

	$.jwindow = function(){

	}
	
	$.jwindow.popup = function(p){
	  if(typeof p == "undefined"){p = {};}
	
	  if(typeof p.content_type == "undefined"){p.content_type="iframe";}
	  if(typeof p.popWidth == "undefined"){p.popWidth=480;}
	  if(typeof p.popHeight == "undefined"){p.popHeight=480;}
	  if(typeof p.content == "undefined"){p.content="";}
		tbl = "<div id=\"imgpop\" class=\"popup_block\"></div>";
		$(document.body).append(tbl);
   		$("div#imgpop").fadeIn().css({ 'height': Number(p.popHeight), 'width': Number( p.popWidth ) }).prepend('<a href="#" class="btn_close"></a>');
	    $('body').append('<div id="fade"></div>');
	    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
		$("div#imgpop").center({x_offset:30});
	//	$("div#imgpop").bgiframe();
		$("div#imgpop").append("<div id=\"content\"><strong>LOADING</strong></div>");
		
		if(p.content_type == "iframe"){
			var iframesrc = '<iframe src="' + p.page_url + '"';
			iframesrc += ' id="content_iframe"';
			iframesrc += ' frameborder="0"';
			iframesrc += ' width="500"';
			iframesrc += ' height="500"';
			iframesrc += ' scrolling="no" />';
			$("div#imgpop div#content").html(iframesrc);
		}
		else{
			$("div#imgpop div#content").html(p.content);
		}
		////
	}
	
	$('a.btn_close, #fade').live('click', function() {
		$('#fade , .popup_block').fadeOut(function() {
			$('#fade, a.btn_close').remove();
			$("div#imgpop").empty().remove();
	});//end fadeout
});//end live click

})(jQuery);

