/* Created by Martin Hintzmann 2008 martin [a] hintzmann.dk
 * MIT (http://www.opensource.org/licenses/mit-license.php) licensed.
 *
 * Version: 0.1
 *
 * Requires:
 *   jQuery 1.2+
 */
(function(jq) {
    jq.fn.boxShadow = function(xOffset, yOffset, IEAbsoluteX, IEAbsoluteY, blurRadius, shadowColor) {
        if (!jq.browser.msie)
        {
            return this.each(function(){
                jq(this).css({
                'box-shadow':           xOffset+'px '+yOffset+'px '+blurRadius+'px '+shadowColor,
                '-o-box-shadow':        xOffset+'px '+yOffset+'px '+blurRadius+'px '+shadowColor,
                '-moz-box-shadow':      xOffset+'px '+yOffset+'px '+blurRadius+'px '+shadowColor,
                '-webkit-box-shadow':   xOffset+'px '+yOffset+'px '+blurRadius+'px '+shadowColor
                });
            });
        }
        return this.each(function(){
            jq(this).parent().css({
                    position:   "relative"
            });
            
            var div=document.createElement("div");
            if (!(jq(div).hasClass("ieboxshadow")))
            {
                jq(div).addClass("ieboxshadow");
            }
            jq(this).append(div);

            var _top, _left, _width, _height;
            if (blurRadius !== 0) {
                jq(div).css("filter", "progid:DXImageTransform.Microsoft.Blur(pixelRadius="+(blurRadius)+", enabled='true')");
                _top =      IEAbsoluteY-blurRadius-1;
                _left =     IEAbsoluteX-blurRadius-1;
                _width =    jq(this).width()+1;
                h =         jq(this).height();
                if (h>4)
                {
                    _height =   h-4;
                }
                else
                {
                    _height = h;
                }
            } else {
                _top =      IEAbsoluteY;
                _left =     IEAbsoluteX;
                _width =    jq(this).width();
                _height =   jq(this).height();
            }
            jq(div).css({
                top:            _top,
                left:           _left,
                width:      _width,
                height:     _height,
                background: shadowColor,
                position:   "absolute",
                zIndex:    -1
            });
        });
    };
})(jQuery);
