jQuery(document).ready(function()
//RJA ZFS eSolutions Feb 2010
//Zurich Municipal feeds
//Use several RSS feeds - hardcoded at present and no time to put in a reusable loop!
    {
        var options = 
        {
            newsList: "ul#RSSnews",
            startDelay: 10,
            loopDelay: 2999,
            tickerRate: 100
	
        }
		var TotalRSS = 0; //Keeps track of how many ajax calls have completed OK.
		var NumberRSS = 4; //Total number we have.
		var NumRSStoShow = 3; //Number items to get and show.
		var TruncationLength = 45; //Number of characters to put in RSS feed.
		//Truncate at word boundary to stop going on to new line.
		var truncate = function (str, limit) {	
			var bits, i;
			bits = str.split('');	
			if (bits.length > limit) {		
				for (i = bits.length - 1; i > -1; --i) {			
					if (i > limit) {
						bits.length = i;
						}			
					else if (' ' === bits[i]) {
						bits.length = i;	
						break;			
						}
			}		
			bits.push('...');	
			}	
			return bits.join('');
		};
		//RJA create ordered list we will be putting everything in.
		jQuery("#RSSTicker").html('<ul id="RSSnews"></ul>');
		//RJA If success fails (!) nothing we can do anyway so just move on...
		//-----------------------------------------------------------------
		jQuery.ajax({
            type: "GET",
            url: "/NR/rdonlyres/85757033-B2F7-4A44-902D-C56532515665/0/bbcUKRSS.xml",
            dataType: "xml",
            success: function(xml) 
			{
                jQuery(xml).find('item').each(function(index, value)
				{
                    var title = jQuery(this).find('title').text();
					title=truncate(title, TruncationLength);
                    var link = jQuery(this).find('link').text();
                    jQuery('<li style="display:list-item;"><a href="'+link+'">BBC UK News: '+title+'</a></li>').appendTo('ul#RSSnews');
					return (index!==NumRSStoShow);
                });
				TotalRSS+=1;
				if(TotalRSS==NumberRSS){jQuery().newsTicker(options);}
            },
			error: function()
			{TotalRSS+=1;
				if(TotalRSS==NumberRSS){jQuery().newsTicker(options);}
			}
        });
		//-----------------------------------------------------------------		
		jQuery.ajax({
            type: "GET",
            url: "/NR/rdonlyres/1C49EFCB-B496-4B85-A0B7-30AC828134E2/0/LGCRSS.xml",
            dataType: "xml",
            success: function(xml) 
			{
                jQuery(xml).find('item').each(function(index, value)
				{
                    var title = jQuery(this).find('title').text();
					title=truncate(title, TruncationLength);
                    var link = jQuery(this).find('link').text();
                    jQuery('<li style="display:list-item;"><a href="'+link+'">Local Government Chronicle: '+title+'</a></li>').appendTo('ul#RSSnews');
					return (index!==NumRSStoShow);
                });
				TotalRSS+=1;
				if(TotalRSS==NumberRSS){jQuery().newsTicker(options);}
            },
			error: function()
			{TotalRSS+=1;
				if(TotalRSS==NumberRSS){jQuery().newsTicker(options);}
			}
        });
		//-----------------------------------------------------------------		
        jQuery.ajax({
            type: "GET",
            url: "/NR/rdonlyres/92423869-518A-4D78-84A1-AFD4D70C85CD/0/CharityTimesRSS.xml",
            dataType: "xml",
            success: function(xml) 
			{
                jQuery(xml).find('item').each(function(index, value)
				{
                    var title = jQuery(this).find('title').text();
					title=truncate(title, TruncationLength);
                    var link = jQuery(this).find('link').text();
                    jQuery('<li style="display:list-item;"><a href="'+link+'">Charity Times: '+title+'</a></li>').appendTo('ul#RSSnews');
					return (index!==NumRSStoShow);
                });
				TotalRSS+=1;
				if(TotalRSS==NumberRSS){jQuery().newsTicker(options);}
            },
			error: function()
			{TotalRSS+=1;
				if(TotalRSS==NumberRSS){jQuery().newsTicker(options);}
			}
        });
		//-----------------------------------------------------------------		
		jQuery.ajax({
            type: "GET",
            url: "/NR/rdonlyres/840FD184-9A9F-4E50-8CC0-53C13DFC67D7/0/InsideHousingNewsRSS.xml",
            dataType: "xml",
            success: function(xml) 
			{
                jQuery(xml).find('item').each(function(index, value)
				{
                    var title = jQuery(this).find('title').text();
					title=truncate(title, TruncationLength);
                    var link = jQuery(this).find('link').text();
                    jQuery('<li style="display:list-item;"><a href="'+link+'">Inside Housing News: '+title+'</a></li>').appendTo('ul#RSSnews');
					return (index!==NumRSStoShow);
                });
               TotalRSS+=1;
				if(TotalRSS==NumberRSS){jQuery().newsTicker(options);}
            },
			error: function()
			{TotalRSS+=1;
				if(TotalRSS==NumberRSS){jQuery().newsTicker(options);}
			}
        });
	});

