/* Created by Martin Hintzmann 2008 martin [a] hintzmann.dk
 * MIT (http://www.opensource.org/licenses/mit-license.php) licensed.
 *
 * Version: 0.2 Modified
 * Requires: jQuery 1.2+
 * http://plugins.jquery.com/project/textshadow
 *
 */
(function (jQuery) {
    jQuery.fn.textShadow = function (color, x, y, radius) {
        var shadow = {
            x: x || 0,
            y: y || 0,
            radius: radius || 0,
            color: color || '#000000'
        };

        if (!jQuery.browser.msie) {
            this.css('text-shadow', shadow.color + ' ' + shadow.x + 'px ' + shadow.y + 'px ' + shadow.radius + 'px');
            return;
        }

        var IE6 = jQuery.browser.version < 7;
        return this.each(function () {
            var el = jQuery(this);

            el.textShadowRemove();

            if (shadow.x == 0 && shadow.y == 0 && shadow.radius == 0) return;

            if (el.css("position") == "static") {
                el.css({
                    position: "relative"
                });
            }
            el.css({
                zIndex: "0"
            });
            if (IE6) {
                el.css({
                    zoom: "1"
                });
            }

            var span = document.createElement("s");
            jQuery(span).addClass("text-shadow");
            jQuery(span).text(el.text());

            if (this.style.width == '') {
                el.width((el.width() + 1));
            }
            
            jQuery(span).css({
                padding: this.currentStyle["padding"],
                width: el.width() + 'px',
                position: "absolute",
                zIndex: "-1",
                color: shadow.color != null ? shadow.color : el.css("color"),
                left: (-parseInt(shadow.radius) + parseInt(shadow.x)) + "px",
                top: (-parseInt(shadow.radius) + parseInt(shadow.y)) + "px",
                textDecoration: el.css('text-decoration')
            });

            if (shadow.radius != 0) {
                if (shadow.opacity != null) {
                    jQuery(span).css("filter", "progid:DXImageTransform.Microsoft.Blur(pixelradius=" + parseInt(shadow.radius) + ", enabled='true', makeShadow='true', ShadowOpacity=" + shadow.opacity + ")");
                } else {
                    jQuery(span).css("filter", "progid:DXImageTransform.Microsoft.Blur(pixelradius=" + parseInt(shadow.radius) + ", enabled='true')");
                }
            }
            el.append(span);

        });
    };

    jQuery.fn.textShadowRemove = function () {
        if (!jQuery.browser.msie) {
            return this.css({
                textShadow: 'none'
            });
        } else {
            return this.each(function () {
                jQuery(this).children("s.text-shadow").remove();
            });
        }
    };
})(jQuery);

if (typeof Array.prototype.map == 'undefined') {
    Array.prototype.map = function (fnc) {
        var a = new Array(this.length);
        for (var i = 0; i < this.length; i++) {
            a[i] = fnc(this[i]);
        }
        return a;
    }
}
