$.fn.jModalFrame=function(closeText){
	var target = (typeof($(this).attr('href')) == "undefined" || $(this).attr('href') == '') ? $(this).data('html') : $(this).attr('href');
	var mWidth = $(this).attr('width');
	var mHeight = $(this).attr('height');
	var scroll = ($(this).attr('scroll') === 'false') ? false : true;
	var half = 0-(mWidth/2);
	var scrolled = Number($(window).scrollTop()+35);
		
	
	if(typeof closeText == "string"){
		closeText = closeText;
		fadeInTime = 800;
	}
	else if(typeof closeText == "number"){
		fadeInTime = closeText;
		closeText = '<div class="modal_closebox" style="position:absolute;top:6px;right:20px;cursor:pointer;color:white;background-color:black;">Close</div>';
	}
	else{
		closeText = '<div class="modal_closebox" style="position:absolute;top:6px;right:20px;cursor:pointer;color:white;background-color:black;">Close</div>';
		fadeInTime = 800;
	}
	
	$.fn.modalShow=function(scroll){
		$('body').append('<div class="modal_veil"></div><div class="modal"></div>');
		
		if (typeof($(this).attr('href')) != "undefined" && $(this).attr('href') !== '') {
			
			var cssStyle = {
				'width':mWidth+'px',
				'height':mHeight+'px',
				'display':'none',
				'position':'absolute',
				'top':scrolled+'px',
				'left':'50%',
				'margin-left':half+'px',
				'border':'1px solid black',
				'z-index':'1000',
				'background-color':'white',
				'padding':'0px',
				'overflow':'hidden'
			}		
	
			
			$('.modal').css(cssStyle).fadeIn(800);
			
			if (scroll === false) {
				var iFrame = '<iframe width="'+mWidth+'px" height="'+mHeight+'px" frameborder="0" src="' + target + '" id="frame" scrolling="no" style="margin:0px;padding:0px;position:absolute;top:0px;left:0px;"></iframe>';
			}
			else {
				var iFrame = '<iframe width="'+mWidth+'px" height="'+mHeight+'px" frameborder="0" src="' + target + '" id="frame" scrolling="auto" style="margin:0px;padding:0px;position:absolute;top:0px;left:0px;"></iframe>';
			}
		}else{
			
			var cssStyle = {
				'width':mWidth+'px',
				'height':mHeight+'px',
				'display':'none',
				'position':'absolute',
				'top':scrolled+'px',
				'left':'50%',
				'margin-left':half+'px',
				'border':'1px solid black',
				'z-index':'1000',
				'background-color':'white',
				'overflow':'auto',
				'padding':'0px'
			}		
	
			
			$('.modal').css(cssStyle).fadeIn(800);
			
			var iFrame =  target;
		}
		
		var closeBox = closeText;
		$('.modal').html(iFrame+closeBox);
		
		
		if($(window).width() > $(document).width()){
			var wWidth = $(window).width();
		}else{
			var wWidth = $(document).width();
		}
		
		if($(window).height() > $(document).height()){
			var wHeight = $(window).height();
		}else{
			var wHeight = $(document).height();
		}
		
		var veilStyle={
			'position':'absolute',
			'top':'0px',
			'left':'0px',
			'width':wWidth,
			'height':wHeight,
			'background-color':'black',
			'opacity':'.1',
			'z-index':'995',
			'filter':'alpha(opacity=10)'
		}
		
		$('.modal_veil').css(veilStyle).fadeTo(fadeInTime, 0.7);
		
		var escClose = $(this);
	
		$(document).bind('keydown',function(e){
			var theKey = (e.which) ? e.which: e.keyCode;
			if(theKey == 27){
				$(escClose).modalHide();
			}
		});
		
	};
	
	$.fn.modalHide=function(){
		$('.modal,.veil').fadeOut(500,function()
			{
				$('.modal,.modal_veil').remove();
			});
	};
	
	if ($('.modal').length == 0){
		$(this).modalShow(scroll);
	}
	
	$('.modal_closebox').click(function(){
		$(this).modalHide();
		
		$(document).unbind('keydown');
	});
	
};
