(function($){
	
	$.confirm = function(params){
		
		//if($('#confirmOverlay').length){
			// A confirm is already shown on the page:
		//	return false;
		//}
		
		var buttonHTML = '',
			template,
			buttons,
			i = 0,
			h1 = typeof params.title !== 'undefined'
				? '<h1>'+params.title+'</h1>'
				: '';

		$.each(params.buttons,function(name, obj){
			// Generating the markup for the buttons:
			buttonHTML += '<a href="#" data-theme="e" class="button '+obj['class']+'"><span class="ui-btn-inner ui-btn-corner-all"><span class="ui-btn-text">'+name+'</span></span></a>';
			//buttonHTML += '<button data-theme="e" data-inline="true">'+name+'</button>';

			if(!obj.action){
				obj.action = function(){};
			}
		});

		if (!params.el) { params.el = "confirmBox"; }
		if (!!params.class) { params.class = ' class="'+params.class+'"';  }

		template = [
			'<div id="confirmOverlay">',
			'<div id="', params.el, '" ', params.class, '>',
			h1,
			'<div>',params.message,'</div>',
			'<div id="confirmButtons">',
			buttonHTML,
			'</div></div></div>'
		].join('');
		
		$(template).hide().appendTo('#content').fadeIn();
		
		buttons = $('#confirmBox .button, #eula .button');

		$.each(params.buttons,function(name,obj){
			buttons.eq(i++).click(function(){				
				obj.action();
				$.confirm.hide();
				return false;
			});
		});
	}

	$.confirm.hide = function(){
		$('#confirmOverlay').fadeOut(function(){
			$(this).remove();
		});
	}
	
})(jQuery);