
schedule("window", insertSWFs); 


/*
	** Each SWF file that needs to be inserted should have a separate function.
*/
function insertSWFs() 
{
	if(document.getElementById('flash-news')) insertNewsSWF();
};

function insertNewsSWF() 
{
	var so = new SWFObject("basemedia/flash/news.swf", "sotester", "239", "215", "7", "#FF6600");
	so.addParam("wmode", "transparent");
	var articles = getArticleString();
	
	//articles = '<li><img src="/media/13334/sca 0027 images-10 copy.jpg" alt="adelaide solar city launch" height="92" width="67"/><p class="title">adelaide solar city launch</p><p class="date">03-10-2007</p><a href="/what-its-all-about/news-and-events.aspx">more...</a></li><li><img src="/media/13073/34_1440.jpg" alt="adelaide solar citizens prepare" height="92" width="67"/><p class="title">adelaide solar citizens prepare</p><p class="date">30-08-07</p><a href="/what-its-all-about/news-and-events.aspx">more...</a></li><li><img src="/media/13078/biwa-10453.jpg" alt="news 3" height="92" width="67"/><p class="title">news 3</p><p class="date">date 3</p><a href="/why-make-a-difference/making-a-difference.aspx">more...</a></li><li><img src="/media/13083/foggylandscape.jpg" alt="it"s easy being green" height="92" width="67"/><p class="title">it\"s easy being green</p><p class="date">03-10-2007</p><a href="/registration-success.aspx">more...</a></li><li><img src="/media/13068/31_1440.jpg" alt="item 5" height="92" width="67"/><p class="title">item 5</p><p class="date">5-october-2007 8pm</p><a href="/faq.aspx">more...</a></li><li><img src="/media/13083/foggylandscape.jpg" alt="title 6" height="92" width="67"/><p class="title">title 6</p><p class="date"></p><a href="#">more...</a></li>'
	//alert("articles:\n" + articles);
	so.addVariable('newsItems', articles);
	so.write("flash-news");
};

function getArticleString()
{
	var holder = $("#flash-news ul").html();
	holder = holder.toLowerCase();
	//alert("holder original: " + holder);
	//get the number of li's
	var counter = 0;
	$("#flash-news ul li").each(
		function(i)
		{
			counter++;
		}
	)
	
	var indexFrom = -1;
	var first = 0;
	var second;
	
	for(var i = 0;i<counter;i++)
	{
		first = holder.indexOf("<img", indexFrom+1);
		indexFrom = first;
		second = holder.indexOf(">", indexFrom);
		trying = holder.substring(0, second) + "/>" + holder.substring(second+1, holder.length);
		holder = trying;
	}
		
	
	var articleString = holder.replace(new RegExp( "\\n", "g" ), "").replace(new RegExp( "\\t", "g" ), "").replace(new RegExp( "\\r", "g" ), "").replace(new RegExp( "\\v", "g" ), "").replace(new RegExp( "\\f", "g" ), "");
	
	//articleString = '<li><img src="basemedia/images/news-image.jpg" width="67" height="92" alt="Image Title"/><p class="title">News Article Title One</p><p class="date">Date</p><a href="#">more...</a></li><li><img src="basemedia/images/news-image.jpg" width="67" height="92" alt="Image Title"/><p class="title">News Article Title Two</p><p class="date">Date</p><a href="#">read on...</a></li><li><img src="basemedia/images/news-image.jpg" width="67" height="92" alt="Image Title"/><p class="title">News Article Title Three</p><p class="date">Date</p><a href="#">read on...</a></li><li><img src="basemedia/images/news-image.jpg" width="67" height="92" alt="Image Title"/><p class="title">News Article Title Four</p><p class="date">Date</p><a href="#">read on...</a></li>';
	//articleString = "<li><img height='92' alt='image title' src='basemedia/images/holder-image-long.gif' width='67'/><p class='title'>news article title</p><p class='date'>date</p><a href='#'>read on...</a></li><li><img height='92' alt='image title' src='basemedia/images/holder-image-long.gif' width='67'/><p class='title'>news article title</p><p class='date'>date</p><a href='#'>read on...</a></li><li><img height='92' alt='image title' src='basemedia/images/homepage-brand-img.gif' width='67'/><p class='title'>news article title</p><p class='date'>date</p><a href='#'>read on...</a></li><li><img height='92' alt='image title' src='basemedia/images/left-lightbulb.gif' width='67'/><p class='title'>news article title</p><p class='date'>date</p><a href='#'>read on...</a></li>";
	articleString = articleString.replace(/'/g, "~");
	articleString = articleString.replace(/"/g, "^");
	
	if($.browser.msie)
	{
		newString = articleString.replace(new RegExp( "\\r\n", "g" ), "");
		//add in ' ' marks around the class names on the p.
		pcounter = 0;
		$("#flash-news ul p").each(
			function(i)
			{
				pcounter++;
			}
		)
		//alert("pcounter")
		var first = 0;
		var second = 0;
		var indexFrom = -1;
		for(var j=0;j<pcounter;j++)
		{
			first = newString.indexOf("class=", indexFrom+1);
			indexFrom = first;
			second = newString.indexOf(">", indexFrom);
			//alert(newString.substring(first+6, second));
			var theClass = newString.substring(first+6, second);
			newString = newString.substring(0, first+6) + "'" + theClass + "'" + newString.substring(second, newString.length);
			//alert("newString: " + newString);
		}
		indexFrom = -1;
		first = 0;
		second = 0;
		//add in ' ' marks aroung the height and the width attributes of the images/
		for(var k=0;k<counter;k++)
		{
			first = newString.indexOf("height=", indexFrom+1);
			indexFrom = first;
			var height = newString.substring(first+7, first+9);
			newString = newString.substring(0, first+7) + "'" + height + "'" + newString.substring(first+9, newString.length) ;
			//alert(newString);
			
		}
		indexFrom= -1;
		for(var l=0;l<counter;l++)
		{
			first = newString.indexOf("width=", indexFrom+1);
			indexFrom = first;
			var width = newString.substring(first+6, first+8);
			newString = newString.substring(0, first+6) + "'" + width + "'" + newString.substring(first+8, newString.length);
			//alert(newString);
		}
		
		
		 trying = newString;
		 //trying = newString.replace(/[>\s*<]+/g, ">!<");
		 trying = newString.replace(/[>\s+<] +/g, ">");
		 articleString = trying;
	}
	
	$("#flash-news").empty();
	return articleString;
}