function initAd(arrAds, numAdsToDisplay, verticalSpace)
{
	//addTopAds();

	var s = '<div style="clear:both; width:1px; height:' + verticalSpace + '">&nbsp;</div>';
	for (var j=0; j<numAdsToDisplay && j<10000; j++) //1000 is to prevent an infinite loop
	{
		if (arrAds.length == 0)
			break;
		
		//Pick a random ad, but will display it or not depending on probability
		var i = Math.floor(Math.random()*arrAds.length); //pick a random index (a number from 0 => arrLenth-1)
		var chance = Math.floor(Math.random()*100); //a number from 0 to 99
		if (parseInt(arrAds[i].chance) < chance) {
			j--; //do again
			continue;
		}
		
		//Build the iframe ad
		s += '<div id="ad' + i + '" style="clear:left; float:left">' + arrAds[i].desc +
			'<div style="width:118px">' +
			'</div>' + 
			'<div style="float:left">' +
				'<iframe src="http://rcm.amazon.com/e/cm?lt1=_top&bc1=000000&IS2=1&' +
				(arrAds[i].nou == '1'? 'nou=1&' : '') + 
				'bg1=FFFFFF&fc1=000000&lc1=0000FF&t=bensstuligand-20&o=1&p=8&l=as1&m=amazon&f=ifr&asins=' +
				arrAds[i].asins + '" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>' +
			'</div>' +
		'</div>' +
		'<div style="clear:both; width:1px; height:' + verticalSpace + '">&nbsp;</div>';
		
		arrAds.splice(i,1); //remove this ad from the array, so that we won't display it again
	}
	var el = document.getElementById('adContainerLeft');
	el.innerHTML = s;
}

