// JavaScript Document
//start of spotlights code
//this function displays randam spotlights on the home page
function nextSpotlight()
{
	if(!spotlights_loaded)
	{
		pos = 0;
		for(i=0; i<12; i++)//populate array with spotlight data
		{
			data = document.getElementById('spotlight'+i).innerHTML;
			if(document.getElementById('spotlight'+i).innerText.length > 5)
			{
				spotlights[pos] = data;
				pos++;
			}
		}
		while(pos < 3)//there should always be at least 3 spotlights
		{
			spotlights[pos] = "<table width='410' border='0' cellspacing='0' cellpadding='0'><tr>"
							+ "<td width='10'>&nbsp;</td>"
							+ "<td width='135'><div id='spotlight_image4'><IMG src='images/chamberlogo1.jpg' align=center border=0></td>"
							+ "<td width='10'>&nbsp;</td>"
							+ "<td width='255' valign='top' class='spotlight'>Looking to promote your business? Feature your business with a Chamber Business Spotlight.<BR><A href='ads.shtml'><STRONG>Click here</STRONG></A><STRONG> for more information.</STRONG></td>"
							+ "<td width='10'>&nbsp;</td>"
							+ "</tr></table>";
			pos ++;
		}
		spotlights_loaded=true;
	}
	if(spotlights.length > 2)
	{
		spot0 = Math.floor(Math.random()*(spotlights.length));
		spot1 = Math.floor(Math.random()*(spotlights.length));
		while(spot0 == spot1)
			spot1 = Math.floor(Math.random()*(spotlights.length));
	
		spot2 = Math.floor(Math.random()*(spotlights.length));
		while(spot0 == spot2 || spot1 == spot2)
			spot2 = Math.floor(Math.random()*(spotlights.length));
	}
	else
	{
		ran = Math.floor(Math.random()*(spotlights.length));
		if(ran < 1)
		{
			spot0 = 0;
			spot1 = 1;
			spot2 = 2;
		}
		else
		{
			spot0 = 2;
			spot1 = 0;
			spot2 = 1;
		}
	}
	document.getElementById('spotlight_visible_0').innerHTML=spotlights[spot0];
	document.getElementById('spotlight_visible_1').innerHTML=spotlights[spot1];
	document.getElementById('spotlight_visible_2').innerHTML=spotlights[spot2];
   	theTimer=setTimeout("nextSpotlight()", 15000);
}
//end of spotlight code...

//this function loads all data from didyouknowlist hidden div and displays one randamly on load
function didyouknow()
{
	var didyouknow_html = document.getElementById('div_did_you_know_list').innerHTML.replace(/<\/?P>/g, "");
	didyouknow_html = didyouknow_html.split("|");
	var didyouknow_text = document.getElementById('div_did_you_know_list').innerText.split("|");
	if(didyouknow_html.length > 0)
	{
		var randomPos = Math.round((Math.random()*didyouknow_html.length));
		if(randomPos >= didyouknow_html.length)
			randomPos = didyouknow_html.length-1;
		
		document.getElementById('div_did_you_know').innerHTML = didyouknow_html[randomPos];
		document.getElementById('div_did_you_know').title = didyouknow_text[randomPos];
	}
}
function showRandamData()
{
	var arrHTML = document.getElementById('div_did_you_know_list').innerHTML;
	var arrText = document.getElementById('div_did_you_know_list').innerText;
	arrHTML = arrHTML.split("|");
	arrText = arrText.split("|");
	if(arrHTML.length > 0)
	{
		var randomPos = Math.round((Math.random()*arrHTML.length));
		if(randomPos >= arrHTML.length)
			randomPos = arrHTML.length-1;
		//trancate string if it is longer that 256 characters(don't count html tags)
		/*var filter = /^<.*>$/
		var str = arrHTML[randomPos].replace(filter, "");
		alert(str);
		if(str.length > 150)
		{
			document.getElementById('div_did_you_know').innerHTML = arrHTML[randomPos].substr(0, 150);
		}
		else*/
			document.getElementById('div_did_you_know').innerHTML = arrHTML[randomPos];
		document.getElementById('div_did_you_know').title = arrText[randomPos];
	}
}