/* By Gary Manfredi
 * Modified from version by Martin Hintzmann
 * MIT (http://www.opensource.org/licenses/mit-license.php) licensed.
 *
 * Version: 0.1
 *
 * Requires:
 *   jQuery 1.2+
 */
(function($){
    $.fn.boxShadow = function(options){
		 // for IE only.  Use CSS for other browsers
		if (!$.browser.msie || ($.browser.msie && Math.floor($.browser.version) < 7)) return;

        // Default options
        var opt = $.extend({
            xOffset: 3,
            yOffset: 5,
            blurRadius: 3,
            color: "#888",
            opacity: 0.5
        }, options);
        
        return this.each(function(){
            var $this = $(this).css({
                position: "relative",
                zoom: 1,
                zIndex: 2
            });
            
			// create shadow
            var div = $("<div class='shadow'></div>").appendTo($this.offsetParent());
            var o = $this.position();
            
            var t, l, w, h;
            if (opt.blurRadius != 0 && $.browser.msie) {
                div.css("filter", "progid:DXImageTransform.Microsoft.Blur(pixelRadius=" + (opt.blurRadius) + ", enabled='true')");
                t = o.top + opt.yOffset - opt.blurRadius - 1;
                l = o.left + opt.xOffset - opt.blurRadius - 1;
                w = $this.outerWidth() + 1;
                h = $this.outerHeight() + 1;
            }
            else {
                t = o.top + opt.yOffset;
                l = o.left + opt.xOffset;
                w = $this.outerWidth();
                h = $this.outerHeight();
            }
			
            div.css({
                top: t,
                left: l,
                width: w,
                height: h,
                background: opt.color,
                position: "absolute",
                zIndex: 1
            });
			
			// store that this has been shadowed for testing on the outside
			$this.data("shadowed", true);
            
        });
    };
})(jQuery);
