(function($) {
    $.fn.rssReader = function(j) {
        var k = $.extend({
            targeturl: "XMLFile1.xml",
            items: 3,
            Maxlength: 200,
            loadingImg: '35-1.gif'
        }, j);

        if (!j.targeturl) return false;
        var l = $.extend(k, j);
        var m = ($.browser.msie);
        if (m) {
            $('#newsfeed').ajaxStart(function() {
                $("#newsfeed").css({
                    'z-index': 90,
                    'opacity': 0.4
                });
                $('<img id="loading" src="' + l.loadingImg + '" alt="Traitement en cours ..." />').css({ 'opacity': 1 }).appendTo('#newsfeed')
            });

            $("#newsfeed").ajaxError(function() {
                $(this).append("<strong>Error requesting page</strong>")
            });
            $.get(l.targeturl, function(f) {
                $('#newsfeed img').remove();
                $("#newsfeed").css({
                    'opacity': 1
                });

                var i = 0;
                var g = j.items;
                function h(e) {
                    $(f).find('item').each(
                                    function(i) {
                                        if (i > e - 1) return;
                                        var a = $(this).find('title').text();
                                        var b = $(this).find('pubDate').text();
                                        var c = $(this).find('link').text();
                                        var d = $(this).find('description').text();

                                        var RssFeed = '<div class="home-news-box left">';
                                        RssFeed = RssFeed + '<span class="news-title"><a href="' + c + '">' + a + '</a></span><br />';
                                        RssFeed = RssFeed + o(d, j.Maxlength) + '<span class="news-title"><a href="' + c + '">..read more</a></span>';

                                        var lastRecord = $(f).find('item').length;

                                        if (lastRecord > e)
                                            lastRecord = e;

                                        if (i < (lastRecord - 1))
                                            RssFeed = RssFeed + '<div class="expand short-break"></div>'

                                        RssFeed = RssFeed + '</div>';
                                        $(RssFeed).appendTo('#newsfeed')
                                    })
                }
                return h(g)
            })
        }
        else {
            var n = "xml";
            $.ajax({
                type: "get",
                url: l.targeturl,
                dataType: n,
                processData: true,
                beforeSend: function() {
                    $("#newsfeed").css({
                        'z-index': 90,
                        'opacity': 0.4
                    });
                    $('<img id="loading" src="' + l.loadingImg + '" alt="Traitement en cours ..." />').css({ 'opacity': 1 }).appendTo('#newsfeed')
                },
                error: function(e) {
                    $(this).append("<strong>Error requesting page</strong>")
                },
                success: function(f) {
                    $("#newsfeed").css({ 'opacity': 1 });
                    $('#newsfeed img').remove();
                    var i = 0;
                    var g = j.items; function h(e) {
                        $(f).find('item').each(function(i) {
                            if (i > e - 1) return;
                            var a = $(this).find('title').text();
                            var b = $(this).find('pubDate').text();
                            var c = $(this).find('link').text();
                            var d = $(this).find('description').text();

                            var RssFeed = '<div class="home-news-box left">';
                            RssFeed = RssFeed + '<span class="news-title"><a href="' + c + '">' + a + '</a></span><br />';
                            RssFeed = RssFeed + o(d, j.Maxlength) + '<span class="news-title"><a href="' + c + '">..read more</a></span>';

                            var lastRecord = $(f).find('item').length;

                            if (lastRecord > e)
                                lastRecord = e;

                            if (i < (lastRecord - 1))
                                RssFeed = RssFeed + '<div class="expand short-break"></div>'

                            RssFeed = RssFeed + '</div>';

                            $(RssFeed).appendTo('#newsfeed')
                        })
                    }
                    return h(g)
                }
            })
        }
    };
    function o(a, b) {
        a = a.replace(/(<.*?>)/ig, "");

        var length = 200;
        if (a.length < length)
            length = a.length;

        if (length <= 0)
            return '';
            
        a = a.substring(0, length - 1);

        var c = a.split(/\s/);
        
        var d = '';
        for (var i = 0; i < c.length; i++) {
            d += c[i] + ' '
        }
        return d
    }
})(jQuery);


          
