// ------------------------- //
function loadOverlay(theContent){
	
if($.browser.msie){
	var bversion = parseInt($.browser.version, 10)
	if(bversion <= 8){
	
		$('body').append('<div id="overlay"></div>');
		$('#overlay').css({
				'height':'100%'
				,'width':'100%'
				,'filter':'alpha(opacity=0)'
				,'position':'absolute'
				,'top':'0px'
				,'left':'0px'
				,'z-index':'1000'
				}).animate({
					'filter':'alpha(opacity=80)'
					},0 ).css({
						'height': $(document).height()
						});
	
		$('body').append('<div id="overlayContent"></div>');
		$('#overlayContent').css({
					'position':'fixed'
					,'z-index':'1001'
					,'filter':'alpha(opacity=80)'	
					}).html(theContent);
		$('#overlayContent').addClass('clearfix');
	
		setOverlayCloseTrigger('#overlay');

	} else {
	
		$('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');
	
	}

} else {
	$('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');

}
}


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


jQuery.fn.loadOverlayContentMSIE = 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({
		'filter':'alpha(opacity=100)'
		,'width':overlayContentWidth
		,'height':overlayContentHeight
		,'top':expandPositionHeight+'px'
		,'left':expandPositionWidth+'px'
		}
		,speed
		,easing
		,function(){
			
	}); // end #overlayContent.animate
}// end function loadOverlayContent



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()});
			});
	}// end removeOverlay
	
function setOverlayCloseTrigger(theElement){
	$(theElement).addClass('closeTriggerCursor');
	$(theElement).click(function(){
		removeOverlay();
	});
	}// end setOverlayCloseTrigger

function removeOverlayCloseTrigger(theElement){
		$(theElement).removeClass('closeTriggerCursor');
		$(theElement).unbind('click');
	}//end removeOverlayCloseTrigger
