// ------------------------- //
function loadOverlay(theContent){
	$('body').css('overflow','hidden');
	
	$('body').append('<div id="overlay"></div>');
	$('#overlay').css({
			'height':'100%'
			,'width':'100%'
			,'opacity':'0'
			,'filter':'alpha(opacity=0)'
			,'position':'absolute'
			,'top':'0px'
			,'left':'0px'
			,'z-index':'1000'
			}).animate({
				'opacity':'0.8'
				,'filter':'alpha(opacity=80)'
				},600 ).css({
					'height': $(document).height()
					});// end #overlay.animate;

	$('body').append('<div id="overlayContent"></div>');
	$('#overlayContent').css({
				'position':'fixed'
				,'z-index':'1001'
				,'opacity':'0.0'
				,'filter':'alpha(opacity=0)'
				}).html(theContent);
	$('#overlayContent').addClass('clearfix');

	setOverlayCloseTrigger('#overlay');
	} //end function.loadOverlay

jQuery.fn.loadOverlayContent = function ( sourceHeight, sourceWidth, speed, easing ){
		$(this).css({'width':'auto','height':'auto'});
		var overlayContentHeight = $(this).height();
		var overlayContentWidth = $(this).width();
		
		var perimeterHeight = $(this).heightOfPerimeter();
		var perimeterWidth = $(this).widthOfPerimeter();
		
		var windowCenterHeight = $().getWindowCenterHeight();
		var windowCenterWidth = $().getWindowCenterWidth();
	
		var expandPositionHeight = (windowCenterHeight - ( overlayContentHeight  / 2 ) - perimeterHeight ) ;
		var expandPositionWidth = ( windowCenterWidth - ( overlayContentWidth / 2 ) - perimeterWidth ) ;
		
		$(this).css({
			'height': sourceHeight + 'px'
			,'width': sourceWidth + 'px'
			,'top': ( windowCenterHeight - ( sourceHeight / 2 ) )+'px'
			,'left': (windowCenterWidth - ( sourceWidth / 2 ) )+'px'
			});
		$(this).animate({
				'opacity':'1'
			,'filter':'alpha(opacity=100)'
			,'width':overlayContentWidth
			,'height':overlayContentHeight
			,'top':expandPositionHeight+'px'
			,'left':expandPositionWidth+'px'
			}
			,speed
			,easing
			,function(){
				$('#overlayContentWrapper').animate({
									'opacity':'1'
									,'filter':'alpha(opacity=100)'
									});
		}); // end #overlayContent.animate
	}// end function loadOverlayContent
	
function setOverlayCloseTrigger(theElement){
	$(theElement).addClass('closeTriggerCursor');
	$(theElement).click(function(){
		removeOverlay();
	});
	}// end setOverlayCloseTrigger
	
function removeOverlay(){
	$('#overlayContentWrapper').animate({'opacity':'0','filter':'alpha(opacity=0)'},400);
	$('#overlayContent').animate({'opacity':'0.0','filter':'alpha(opacity=0)'}, 400, 
		function(){
			$('#overlayContent').remove();
			$('#overlay').animate({'opacity':'0.0','filter':'alpha(opacity=0)'}, 300,function(){$('#overlay').remove()});
			$('body').css('overflow','auto');
			});
	}// end removeOverlay

