(function(jB) {
	
	jB.fn.bar = function(options) {
		var opts = $.extend({}, jB.fn.bar.defaults, options);
		return this.each(function() {
			jBthis = $(this);
			var o = $.meta ? $.extend({}, opts, jBthis.data()) : opts;
			

				showAlert(o);

			
			
		});
	};
	
	var timeout;
	jB.fn.bar.removebar = function(txt) {
		if ($('.jbar-container').length) {
			clearTimeout(timeout);
			$('.jbar-container').slideUp('slow',function() {
				$('.jbar').remove();
				$('.jbar-container').removeClass('jbar-container-bottom');
				$('.jbar-container').removeClass('jbar-container-top');
			});
		}	
	};
	jB.fn.bar.defaults = {
		color 			: '#000',
		removebutton	: false,
		time			: 4000};
	
})(jQuery);


function showAlert(o, msg) {
	if(!$('.jbar').length) {
		if (msg !== undefined) o["message"]=msg;
		timeout = setTimeout('$.fn.bar.removebar()',o.time);
		var _message_span = $(document.createElement('span')).addClass('jbar-content').html(o.message);
		_message_span.css({"color" : o.color});
		var _wrap_bar;
		if (o.position == 'bottom') {
			$('.jbar-container').addClass('jbar-container-bottom');
			_wrap_bar = $(document.createElement('div')).addClass('jbar jbar-bottom');
		} else {
			$('.jbar-container').addClass('jbar-container-top');
			_wrap_bar = $(document.createElement('div')).addClass('jbar jbar-top');
		}
		
		_wrap_bar.css({"background-color": o.background_color});
		if (o.removebutton) {
			var _remove_cross = $(document.createElement('a')).addClass('jbar-cross');
			_remove_cross.click(function(e){$.fn.bar.removebar();})
		} else {
			_wrap_bar.css({"cursor"	: "pointer"});
			_wrap_bar.click(function(e){$.fn.bar.removebar();})
		}	
		_wrap_bar.append(_message_span).append(_remove_cross).appendTo($('.jbar-container'));
		$('.jbar-container').slideDown('slow');
	}
}

jQuery.fn.delay = function(time,func){
    this.each(function(){
        setTimeout(func,time);
    });

    return this;
};

