

	// All variants below can be modified.
	var contents = [ // If you choose "Text" type, input text below
	{title:"'The experience of Caltech right from the 1st call with my account manager through to the deployment of GoldMine, then to after care has been second to none'..Seaward Electronic Ltd", url:""},
	{title:"'The best thing about working with Caltech was they took time to understand our business'...The Information Centre NHS", url:""},
	{title:"'The introduction of Goldmine and QuoteWerks has played a major part in the doubling of my departments global sales since the introduction of the two systems'..Nigel Bleackley, Stork Cooperheat", url:""}
	];
	var version = 1; // 0: Manipulating Opacity (Default), 1: Using JQUERY FadeIn (JQUERY)
	var type = "TEXT"; // 3 types: TEXT, RSS, XML | Default is TEXT loading contents from the contents array
	var rssfeedURL = "/iweb/blogs/rss.xml"; // Your iWeb RSS feed URL
	var newsURL = "news.xml"; // Your News XML file URL
	var fadetime = 3000; // Fading duration
	var pausetime = 12000; // Pausing duration after fade in
	/* end line */
	
	// Do not modify codes below
	var count = 0;
	var opacity = 0.00;
	var t;
	var textbox, link;
	
function getRSSfeeds(xml)
{
	while (contents.length) {
		contents.pop();
	}
	
	var $items = jQuery('item', xml);
	
    $items.each(function(i) {
		var container = jQuery('description', this).text();	
		var description = truncate(container.slice(container.indexOf('</a>') + 4), 100);
		contents.push({title: description, url: jQuery('link', this).text()});
    });
}

function getItems(xml)
{
	while (contents.length) {
		contents.pop();
	}
	
	var $items = jQuery('item', xml);
	
    $items.each(function(i) {
		contents.push({title: jQuery(this).attr("title"), url: jQuery(this).attr("url")});
    });
}

function truncate(str, length, suffix) {
    if (str.length <= length) {
        return str;
    }

    if (suffix == undefined) {
        suffix = '...';
    }

    return str.substr(0, length).replace(/\s+?(\S+)?$/g, '') + suffix;
};

function fadetext()
{
	version == 1 ? fadetextjquery() : fadetextopacity();
}

function fadetextopacity()
{
	if (t)
		clearTimeout(t);
		
	opacity = 0.00;
	textbox.style.opacity = opacity;
	textbox.style.filter = "alpha(opacity=" + (opacity * 100) + ")";
	
	link.innerHTML=contents[count].title;	
	
	if (contents[count].url)
		link.href=contents[count].url;
	else
		link.removeAttribute('href');
	
	changeopacity();
	
	count++;
	
	if (count == contents.length)
		count = 0;
	
	setTimeout("fadetextopacity()", fadetime + pausetime);
}

function fadetextjquery()
{
	textbox.fadeOut(function(){
	link.html(contents[count].title);	
	
	if (contents[count].url)
		link.attr("href", contents[count].url);
	else
		link.removeAttr("href");
		
	textbox.fadeIn(fadetime, function(){
		count++;
		if (count == contents.length)
			count = 0;
			
		setTimeout("fadetextjquery()", pausetime);
		});
	});
}

function changeopacity()
{
	if (opacity < 1.00)
	{
		opacity = opacity + 0.01;
		
		textbox.style.opacity = opacity;
		textbox.style.filter = "alpha(opacity=" + (opacity * 100) + ")";
	
		t = setTimeout("changeopacity()", fadetime / 100);
	}
}

jQuery(document).ready(function() {

	if (version) { //jQuery
		textbox = jQuery('#textbox');
		link = jQuery('#link');
	} else { // CSS
		textbox = document.getElementById("textbox");
		link = document.getElementById("link");
	}
	
	switch (type)
	{
		case "RSS":
		jQuery.get(rssfeedURL, {}, function(xml) {
			getRSSfeeds(xml);
			fadetext();
      	}, "xml");
      	break;
      	
      	case "XML":
      	jQuery.get(newsURL, {}, function(xml) {
			getItems(xml);
			fadetext();
      	}, "xml");
      	break;
      	
      	default:
      	fadetext();
      	break;
     }
});