function addTopAds()
{
	var arrTopAds = [{chance:"50", html:'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" id="Player_708b8986-5e5c-4cb3-8bff-c572fd54fb88"  WIDTH="728px" HEIGHT="90px"> <PARAM NAME="movie" VALUE="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F708b8986-5e5c-4cb3-8bff-c572fd54fb88&Operation=GetDisplayTemplate"><PARAM NAME="quality" VALUE="high"><PARAM NAME="bgcolor" VALUE="#FFFFFF"><PARAM NAME="allowscriptaccess" VALUE="always"><embed src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F708b8986-5e5c-4cb3-8bff-c572fd54fb88&Operation=GetDisplayTemplate" id="Player_708b8986-5e5c-4cb3-8bff-c572fd54fb88" quality="high" bgcolor="#ffffff" name="Player_708b8986-5e5c-4cb3-8bff-c572fd54fb88" allowscriptaccess="always"  type="application/x-shockwave-flash" align="middle" height="90px" width="728px"></embed></OBJECT> <NOSCRIPT><A HREF="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F708b8986-5e5c-4cb3-8bff-c572fd54fb88&Operation=NoScript">Amazon.com Widgets</A></NOSCRIPT>'}, //Lightning deals
					 {chance:"50", html:'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" id="Player_80b20a0a-ef83-4e2b-b112-1d40e163615a"  WIDTH="728px" HEIGHT="90px"> <PARAM NAME="movie" VALUE="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F80b20a0a-ef83-4e2b-b112-1d40e163615a&Operation=GetDisplayTemplate"><PARAM NAME="quality" VALUE="high"><PARAM NAME="bgcolor" VALUE="#FFFFFF"><PARAM NAME="allowscriptaccess" VALUE="always"><embed src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F80b20a0a-ef83-4e2b-b112-1d40e163615a&Operation=GetDisplayTemplate" id="Player_80b20a0a-ef83-4e2b-b112-1d40e163615a" quality="high" bgcolor="#ffffff" name="Player_80b20a0a-ef83-4e2b-b112-1d40e163615a" allowscriptaccess="always"  type="application/x-shockwave-flash" align="middle" height="90px" width="728px"></embed></OBJECT> <NOSCRIPT><A HREF="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F80b20a0a-ef83-4e2b-b112-1d40e163615a&Operation=NoScript">Amazon.com Widgets</A></NOSCRIPT>'}, //Our best deals
					 {chance:"50", html:'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" id="Player_8012d7d4-9723-466f-8a19-5a3c39399329"  WIDTH="728px" HEIGHT="90px"> <PARAM NAME="movie" VALUE="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F8012d7d4-9723-466f-8a19-5a3c39399329&Operation=GetDisplayTemplate"><PARAM NAME="quality" VALUE="high"><PARAM NAME="bgcolor" VALUE="#FFFFFF"><PARAM NAME="allowscriptaccess" VALUE="always"><embed src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F8012d7d4-9723-466f-8a19-5a3c39399329&Operation=GetDisplayTemplate" id="Player_8012d7d4-9723-466f-8a19-5a3c39399329" quality="high" bgcolor="#ffffff" name="Player_8012d7d4-9723-466f-8a19-5a3c39399329" allowscriptaccess="always"  type="application/x-shockwave-flash" align="middle" height="90px" width="728px"></embed></OBJECT> <NOSCRIPT><A HREF="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F8012d7d4-9723-466f-8a19-5a3c39399329&Operation=NoScript">Amazon.com Widgets</A></NOSCRIPT>'}, //Photo Accessories
					 {chance:"50", html:'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" id="Player_d57a880c-3305-4b11-8203-1efe89902050"  WIDTH="728px" HEIGHT="90px"> <PARAM NAME="movie" VALUE="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Fd57a880c-3305-4b11-8203-1efe89902050&Operation=GetDisplayTemplate"><PARAM NAME="quality" VALUE="high"><PARAM NAME="bgcolor" VALUE="#FFFFFF"><PARAM NAME="allowscriptaccess" VALUE="always"><embed src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Fd57a880c-3305-4b11-8203-1efe89902050&Operation=GetDisplayTemplate" id="Player_d57a880c-3305-4b11-8203-1efe89902050" quality="high" bgcolor="#ffffff" name="Player_d57a880c-3305-4b11-8203-1efe89902050" allowscriptaccess="always"  type="application/x-shockwave-flash" align="middle" height="90px" width="728px"></embed></OBJECT> <NOSCRIPT><A HREF="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Fd57a880c-3305-4b11-8203-1efe89902050&Operation=NoScript">Amazon.com Widgets</A></NOSCRIPT>'}, //Photo Accessories - Lighting
					 {chance:"50", html:'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" id="Player_1e34bb7d-51a4-4794-8fab-98d952676b84"  WIDTH="728px" HEIGHT="90px"> <PARAM NAME="movie" VALUE="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F1e34bb7d-51a4-4794-8fab-98d952676b84&Operation=GetDisplayTemplate"><PARAM NAME="quality" VALUE="high"><PARAM NAME="bgcolor" VALUE="#FFFFFF"><PARAM NAME="allowscriptaccess" VALUE="always"><embed src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F1e34bb7d-51a4-4794-8fab-98d952676b84&Operation=GetDisplayTemplate" id="Player_1e34bb7d-51a4-4794-8fab-98d952676b84" quality="high" bgcolor="#ffffff" name="Player_1e34bb7d-51a4-4794-8fab-98d952676b84" allowscriptaccess="always"  type="application/x-shockwave-flash" align="middle" height="90px" width="728px"></embed></OBJECT> <NOSCRIPT><A HREF="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F1e34bb7d-51a4-4794-8fab-98d952676b84&Operation=NoScript">Amazon.com Widgets</A></NOSCRIPT>'}, //Photo Accessories - Photo Studio
					 {chance:"50", html:'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" id="Player_c762ff2b-7f54-4e1c-8cec-d610d19c13b6"  WIDTH="728px" HEIGHT="90px"> <PARAM NAME="movie" VALUE="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Fc762ff2b-7f54-4e1c-8cec-d610d19c13b6&Operation=GetDisplayTemplate"><PARAM NAME="quality" VALUE="high"><PARAM NAME="bgcolor" VALUE="#FFFFFF"><PARAM NAME="allowscriptaccess" VALUE="always"><embed src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Fc762ff2b-7f54-4e1c-8cec-d610d19c13b6&Operation=GetDisplayTemplate" id="Player_c762ff2b-7f54-4e1c-8cec-d610d19c13b6" quality="high" bgcolor="#ffffff" name="Player_c762ff2b-7f54-4e1c-8cec-d610d19c13b6" allowscriptaccess="always"  type="application/x-shockwave-flash" align="middle" height="90px" width="728px"></embed></OBJECT> <NOSCRIPT><A HREF="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Fc762ff2b-7f54-4e1c-8cec-d610d19c13b6&Operation=NoScript">Amazon.com Widgets</A></NOSCRIPT>'}, //Digital SLR
					 {chance:"50", html:'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" id="Player_aa960765-e056-4a9a-bd30-57c1e8bf8155"  WIDTH="728px" HEIGHT="90px"> <PARAM NAME="movie" VALUE="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Faa960765-e056-4a9a-bd30-57c1e8bf8155&Operation=GetDisplayTemplate"><PARAM NAME="quality" VALUE="high"><PARAM NAME="bgcolor" VALUE="#FFFFFF"><PARAM NAME="allowscriptaccess" VALUE="always"><embed src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Faa960765-e056-4a9a-bd30-57c1e8bf8155&Operation=GetDisplayTemplate" id="Player_aa960765-e056-4a9a-bd30-57c1e8bf8155" quality="high" bgcolor="#ffffff" name="Player_aa960765-e056-4a9a-bd30-57c1e8bf8155" allowscriptaccess="always"  type="application/x-shockwave-flash" align="middle" height="90px" width="728px"></embed></OBJECT> <NOSCRIPT><A HREF="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Faa960765-e056-4a9a-bd30-57c1e8bf8155&Operation=NoScript">Amazon.com Widgets</A></NOSCRIPT>'}, //Lighting books
					 {chance:"50", html:'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" id="Player_9fa89fe9-e228-47be-9f8f-7315b5cc6a2d"  WIDTH="728px" HEIGHT="90px"> <PARAM NAME="movie" VALUE="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F9fa89fe9-e228-47be-9f8f-7315b5cc6a2d&Operation=GetDisplayTemplate"><PARAM NAME="quality" VALUE="high"><PARAM NAME="bgcolor" VALUE="#FFFFFF"><PARAM NAME="allowscriptaccess" VALUE="always"><embed src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F9fa89fe9-e228-47be-9f8f-7315b5cc6a2d&Operation=GetDisplayTemplate" id="Player_9fa89fe9-e228-47be-9f8f-7315b5cc6a2d" quality="high" bgcolor="#ffffff" name="Player_9fa89fe9-e228-47be-9f8f-7315b5cc6a2d" allowscriptaccess="always"  type="application/x-shockwave-flash" align="middle" height="90px" width="728px"></embed></OBJECT> <NOSCRIPT><A HREF="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F9fa89fe9-e228-47be-9f8f-7315b5cc6a2d&Operation=NoScript">Amazon.com Widgets</A></NOSCRIPT>'}, //Portrait books
					 {chance:"50", html:'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" id="Player_3996c8a9-e49b-467d-bbc6-a5bac2469f1d"  WIDTH="728px" HEIGHT="90px"> <PARAM NAME="movie" VALUE="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F3996c8a9-e49b-467d-bbc6-a5bac2469f1d&Operation=GetDisplayTemplate"><PARAM NAME="quality" VALUE="high"><PARAM NAME="bgcolor" VALUE="#FFFFFF"><PARAM NAME="allowscriptaccess" VALUE="always"><embed src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F3996c8a9-e49b-467d-bbc6-a5bac2469f1d&Operation=GetDisplayTemplate" id="Player_3996c8a9-e49b-467d-bbc6-a5bac2469f1d" quality="high" bgcolor="#ffffff" name="Player_3996c8a9-e49b-467d-bbc6-a5bac2469f1d" allowscriptaccess="always"  type="application/x-shockwave-flash" align="middle" height="90px" width="728px"></embed></OBJECT> <NOSCRIPT><A HREF="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2F3996c8a9-e49b-467d-bbc6-a5bac2469f1d&Operation=NoScript">Amazon.com Widgets</A></NOSCRIPT>'}, //Photography How-to books
					 {chance:"50", html:'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" id="Player_a837a8aa-3385-4d76-ae30-79649c1ddac8"  WIDTH="728px" HEIGHT="90px"> <PARAM NAME="movie" VALUE="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Fa837a8aa-3385-4d76-ae30-79649c1ddac8&Operation=GetDisplayTemplate"><PARAM NAME="quality" VALUE="high"><PARAM NAME="bgcolor" VALUE="#FFFFFF"><PARAM NAME="allowscriptaccess" VALUE="always"><embed src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Fa837a8aa-3385-4d76-ae30-79649c1ddac8&Operation=GetDisplayTemplate" id="Player_a837a8aa-3385-4d76-ae30-79649c1ddac8" quality="high" bgcolor="#ffffff" name="Player_a837a8aa-3385-4d76-ae30-79649c1ddac8" allowscriptaccess="always"  type="application/x-shockwave-flash" align="middle" height="90px" width="728px"></embed></OBJECT> <NOSCRIPT><A HREF="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Fa837a8aa-3385-4d76-ae30-79649c1ddac8&Operation=NoScript">Amazon.com Widgets</A></NOSCRIPT>'}, //Electronics
					 {chance:"50", html:'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" id="Player_f73f738f-f4bf-495b-a94b-97b2682878a4"  WIDTH="728px" HEIGHT="90px"> <PARAM NAME="movie" VALUE="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Ff73f738f-f4bf-495b-a94b-97b2682878a4&Operation=GetDisplayTemplate"><PARAM NAME="quality" VALUE="high"><PARAM NAME="bgcolor" VALUE="#FFFFFF"><PARAM NAME="allowscriptaccess" VALUE="always"><embed src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Ff73f738f-f4bf-495b-a94b-97b2682878a4&Operation=GetDisplayTemplate" id="Player_f73f738f-f4bf-495b-a94b-97b2682878a4" quality="high" bgcolor="#ffffff" name="Player_f73f738f-f4bf-495b-a94b-97b2682878a4" allowscriptaccess="always"  type="application/x-shockwave-flash" align="middle" height="90px" width="728px"></embed></OBJECT> <NOSCRIPT><A HREF="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Ff73f738f-f4bf-495b-a94b-97b2682878a4&Operation=NoScript">Amazon.com Widgets</A></NOSCRIPT>'}, //Flashes
					 {chance:"50", html:'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" id="Player_b5648295-1920-4133-bb59-2331291923c3"  WIDTH="728px" HEIGHT="90px"> <PARAM NAME="movie" VALUE="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Fb5648295-1920-4133-bb59-2331291923c3&Operation=GetDisplayTemplate"><PARAM NAME="quality" VALUE="high"><PARAM NAME="bgcolor" VALUE="#FFFFFF"><PARAM NAME="allowscriptaccess" VALUE="always"><embed src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Fb5648295-1920-4133-bb59-2331291923c3&Operation=GetDisplayTemplate" id="Player_b5648295-1920-4133-bb59-2331291923c3" quality="high" bgcolor="#ffffff" name="Player_b5648295-1920-4133-bb59-2331291923c3" allowscriptaccess="always"  type="application/x-shockwave-flash" align="middle" height="90px" width="728px"></embed></OBJECT> <NOSCRIPT><A HREF="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Fbensstuligand-20%2F8009%2Fb5648295-1920-4133-bb59-2331291923c3&Operation=NoScript">Amazon.com Widgets</A></NOSCRIPT>'} //Digital frames
					 ];
	var s = '';
	for (var j=0; j<10000; j++) //1000 is to prevent an infinite loop
	{
		if (arrTopAds.length == 0)
			break;
		
		//Pick a random ad, but will display it or not depending on probability
		var i = Math.floor(Math.random()*arrTopAds.length); //pick a random index (a number from 0 => arrLenth-1)
		var chance = Math.floor(Math.random()*100); //a number from 0 to 99
		if (parseInt(arrTopAds[i].chance) < chance) {
			j--; //do again
			continue;
		}
		
		var el = document.getElementById('adContainerTop');
		el.innerHTML = arrTopAds[i].html;
		break;
	}
	
}