
function Ad(path)	{
	if ((path)==null)	{
		path = "../ads/";
	}

	myList = new AdList();
	max_ad_height="960";
	ad_width="213";
	ad_path = path;
	var max_ads = myList.Total-1;
	
	var random_ad = get_random(max_ads);
	
	var file_name = myList[random_ad][0];
	var ad_height =  myList[random_ad][1];
	var total_height_used = ad_height;
	var html_code = BuildIframe(ad_height, ad_width, ad_path, file_name);	
	
	// get second ad
	random_ad++;
	if (random_ad > max_ads)	{
		random_ad = 0;
	}
	file_name = myList[random_ad][0];
	ad_height =   myList[random_ad][1];
	html_code += "<br/><hr/>";
	html_code += BuildIframe(ad_height, ad_width, ad_path, file_name);	

	if (total_height_used < (max_ad_height - 340))	{
		// get a third ad
		random_ad++;
		if (random_ad > max_ads)	{
			random_ad = 0;
		}
		file_name = myList[random_ad][0];
		ad_height =   myList[random_ad][1];
		html_code += "<br/><hr/>";
		html_code += BuildIframe(ad_height, ad_width, ad_path, file_name);	

	}
	
	this.iFrameCode = html_code;
}


function get_random(MaxValue)	{
	var ranNum= Math.round(Math.random()* (MaxValue));
	return ranNum;
}

function BuildIframe (ad_height, ad_width, ad_path, file_name)	{
	var iFrameCode = "<iframe name='' height='" + ad_height + "' width='"+ ad_width+"' frameborder='0' marginwidth='0' marginheight='0' frameborder='0' vspace='0' hspace='0' allowtransparency='true' scrolling='auto' src=\"" + ad_path + file_name + "\"></iframe>";
	return iFrameCode;
	
}  

