/*
	NMS for jQuery
	
	(c) Steven Monetti 2008
	
	E-Mail: steven.monetti@gmail.com	
	
	V 1.0 - Dec 27th

*/

(function($){  
var init = false;
$.fn.nms_msg = function(options) {  
	
	//Options
	var defaults = {  
		text: '',
		text_color: '#333',
		text_align: 'center',
		border_color: '',
		background: '',
		freeze: false,
		close: true,
		type: 'notice',
		delay: '',
		icon: '',
		icon_path: ''  
	};  
	var options = $.extend(defaults, options);  
			
	//-- Functionality --- //
		
		//--- Message box --- //
		
		//Style overwrite
		var style='', icon='', close='';
		if(options.border_color != '') style += 'border: 2px solid ' + options.border_color +';';
		if(options.background != '')   style += 'background: ' + options.background +';';
		if(options.close) close = '<div id="nms_msg_close"></div>';
		else					close = '<div id="nms_msg_close" style="display: none"></div>';
		//Message with/without loading
		if(options.type=='notice'){
			className = 'notice_msg notices'; title = 'Notice:'
		}else if(options.type=='error'){
			className = 'err_msg notices'; title = 'Error:'
		}else{
			className = 'notice_msg notices'; title = ''
		}
		if(options.icon != '') icon = '<td width="1"><img src="'+options.icon_path + options.icon+'"></td>';

		
		//Box HTML
		var content = '\
		<div class=\"msgContent\"  > \
			<div class="'+className+'" id="err">\
				 <div class="sys-messages-span">\
				 	<div class="sys-messages-header">'+title+'</div>\
					<div class="sys-messages-msg">'+options.text+'</div>\
 </div>\
                    <div class="sys-messages-button">\
                    '+close+'\
                    </div>\
                </div>\
		</div>';
		
		var box='\
		<div id="nms_msg" style="display: none;">\
			<div class="popup">\
			'+content+'\
			</div>\
		</div>';
			
		//Appened to body and show
		if(!init) { 
			$(this).append(box);
			init = true;
		}
		else {	
			$('#nms_msg .msgContent').remove();
			$('#nms_msg .popup').append(content);
		}
		
		if(options.freeze) $(this).append('<div id="nms_freezeBG" style="display: none;"></div>');
		$('#nms_msg').fadeIn('normal');
		if(options.freeze) $('#nms_freezeBG').fadeIn('normal');
	
		//Hide with delay
		if(options.delay != '') 
		{
			$('#nms_msg').fadeTo(options.delay, 1).fadeOut('slow');
			$('#nms_freezeBG').fadeTo(options.delay, 0.4).fadeOut('slow');
		}
		
		//Close function
		$('#nms_msg_close').bind('click', function () {
			$('#nms_msg').fadeOut('slow');
			$('#nms_freezeBG').fadeOut('slow');
		});
		
		
}


})(jQuery);  
