(function($) {

    $.fn.shadow = function(options) {
        var defaults = { bottom: 5, right: 5, color: "#888" };
        var opt = $.extend(defaults, options||{});
        return this.each(function() {
                var target = $(this);
                if (target.css("position") != "absolute")
                    target.css("position", "relative");
                var w = target.outerWidth(false);
                var h = target.outerHeight(false);
                var o = target.offset();
                var z = parseInt(target.css("zIndex"), 10);
                z = (isNaN(z) || z < 2) ? 2 : z;
                target.css("zIndex", z); //in case it wasn't there
                var s = target.data("shadow") || $("<div/>").appendTo(target.parent());
                s.css({ position: "absolute", backgroundColor: opt.color,
                    left: o.left + opt.right, top: o.top + opt.bottom,
                    width: w, height: h, zIndex: z-1 });
                target.data("shadow", s);
            });
    };
    
    $.fn.unshadow = function() {
        return this.each(function() {
            var target = $(this);
            var shadow = target.data("shadow");
            target.removeData("shadow");
            if (shadow)
                shadow.remove();
        });
    };
    
})(jQuery);
