(function($) {
	
	$.fn.extend({
						
		dhtml: function(script, option, progress, callback) {
			
			var obj = $(this);
						
			if(typeof option == "function") {
				callback = option;
				option = "";
			}
			
			if(typeof progress == "function") {
				callback = progress;
				progress = null;
			}
			
			return this.each(function() {
				
				var action = function() {
					$.get(script, function(data) {
						
						$("#__loading").remove();
										
						if(option == "append")
							obj.append(data);
							
						else if(option == "insertBefore" || option == "before")
							$(data).insertBefore(obj);
							
						else if(option == "insertAfter" || option == "after")
							$(data).insertAfter(obj);
						
						else if(option == "html" || !option)
							obj.html(data)
						
						if(typeof callback == "function")
							callback(data);
					});
				}
				
				if(progress && typeof progress != "function") {						
					obj.startProgress(progress, function() {
						action();
					});
				} else
					action();
					
			});		
		}		
	});
	
	
})(jQuery);
