/*
原作者：
AD rotator script written entirely in JavaScript
Written by WenWei, 2002/03/03. E-mail: wenwei@blueidea.com
ASP 2 JS Written by 小荷, 2003/05/28. E-mail: aston314@sohu.com

**********************************
Editor By BAIN , 2004/06/12
Member Of contnew Web Team
Welcome To www.contnew.com
*/

var obj;

// 广告对象
function Advertise(){
	this.obj = obj;
	this.Htmlcode	= "";	// Non image banner's html code
	this.Href		= "";	// Link's Href attrib
	this.Src		= "";	// Image's src attrib
	this.Width		= "";	// Image's width attrib
	this.Height		= "";	// Image's height attrib
	this.Alt		= "";	// Image's alt attrib
	this.Border		= 0;	// Image's border attrib
	this.Weight		= 1;	// Banner's show Weight
	this.Place		= 1;	// Banner's Place
	this.Type		= 1;	// Banner's Type
}

// 创建广告
function CreateAds(sAds,sNum)
{
	obj = eval(sAds);

	var i = 0;
	for (i=0;i<sNum;i++)
	{
		sAds[i] = new Advertise();
	}
}

// 显示广告
function ShowAds(sPlace, sType, sAdsId)
{

	var amount = obj.length;
	var itemlist = new Array(amount);

	if (!document.banners)
	{
		document.banners = new Array(amount);
		
		for (var i=0; i<amount; i++)
		{
			document.banners[i] = -1;
		}
	}
 
	var usedlist = document.banners;
	
	if (arguments.length == 2)
	{
		var j = 0;
		var sum = 0;
		for(var i=0; i<amount; i++)
		{
			if (obj[i].Place == sPlace && obj[i].Type == sType)
			{
				if (usedlist[i] != i)
				{
					itemlist[j] = i;
					j++;
					sum = sum + obj[i].Weight;
				}
			}
		}

		if (sum <= 0)
		{
			return;
		}

		var rndNum = Math.round(Math.random() * sum);
		
		i = 0;
		j = 0;

		while (true)
		{
			j = j + obj[itemlist[i]].Weight;
		    if (j >= rndNum)
			{
				break;
			}
			i++;
		}
		
		i = itemlist[i];
	}else{
		if (sAdsId >= 0 && sAdsId < amount)
		{
			i = sAdsId;
		}else{
			return;
		}
	}
	
	usedlist[i] = i;

	if (obj[i].Htmlcode == "")
	{
		if (obj[i].Href == "")
		{
			document.write('<img src="'+ obj[i].Src +'" width="'+ obj[i].Width +'" height="'+ obj[i].Height +'" alt="'+ obj[i].Alt +'" border="'+ obj[i].Border +'">');
		}else{
			if (obj[i].Href.indexOf("http") == 0)
			{
				document.write('<a href="'+ obj[i].Href +'" target="_blank"><img src="'+ obj[i].Src +'" width="'+ obj[i].Width +'" height="'+ obj[i].Height +'" alt="'+ obj[i].Alt +'" border="'+ obj[i].Border +'"></a>');
			}else{
				document.write('<a href="'+ obj[i].Href +'"><img src="'+ obj[i].Src +'" width="'+ obj[i].Width +'" height="'+ obj[i].Height +'" alt="'+ obj[i].Alt +'" border="'+ obj[i].Border +'"></a>');
			}
		}
	}else{
		document.write(obj[i].Htmlcode);
	}
}

var ADBanners = new Array();
CreateAds(ADBanners, 12);


