//Define banners
rB = new Array();		

//Array item 4 determines "support by" text.  If item 4 has a value
//company name will appear, if item 4 has value false, "support by" appears
//without company name.  If no item 4, use shop/banner display
//BANNERS: 180 wide		
rB[0] = new Array();
rB[0][0] = "http://www.endlesspools.com/s.asp?id=NPR&e=12136&l=landingpages/searchlandingsp.html";
rB[0][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/sponsors/endlesspools_180d.jpg";
rB[0][2] = "Endless Pools";
rB[0][3] = "_blank";
rB[0][4] = "false";

rB[1] = new Array();
rB[1][0] = "http://www.endlesspools.com/s.asp?id=NPR&e=12136&l=landingpages/searchlandingsp.html";
rB[1][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/sponsors/endlesspools_180d.jpg";
rB[1][2] = "Endless Pools";
rB[1][3] = "_blank";
rB[1][4] = "false";

rB[2] = new Array();
rB[2][0] = "http://www.endlesspools.com/s.asp?id=NPR&e=12136&l=landingpages/searchlandingsp.html";
rB[2][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/sponsors/endlesspools_180f.jpg";
rB[2][2] = "Endless Pools";
rB[2][3] = "_blank";
rB[2][4] = "false";

rB[3] = new Array();
rB[3][0] = "http://www.endlesspools.com/s.asp?id=NPR&e=12136&l=landingpages/searchlandingsp.html";
rB[3][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/sponsors/endlesspools_180f.jpg";
rB[3][2] = "Endless Pools";
rB[3][3] = "_blank";
rB[3][4] = "false";

rB[4] = new Array();
rB[4][0] = "http://www.endlesspools.com/s.asp?id=NPR&e=12136&l=landingpages/searchlandingsp.html";
rB[4][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/sponsors/endlesspools_180e.jpg";
rB[4][2] = "Endless Pools";
rB[4][3] = "_blank";
rB[4][4] = "false";

rB[5] = new Array();
rB[5][0] = "http://www.endlesspools.com/s.asp?id=NPR&e=12136&l=landingpages/searchlandingsp.html";
rB[5][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/sponsors/endlesspools_180e.jpg";
rB[5][2] = "Endless Pools";
rB[5][3] = "_blank";
rB[5][4] = "false";

rB[6] = new Array();
rB[6][0] = "http://lifeaquatic.movies.go.com/splash.html";
rB[6][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/sponsors/la_npr_180x150.jpg";
rB[6][2] = "Touchstone Pictures: The Life Aquatic";
rB[6][3] = "_blank";
rB[6][4] = "false";

rB[7] = new Array();
rB[7][0] = "http://www.starbucks.com/holiday";
rB[7][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/sponsors/starbucks_canes_180x150.gif";
rB[7][2] = "Starbucks";
rB[7][3] = "_blank";
rB[7][4] = "false";

rB[8] = new Array();
rB[8][0] = "http://www.starbucks.com/holiday";
rB[8][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/sponsors/starbucks_dove_180x150.gif";
rB[8][2] = "Starbucks";
rB[8][3] = "_blank";
rB[8][4] = "false";

rB[9] = new Array();
rB[9][0] = "http://www.starbucks.com/holiday";
rB[9][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/sponsors/starbucks_gb_180x150.gif";
rB[9][2] = "Starbucks";
rB[9][3] = "_blank";
rB[9][4] = "false";

rB[10] = new Array();
rB[10][0] = "http://www.starbucks.com/holiday";
rB[10][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/sponsors/starbucks_tree_180x150.gif";
rB[10][2] = "Starbucks";
rB[10][3] = "_blank";
rB[10][4] = "false";

rB[11] = new Array();
rB[11][0] = "http://shop.npr.org/catalog/Product.jhtml?PRODID=prod550002&CATID=17&TOPCATID=3"; 
rB[11][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/shop/calendar_180x150.gif";
rB[11][2] = "NPR Shop:  NPR Calendar";
rB[11][3] = "_self";

rB[12] = new Array();
rB[12][0] = "http://shop.npr.org/catalog/Product.jhtml?PRODID=prod570006&CATID=8"; 
rB[12][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/shop/newyorker_180x150.gif";
rB[12][2] = "NPR Shop: New Yorker";
rB[12][3] = "_self";

rB[13] = new Array();
rB[13][0] = "http://shop.npr.org/"; 
rB[13][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/shop/electionday_180x150.gif";
rB[13][2] = "Choose NPR: Free Shipping Offer for a Limited Time";
rB[13][3] = "_self";

//BANNERS: 150 wide
rB[14] = new Array();
rB[14][0] = "http://www.endlesspools.com/s.asp?id=NPR&e=12136&l=landingpages/searchlandingsp.html";
rB[14][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/sponsors/endlesspools_150a.jpg";
rB[14][2] = "Endless Pools";
rB[14][3] = "_blank";
rB[14][4] = "false";

rB[15] = new Array();
rB[15][0] = "http://www.endlesspools.com/s.asp?id=NPR&e=12136&l=landingpages/searchlandingsp.html";
rB[15][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/sponsors/endlesspools_150a.jpg";
rB[15][2] = "Endless Pools";
rB[15][3] = "_blank";
rB[15][4] = "false";

rB[16] = new Array();
rB[16][0] = "http://www.endlesspools.com/s.asp?id=NPR&e=12136&l=landingpages/searchlandingsp.html";
rB[16][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/sponsors/endlesspools_150b.jpg";
rB[16][2] = "Endless Pools";
rB[16][3] = "_blank";
rB[16][4] = "false";

rB[17] = new Array();
rB[17][0] = "http://www.endlesspools.com/s.asp?id=NPR&e=12136&l=landingpages/searchlandingsp.html";
rB[17][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/sponsors/endlesspools_150b.jpg";
rB[17][2] = "Endless Pools";
rB[17][3] = "_blank";
rB[17][4] = "false";

rB[18] = new Array();
rB[18][0] = "http://lifeaquatic.movies.go.com/splash.html";
rB[18][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/sponsors/la_npr_150x150.jpg";
rB[18][2] = "Touchstone Pictures: The Life Aquatic";
rB[18][3] = "_blank";
rB[18][4] = "false";

rB[19] = new Array();
rB[19][0] = "http://shop.npr.org/catalog/Product.jhtml?PRODID=prod550002&CATID=17&TOPCATID=3"; 
rB[19][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/shop/calendar_150x150.gif";
rB[19][2] = "NPR Shop:  NPR Calendar";
rB[19][3] = "_self";

rB[20] = new Array();
rB[20][0] = "http://shop.npr.org/catalog/Product.jhtml?PRODID=prod570006&CATID=8"; 
rB[20][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/shop/newyorker_150x150.gif";
rB[20][2] = "NPR Shop: New Yorker";
rB[20][3] = "_self";

rB[21] = new Array();
rB[21][0] = "http://shop.npr.org/";
rB[21][1] = "http://<!--#echo var="SERVER_NAME" -->/banners/shop/electionday_150x150.gif";
rB[21][2] = "NPR Shop: Free Shipping Offer for a Limited Time";
rB[21][3] = "_self";	

function addSurfaidVarToLink(linkToUse)
{	charToAdd = "?";
	if(linkToUse.indexOf("?") != -1)
		{
			charToAdd = "&";
		}
	return charToAdd;
}

function writeBanner(targetPage)
	{
		//First number of each pair is creative number, second is frequency
		//sum of all second numbers must total 100
		
		//home is 180 wide
		if(targetPage == "home")
			{
				bannersToUse = "6,50|11,25|12,25";
			}
		//topics are 180 wide
		if(targetPage == "topic")
			{
				bannersToUse = "0,5|1,5|2,5|3,5|4,5|5,5|6,40|11,15|12,15";
			}
		//program home page are 150 wide
		//programs are: atc, morning, totn, day, wesun, wesat, fool, tavis
		if((targetPage == "totn") || (targetPage == "tavis") || (targetPage == "fool") || (targetPage == "atc") || (targetPage == "morning") || (targetPage == "wesat") || (targetPage == "wesun") || (targetPage == "pt") || (targetPage == "day"))
			{
				bannersToUse = "14,8|15,9|16,8|17,8|18,33|19,17|20,17";
			}
		
		//set width of image
		if((targetPage == "home") || (targetPage == "topic"))
			{
				banWidth = "180";
			}
		else
			{
				banWidth = "150";
			}
		bannerToUseArray = new Array();
		bannerToUseArray = bannersToUse.split("|");
		for(k = 0; k < bannerToUseArray.length; k++)
			{
				bannerToUseArray[k] = bannerToUseArray[k].split(",");
			}
		
		// choose weighted result
		var wChoice = Math.floor(Math.random()*100);
		var j = 0;
		rb_num = "";
		for (i = 0; i < bannerToUseArray.length; i++) 
			{
				if (wChoice < (parseInt(bannerToUseArray[i][1]) + j)) 
					{
						rb_num = parseInt(bannerToUseArray[i][0]);
						break;
					} 
				else 
					{
						j += parseInt(bannerToUseArray[i][1]);
					}
			}
		if(rB[rb_num][4])
			{
				var rBout = '<div class="dynamicbucket sponsor">' +
					'	<div class="buckettop">&nbsp;</div>' +
					'	<div class="bucketcontent">' +
					'		<div class="story">' +
					'			<p>Support for NPR is provided by:</p>';
				if(rB[rb_num][4] != "false")
					{
						rBout += '			<p>' + rB[rb_num][4] + '</p>';
					}
				rBout += '			<p><a onClick="sa_onclick(this.href);" onKeyPress="sa_onclick(this.href);" href="' + rB[rb_num][0] + '" target="' + rB[rb_num][3] + '"><img src="' + rB[rb_num][1] + '" width="' + banWidth + ' height="150" alt="' + rB[rb_num][2] + '" /></a></p>' +
					'			<p><a href="/about/place/corpsupport/">Become an NPR Sponsor</a></p>' +
					'			<div class="spacer">&nbsp;</div>' +
					'		</div>' +
					'	</div>' +
					'	<div class="bucketbottom">&nbsp;</div>' +
					'</div>';			
			}
		else 
			{
				var rBout = '<div class="dynamicbucket banner">' +
					'	<div class="buckettop">&nbsp;</div>' +
					'	<div class="bucketcontent">' +
					'		<div class="story">' +
					'			<p><a href="' + rB[rb_num][0] + addSurfaidVarToLink(rB[rb_num][0]) + 'npr_ur_inc" target="' + rB[rb_num][3] + '"><img src="' + rB[rb_num][1] + '" width="' + banWidth + '" height="150" border="0" alt="' + rB[rb_num][2] + '" class="underwriting" /></a></p>' +
					'			<div class="spacer">&nbsp;</div>' +
					'		</div>' +
					'	</div>' +
					'	<div class="bucketbottom">&nbsp;</div>' +
					'</div>';				
			}
		document.write(rBout);
	}
	



