
schedule("window", insertSWFs); 


/*
	** Each SWF file that needs to be inserted should have a separate function.
*/
function insertSWFs() 
{
	if(document.getElementById('flash')) insertGridFlashSWF();
};

function insertGridFlashSWF() 
{
	var so = new SWFObject("basemedia/flash/hover-grid.swf", "hover-grid", "430", "430", "8", "#FF6600");
	so.addParam("wmode", "transparent");
	html = getMarkup();
	so.addVariable("markup", html);
	so.write("flash");
};

function getMarkup()
{
	$(".grid-flash ul img").each(
		function(i)
		{
			$(this).removeAttr("alt");
		}
	);
	var holder = $(".grid-flash ul").html();
	holder = holder.toLowerCase();
	//get the number of li's
	var counter = 0;
	$(".grid-flash 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;
		
		//remove the alt tag from the images
		
		 trying = newString;
		 //trying = newString.replace(/[>\s*<]+/g, ">!<");
		 trying = newString.replace(/[>\s+<] +/g, ">");
		 articleString = trying;
	}
	
	$("#flash-news").empty();
	return articleString;
}