ADBanners[11].Src = "non-bin/upload/advertise/2008122638310093.jpg";
ADBanners[11].Href = "http://bbs.13pu.com/thread-64-1-1.html";
ADBanners[11].Width  = "200";
ADBanners[11].Height = "110";
ADBanners[11].Alt = "";
ADBanners[11].Weight = 1;
ADBanners[11].Place = 1;
ADBanners[11].Type = 0;
ADBanners[10].Src = "non-bin/upload/advertise/2008122638298657.jpg";
ADBanners[10].Href = "http://www.13pu.com/blog/";
ADBanners[10].Width  = "200";
ADBanners[10].Height = "110";
ADBanners[10].Alt = "";
ADBanners[10].Weight = 1;
ADBanners[10].Place = 1;
ADBanners[10].Type = 0;
ADBanners[9].Src = "non-bin/upload/advertise/2008122638290109.jpg";
ADBanners[9].Href = "http://shop35163238.taobao.com/";
ADBanners[9].Width  = "200";
ADBanners[9].Height = "110";
ADBanners[9].Alt = "";
ADBanners[9].Weight = 1;
ADBanners[9].Place = 1;
ADBanners[9].Type = 0;
ADBanners[8].Src = "non-bin/upload/advertise/2008122638282469.jpg";
ADBanners[8].Href = "http://www.douban.com/group/www13pucom/";
ADBanners[8].Width  = "200";
ADBanners[8].Height = "110";
ADBanners[8].Alt = "";
ADBanners[8].Weight = 1;
ADBanners[8].Place = 1;
ADBanners[8].Type = 0;
ADBanners[7].Src = "non-bin/upload/advertise/2008122579798497.jpg";
ADBanners[7].Href = "http://www.13pu.com/detail.asp?cgid=4&pdid=54";
ADBanners[7].Width  = "400";
ADBanners[7].Height = "200";
ADBanners[7].Alt = "";
ADBanners[7].Weight = 1;
ADBanners[7].Place = 1;
ADBanners[7].Type = 0;
ADBanners[6].Src = "non-bin/upload/advertise/2008122579552425.jpg";
ADBanners[6].Href = "http://www.13pu.com/detail.asp?cgid=4&pdid=53";
ADBanners[6].Width  = "400";
ADBanners[6].Height = "200";
ADBanners[6].Alt = "";
ADBanners[6].Weight = 1;
ADBanners[6].Place = 1;
ADBanners[6].Type = 0;
ADBanners[5].Src = "non-bin/upload/advertise/2008122578290921.jpg";
ADBanners[5].Href = "http://www.13pu.com/detail.asp?cgid=4&pdid=50";
ADBanners[5].Width  = "400";
ADBanners[5].Height = "200";
ADBanners[5].Alt = "";
ADBanners[5].Weight = 1;
ADBanners[5].Place = 1;
ADBanners[5].Type = 0;
ADBanners[4].Src = "non-bin/upload/advertise/2008122578313937.jpg";
ADBanners[4].Href = "http://www.13pu.com/detail.asp?cgid=4&pdid=51";
ADBanners[4].Width  = "400";
ADBanners[4].Height = "200";
ADBanners[4].Alt = "";
ADBanners[4].Weight = 1;
ADBanners[4].Place = 1;
ADBanners[4].Type = 0;
ADBanners[3].Src = "non-bin/upload/advertise/20086542134713.gif";
ADBanners[3].Href = "http://www.13pu.com/blog/";
ADBanners[3].Width  = "155";
ADBanners[3].Height = "124";
ADBanners[3].Alt = "";
ADBanners[3].Weight = 1;
ADBanners[3].Place = 1;
ADBanners[3].Type = 0;
ADBanners[2].Src = "non-bin/upload/advertise/20092954215877.jpg";
ADBanners[2].Href = "";
ADBanners[2].Width  = "800";
ADBanners[2].Height = "300";
ADBanners[2].Alt = "";
ADBanners[2].Weight = 1;
ADBanners[2].Place = 1;
ADBanners[2].Type = 0;
ADBanners[1].Src = "non-bin/upload/advertise/2008122570171129.jpg";
ADBanners[1].Href = "http://www.13pu.com/category.asp?ptid=0&cgid=1";
ADBanners[1].Width  = "810";
ADBanners[1].Height = "167";
ADBanners[1].Alt = "";
ADBanners[1].Weight = 1;
ADBanners[1].Place = 1;
ADBanners[1].Type = 0;
