﻿function AdItem()
{
	this.id=0;
	this.type=1;
	this.name="";
	this.title="";
	this.source="";
	this.URL;
	this.target="_blank";	
	this.priority=1;
	this.style;
	this.parameter;
};
function vAds()
{
	this.items=new Array();
	this.width=0;
	this.height=0;
	this.ShowType=0;
	this.name;
	this.add=function(item)
	{
		this.items[this.items.length]=item;
	};
	this.show=function()
	{
		this.divname="vAds_"+this.name;
		switch(this.ShowType)
		{
			
			default:
				document.write("<div id=\""+this.divname+"\"");
				document.write(" style=\"visibility:visible; z-index:1; width:");
				document.write(this.width+"px;height:"+this.height+"px;\">");
				document.write(this.GetData());
				document.write("</div>");
			break;
		}
	};
	this.GetData=function()
	{
		var index=this.GetIndex();
		if(index<0)return;
		var str = "";
		var item=this.items[index];
		if(item.type==1) /*图片*/
		{
			str+="<a href=\""+item.URL+"\" target=\""+item.target+"\" title=\""+item.title+"\">";
			str+="<img src=\""+item.source+"\" border=\"0\"";
			if(item.style)str+=" style=\""+item.style+"\"";
			str+=" width=\""+this.width+"\" height=\""+this.height+"\"";
			str+=" alt=\""+item.title+"\"></a>";
		}
		else if(item.type==2) /*Flash*/
		{
			str="<object type=\"application/x-shockwave-flash\" data=\"";
			str+=item.source+"\" width=\""+this.width+"\" height=\""+this.height+"\" />";
			str+="<param name=\"movie\" value=\""+item.source+"\" />";
			str+="<param name=\"wmode\" value=\"Transparent\" />";
			if(item.parameter)str+=item.parameter;
			str+="</object>";
		} 
		else if(item.type==3) /*文字*/
		{
			str+="<a href=\""+item.URL+"\" target=\""+item.target+"\" title=\""+item.title+"\"";
			if(item.style)str+=" style=\""+item.style+"\"";
			str+=">"+item.title+"</a>";
		}
	  return str;
	};
	this.GetIndex=function()
	{
		if(this.items.length<=1)return this.items.length-1;
		var m=this.items.length;
		var s=0;
		for(var i=0;i<m;i++)
		{
			s=s+this.items[i].priority;
		};
		if(s<=0)return -1;
		var r = Math.random() * s;
		var i = 0;
	  var j = 0;
	  while (true) 
	  {
	    j = j + this.items[i].priority;
	    if (j >= r) break;
	    i++;
	  };
	  if(i>=m)i=0;
	  return i;
	};
};

var g001=new vAds("g001");
g001.width="190";g001.height="65";g001.name="g001";var item=new AdItem();item.id=47;item.name="联系方式";item.title="联系方式";item.type=1;item.URL="http://711688.net/Help/Details-4.aspx";item.source="/Uploads/Ads/200952/210784.gif";g001.add(item);g001.show();