﻿(function($) {
    $.fn.imageSwap = function(options) {
        $imageSwapSettings = $.extend({}, $.fn.imageSwap.defaults, options);

        $('a', this).each(function() {
            //            var t = $imageSwapSettings.imagePath + $(this).text() + '.png';
            $(this).append('<img src="" alt="" style="border: none" />');
            hoverOut($(this));
        });

        function hoverOut(o) {
            var t = $imageSwapSettings.imagePath + o.text() + '.png';
            $('img', o).attr('src', t).attr('alt',o.text()).css(
            { width: $imageSwapSettings.imageWidth }
            );
        }

        function hoverIn(o) {
            var t = $imageSwapSettings.imagePath + o.text() + $imageSwapSettings.hoverSuffix + '.png';
            $('img', o).attr('src', t).attr('alt',o.text()).css(
            { width: $imageSwapSettings.imageWidth }
            );
        }

        $('a', this).hover(function() {
            hoverIn($(this));
        }, function() {
            hoverOut($(this));
        });
    };


    $.fn.imageSwap.defaults = {
        imagePath: '/Content/Images/',
        hoverSuffix: '-hover',
        imageWidth: 48
    };
})(jQuery);