﻿/**
**广告对象
*/
function adsCls()
{
    this.AdsItem=function()
    {
         this.ADID        = 0;
         //1image,2flash,3iframe
         this.ADType      = 0;
         this.ADName      = "";
         this.FileUrl      = "";
         this.FileWidth    = 0;
         this.FileHeight   = 0;
         this.FlashWmode  = 0;
         this.LinkTarget  = 0;
         this.LinkUrl="";
         this.LinkAlt     = "";
         this.Priority    = 0;
         this.CountView   = 0;
         this.CountClick  = 0;
         this.Delay=6000;
         this.ViewAction  = "";
         this.ClickAction = "";
    }
    this.BannerZoneAD=function(_id) 
	{
	/* Define Constants */
      this.adNum       = 0;
      this.adDelay     = 6000;
      this.ID          = _id;
      this.ZoneID      = 0;
      this.ZoneName    = "";
      this.ZoneWidth   = 0;
      this.ZoneHeight  = 0;
      //1priority,2first,3Loop
      this.ShowType    = 3;
      this.DivName     = "";
      this.Div         = null;
    
      this.ADList= new Array();
      this.ShowAD=null;
      
      this.AddAD=function(_AD)
      {
         if(_AD.FileWidth>this.ZoneWidth)
            _AD.FileWidth=this.ZoneWidth;
         
         if(_AD.FileHeight>this.ZoneHeight)
            _AD.FileHeight=this.ZoneHeight;
            
         this.ADList[this.ADList.length] = _AD;
      }
      
      this.GetShowAD=function()
      {
          if (this.ShowType > 1) {
            this.ShowAD = this.ADList[0];
            return;
          }
          var num = this.ADList.length;
          var sum = 0;
          for (var i = 0; i < num; i++) {
            sum = sum + this.ADList[i].Priority;
          }
          if (sum <= 0) {return ;}
          var rndNum = Math.random() * sum;
          i = 0;
          j = 0;
          while (true) {
            j = j + this.ADList[i].Priority;
            if (j >= rndNum) {break;}
            i++;
          }
          this.ShowAD = this.ADList[i];
      }
      this.Show=function()
      {
         this.GetShowAD();
         if (this.ShowAD == null) return false;
         
         this.DivName = "BannerZoneAD_Div" + this.ZoneID;
         
         if (!this.ShowAD.ImgWidth) this.ShowAD.ImgWidth = this.ZoneWidth
         if (!this.ShowAD.ImgHeight) this.ShowAD.ImgHeight = this.ZoneHeight
        
         if (this.ShowType == 3) 
         {
            document.write("<div id='" + this.DivName + "' style='visibility:visible; z-index:1; width:" + this.ZoneWidth + "; height:" + this.ZoneHeight + "; filter: revealTrans(duration=2,transition=20);'>" + this.getAD_Content(this.ShowAD) + "</div>");
         } 
         else
         {
            if (navigator.appName == "Netscape") 
            {
              document.write("<layer id='" + this.DivName + "' width='" + this.ZoneWidth + "px' height='" + this.ZoneHeight + "px'>" + this.getAD_Content(this.ShowAD) + "</layer>");
            } 
            else 
            {
              document.write("<div id='" + this.DivName + "' style='visibility:visible; z-index:1; width:" + this.ZoneWidth + "px; height:" + this.ZoneHeight + "px;'>" + this.getAD_Content(this.ShowAD) + "</div>");
            }
            if (this.ShowAD.CountView) 
            {
              document.write ("<script src='" + this.ShowAD.ViewAction+"?url="+escape(this.ShowAD.LinkUrl) + "'></" + "script>")
            }
          }
          this.Div = document.getElementById(this.DivName);
          if (this.ShowType == 3) this.LoopShow();
      }
      this.LoopShow =function()
      {
          if(this.adNum<this.ADList.length-1) this.adNum++ ; 
          else this.adNum=0; 
          var ADObj=this.ADList[this.adNum];
          this.adDelay=ADObj.Delay;
          
          
          this.Div.filters.revealTrans.Transition=Math.floor(Math.random()*23); 
          this.Div.filters.revealTrans.apply(); 
          
          if (ADObj.ImgWidth) ADObj.ImgWidth = this.ZoneWidth
          if (ADObj.ImgHeight) ADObj.ImgHeight = this.ZoneHeight
          
          this.Div.innerHTML=this.getAD_Content(ADObj);
          try{
                this.Div.filters.revealTrans.play() ;
          }catch(e)
          {
          }
          
          this.Div.timer=setTimeout(this.ID+".LoopShow()",this.adDelay);
      }
      
      this.getAD_Content=function(o)
     {
        var str = "";
        if(o.ADType==1)
        {
            o.FileUrl = o.FileUrl.toLowerCase()
            if (o.FileUrl.indexOf(".gif") !=  - 1 || o.FileUrl.indexOf(".jpg") !=  - 1 || o.FileUrl.indexOf(".jpeg") !=  - 1 || o.FileUrl.indexOf(".bmp") !=  - 1 || o.FileUrl.indexOf(".png") !=  - 1)
            {
                if (o.ClickAction) 
                {
                    str += "<a href='" + o.ClickAction+"?url="+escape(o.LinkUrl) + "' target='" + ((o.LinkTarget == 0) ? "_self" : "_blank") + "' title='" + o.LinkAlt + "'>";
                }
                str += "<img ";
                str += " name='AD_" + o.ADID + "' id='AD_" + o.ADID + "'";
                if (o.style) str += " style='" + o.style + "'";
                if (o.extfunc) str += " " + o.extfunc + " ";
                str += " src='" +o.FileUrl + "'";
                if (o.FileWidth) str += " width='" + o.FileWidth + "'";
                if (o.FileHeight) str += " height='" + o.FileHeight + "'";
                str += " border='0'>";
                if (o.LinkUrl) str += "</a>";
            }
        }
        else if (o.ADType == 2) 
        {
            o.FileUrl = o.FileUrl.toLowerCase()
            if (o.FileUrl.indexOf(".swf") !=  - 1 || o.FileUrl.indexOf(".fla") !=  - 1) 
            {
                str ="<embed ";
                str += " name='AD_" + o.ADID + "' id='AD_" + o.ADID + "'";
                str += " width='" + o.FileWidth + "'";
                str += " height='" + o.FileHeight + "'";
                if (o.style) str += " style='" + o.style + "'";
                if (o.extfunc) str += " " + o.extfunc + " ";
                str += " src='" + o.FileUrl + "'";
                if (o.FlashWmode == 1) str += " wmode='Transparent'";
                if (o.play) str += " play='" + o.play + "'";
                if (typeof(o.loop) != "undefined") str += " loop='" + o.loop + "'";
                str += " quality='autohigh'";
                str += " pluginspage='http://www.macromedia.com/shockwave/download/'type='application/x-director'></embed>";
            }
        } 
        
        else
        {
            str = "<iframe id='" + "AD_" + o.ADID + "' marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no width='"+o.FileWidth +"' height='" + o.FileHeight + "' src='" + o.LinkUrl + "'>wait</iframe>";
        }
        return str;
    }
  }  
}
