/*

	Author: Suciu Vlad
	Name: Modalbox
	Version: 1.1
	Last Update: 17.07.2010

*/

(function(){
	
	$.fn.modalbox = function(options){
		return this.each(function(){
			
			var defaults = {
				location : $(this).attr("href"),
				width: 490
			}
			
			settings = $.extend(defaults, options);
			

			$('body')
					.append('<div id="overlay" />')
					.append('<div id="modalbox" />');
			
			$('#modalbox').append("<div class='ajaxLoader' />")
					
			$('#modalbox').load(settings.location, function(){
				$(this).find('#top').append('<a href="#" class="controls"></a>');
			})
						
								
			$('#overlay').css({
				backgroundColor: '#000',
				opacity: '0.3',
				width: '100%',
				height: '100%',
				position: 'fixed',
				top: 0,
				left: 0,
				zIndex: '998'
			});
			
			$('#modalbox').css({
				position: 'absolute', 
				top: '10px',
				display: 'block',
				left: '50%',
				marginTop: '20px',
				marginLeft: - settings.width / 2 - parseInt($('#modalbox').css('padding-left') + parseInt($('#modalbox').css('padding-right'))),
				zIndex: '999',
				background: '#fff',
				width: settings.width,
				height: settings.height
			})
			
			$('#modalbox a.close').live("click", function(){
				$('#modalbox').fadeOut("fast", function(){
					$(this).remove();
				})
				$('#overlay').fadeOut("fast", function(){
					$(this).remove();
				})
			})

		})
	}
	
})(jQuery);
