/* 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($) {
    $.fn.boxShadow = function(xOffset, yOffset, blurRadius, shadowColor) {
        if (!$.browser.msie) {
            var shadowText = xOffset + 'px ' + yOffset + 'px ' +  blurRadius + 'px ' + shadowColor;
            return this.css({
                'box-shadow':         shadowText,
    			'-o-box-shadow':      shadowText,
    			'-moz-box-shadow':    shadowText,
    			'-webkit-box-shadow': shadowText
            });
        } else {
            return this.each(function(){
                var $this = $(this);
                $this.bind('load', function() {
                    var $parent = $this.parent();
                    var objPos = $this.position();

                    $this.css({
                        zoom:   1,
                        zIndex: 2
                    });

                    if ($parent.css('position') == 'static') {
                        $(this).parent().css({
                            position: 'relative'
                        });
                    }

                    var div = document.createElement('div');
                    $(this).parent().append(div);

                    var _top, _left, _width, _height;
                    if (blurRadius != 0) {
                        $(div).css('filter', 'progid:DXImageTransform.Microsoft.Blur(pixelRadius=' + (blurRadius) + ', enabled="true")');
                        _top =    yOffset - blurRadius - 1;
                        _left =   xOffset - blurRadius - 1;
                        _width =  $(this).outerWidth() + 1;
                        _height = $(this).outerHeight() + 1;
                    } else {
                        _top =    yOffset;
                        _left =   xOffset;
                        _width =  $(this).outerWidth();
                        _height = $(this).outerHeight();
                    }
                    $(div).css({
                        top:        _top + objPos.top + parseInt($this.css('margin-top')),
                        left:       _left + objPos.left + parseInt($this.css('margin-left')),
                        width:      _width,
                        height:     _height,
                        background:	shadowColor,
                        position:   'absolute',
                        zIndex:     1
                    });
                }).each(function() {
                    if (this.complete) {
                        $(this).trigger('load');
                    }
                })
            });
        }
    };
})(jQuery);
