function enl_Init ()
{	
	// Error messages
	var enl_Error = new Array();
	enl_Error[0] = "The target element specifyed in the 'rev' attribute couldn't be found.";

	// Creates the shade element
	$('body').prepend('<div id="enl_Shade"></div>');
	$('#enl_Shade').css('display', 			'none');
	$('#enl_Shade').css('position', 		'absolute');
	$('#enl_Shade').css('top', 				0);
	$('#enl_Shade').css('left', 			0);
	$('#enl_Shade').css('width', 			'100%');
	$('#enl_Shade').css('height', 			'100%');
	$('#enl_Shade').css('opacity', 			0);
	$('#enl_Shade').css('backgroundColor', 	'#000');
	$('#enl_Shade').css('zIndex', 			1000);
	
	// Add event litener to the shade for exit out of the enlightment.
	$('#enl_Shade').bind('click', function () {enl_End();});
	
	$('[rel=enlight]').each(
		function ()
		{
			var target = $(this).attr('rev');
			var targetParent = $(target).parent();
			var targetSize = $(target).size();
			
			if(targetSize == 1)
			{
				$(target).css('display', 'none');
				$(target).css('marginLeft', '-3000px');
				$(target).css('position', 'absolute');
				$(this).bind('click', function () {enl_Start($(this).attr('rev')); return false});
			}
			else if (targetSize < 1)
			{
				alert(enl_Error[0]);
				$(this).bind('click', function () {return false});
			}
		}
	);
}

function enl_Start (obj)
{
	var enl_windowHeight = $(window).height();
	var enl_windowWidth = $(window).width();
	var enl_documentHeight = $(document).height();
	var enl_documentWidth = $(document).width();
	var obj_Width = $(obj).width();
	var obj_Height = $(obj).height();
	var scrollTop = $(window).scrollTop();
	
	// Hides all select boxes
	if($.browser.msie && $.browser.version < 7)
	{
		$('select').css('visibility', 'hidden');
		$('select', obj).css('visibility', 'visible');
	}
	
	// Redefine the shade dimensions
	$('#enl_Shade').css('height', enl_documentHeight+'px');
	
	// Redefines the position of the enlight target element
	
	if($.browser.msie && $.browser.version < 7)
	{
		$(obj).css('position', 		'absolute');
	}
	else
	{
		$(obj).css('position', 		'fixed');
	}
	
	$(obj).css('zIndex', 		2000);
	$(obj).css('top',			'50%');
	$(obj).css('left',			'50%');
	
	if(scrollTop == 0)
	{
		$(obj).css('marginTop',		'-'+(obj_Height/2)+'px');
		$(obj).css('marginLeft',	'-'+(obj_Width/2)+'px');
	}
	else
	{
		if($.browser.msie && $.browser.version < 7)
			$(obj).css('marginTop',		scrollTop - (obj_Height/2)+'px');
		else
			$(obj).css('marginTop',		 '-'+(obj_Height/2)+'px');
			
		$(obj).css('marginLeft',	'-'+(obj_Width/2)+'px');
	}
	
	$(obj).css('opacity',		0);
	$(obj).css('display',		'block');
	$(obj).addClass('enl_Current');
	
	// Enables the shade
	$('#enl_Shade').css('display', 'block').fadeTo(500, 0.8,
		function ()
		{
			$(obj).fadeTo(300, 1);	
		}
	);
}

function enl_End ()
{
	$('.enl_Current').fadeTo(500, 0, 
		function ()
		{
			$(this).removeClass('enl_Current');
			$(this).css('display', 'none');
			$('#enl_Shade').fadeTo(300, 0, 
				function ()
				{
					$('#enl_Shade').css('display', 'none');
					$('select').css('visibility', 'visible');
				}
			);
		}
	);	
}



$(document).ready(
	function ()
	{
			enl_Init();
	}
);