/* JavaScript Document
	@Description: Over Lightobx javascript.
	@Auteur: Neov.
	@Creation: 10/07/2008.
*/

(function($) {
	$.fn.oLightBoxMainFrame = function (settings) {
		settings = jQuery.extend({
			poptop	: 100,
			overlay : true,
			template: 'template_1',
			callClose : null								 	
		},settings);
		
		var $popupContent = $(this);
		var contenTop = settings.poptop;
		
		var template_1 = '<div id="lightbox-overlay-mainframe"></div>'
						+ 	'<div id="lightbox-outter-mainframe">'
						+ 		'<div id="lightbox-inner-mainframe">'
						+			'<div class="lightbox-close"></div>'						
						+		'</div>'
						+	'</div>';
		
		var template_2 = '<div id="lightbox-overlay-mainframe"></div>'
						+ 	'<div id="lightbox-outter-mainframe">'
						+ 		'<div id="lightbox-inner-mainframe">'
						+			'<div class="lightbox-close orange"></div>'						
						+		'</div>'
						+	'</div>';
		
		var template = eval(settings.template);		   
    
		function _showOverlay () 
		{
			
			var bodyWitdh = $('body').width();
			var bodyHeight = $(window).height();

			$('#lightbox-overlay-mainframe').css({width: bodyWitdh + 'px', height: bodyHeight +'px', opacity: 0.2, filter:'Alpha(Opacity=20)'});

		}
		
		function _showLightBox () 
		{
			
			// Hime some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
			$('select').css ({ 'visibility' : 'hidden' }) ;
			$('body').append (template) ;

			if (settings.overlay) 
			{
				_showOverlay () ;
			}

			var contentWidth = $popupContent.innerWidth () ;
			var contentHeight = $popupContent.innerHeight () ;

			$popupContent
				.appendTo('#lightbox-inner-mainframe')
				//.css ({ position:'static', top:'auto', left:'auto' });
				.removeClass('popup');

			$('#lightbox-inner-mainframe').css ({ width: contentWidth + 'px', height: contentHeight + 'px'  }) ;
			$('#lightbox-outter-mainframe').css({ top: contenTop + 'px' }) ;

			$('#lightbox-inner-mainframe .lightbox-close').click ( function () {
				_closeLightBox () ;
				if (settings.callClose) settings.callClose.call (this) ;
			}) ;
			
		}
		
		$popupContent[0]._closeLightBox = _closeLightBox;
				
		function _closeLightBox () {
			$('#lightbox-inner-mainframe').find('#' + $popupContent.attr('id'))
				//.css ({ position:'absolute', left:'-1000px', top:'0px' })
				.addClass('popup')
				.appendTo('body');
				
			$('#lightbox-outter-mainframe').remove();
			//$('#lightbox-overlay-mainframe').fadeOut ( function() { $('#lightbox-overlay-mainframe').remove(); });
			$('#lightbox-overlay-mainframe').remove();
			$(' select').css({ 'visibility' : 'visible' });
		}
		
		_showLightBox ();

	}
})(jQuery); // Call and execute the function immediately passing the jQuery object


