﻿/*******************************************************************************
 *        程序 ID     ：    AdsManager
 *        程序名称    ：    广告管理类
 *        处 理       ：    广告管理类
 *        功 能       ：    广告管理类
 *
 *        修改履历
 *        年  月  日 区分 所 属/担 当        内 容                     对应编号
 *        ---------- ---- ------------------ ------------------------- --------
 *        2007/10/16 编写 Intasect/陈冬    新規作成
 *        2008/03/21 变更 Intasect/陈冬    对应课题                    综合.354
 * 
 * 
 *        Copyright ( C ) 2007 by Intasect communications(Chengdu), Co, Ltd.
 *        All rights reserved.
 *
********************************************************************************/
//画面左侧小广告类
var MiniAds = Class.create();
MiniAds.prototype = {
  initialize : function()
  {
    this.options = Object.extend(
    {
      fileType : null,
      fileUrl  : null,
      link     : null
    }, arguments[0] || {});
  },
  
  toHTML : function()
  {
    var result = "";
    result += "<div style=\"margin-top:8px;\">";
    if(this.options.link != "" && this.options.link != null)
    {
        result += "<a href=\""+this.options.link+"\" target=\"_blank\">";
    }
    switch(this.options.fileType)
    {
        case "img":
            
            result += "<img src=\"" + this.options.fileUrl + "\" width=\"160\" border=\"0\" />";
            
            break;
        case "flash":
            result += JSUtil.GetFlashHtml(this.options.fileUrl,160,80);
            break;
    }
    if(this.options.link != "" && this.options.link != null)
    {
        result += "</a>";
    }
    result += "</div>";
    return result;
  }
}

//主页广告类
var JydAd = Class.create();
JydAd.prototype = {
  initialize : function()
  {
    this.options = Object.extend(
    {
      id       : "",
      fileType : null,
      fileUrl  : null,
      link     : "",
      width    : 100,
      height   : 100
    }, arguments[0] || {});
  },
  
  Embed : function()
  {
      switch(this.options.fileType)
      {
          case "swf":
              AdsManager.EmbedFlash(this.options.fileUrl,this.options.width,this.options.height,this.options.link);
              break;
          case "jpg":
          case "gif":
              AdsManager.EmbedImg(this.options.fileUrl+"."+this.options.fileType,this.options.width,this.options.height,this.options.link);
              break;
          default :
              break;
      }
  }
}

//广告管理器
var AdsManager = {
    //主页广告数组
    ads : [],
    
    //添加广告到管理器
    AddAd : function(ad)
    {
        this.ads.push(ad);
        this.ads[ad.options.id] = ad;
    },
    
    //根据ID获取广告
    Get : function(id,route)
    {
        var obj = this.ads[id];
        if(obj != null && route != undefined)
        {
            obj.options.fileUrl = route + obj.options.fileUrl;
            if(obj.options.link != "" && obj.options.link.substring(0,4) != "http")
            {
                obj.options.link = route + obj.options.link;
            }
        }
        return obj;
    },
    
    //常驻小广告
    CONSTMiniAd : "<div style=\"margin-top:8px;\"><img src=\"img/v2/miniad1.gif\" width=\"160\" /></div>",
    
    GetMiniAds : function(strAds)
    {
        var result = AdsManager.CONSTMiniAd;
        var miniAdsArr = strAds.split(",");
        for(var i=0;i<miniAdsArr.length;i++){
            var adoption = miniAdsArr[i].split("::");
            var type = adoption[0];
            var url = adoption[1];
            var lnk = "";
            if(adoption.length == 3)
            {
                lnk = adoption[2];
            }
            var miniads = new MiniAds({fileType:type,fileUrl:url,link:lnk});
            result += miniads.toHTML();
        }
        return result;
    },
    
    //嵌入图片
    EmbedImg : function(imgurl,w,h,l)
    {
        if(l=="")
        {
            document.write("<div><img src=\""+imgurl+"\" width=\""+w+"\" height=\""+h+"\" /></div>");
        }else{
            document.write("<div><a href=\""+l+"\" target=\"_blank\"><img src=\""+imgurl+"\" width=\""+w+"\" height=\""+h+"\" border=\"0\" /></a></div>");
        }
    },
    
    //嵌入FLASH
    EmbedFlash : function(swfurl,w,h,l)
    {
        AC_FL_RunContent(
            'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
            'width', w,
            'height', h,
            'src', swfurl,
            'quality', 'high',
            'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
            'align', 'middle',
            'play', 'true',
            'loop', 'true',
            'scale', 'showall',
            'wmode', 'window',
            'devicefont', 'false',
            'id', 'jydflash',
            'bgcolor', '#ffffff',
            'name',swfurl,
            'menu', 'true',
            'allowFullScreen', 'false',
            'allowScriptAccess','sameDomain',
            'movie', swfurl,
            'salign',''
        );
    }
}

//将主页广告添加到集合

AdsManager.AddAd(new JydAd({id:"ad1",fileType:"swf",fileUrl:"img/ads/ad1",width:742,height:65, link:""}));
AdsManager.AddAd(new JydAd({id:"ad2",fileType:"gif",fileUrl:"img/ads/ad2",width:733,height:95, link:""}));
AdsManager.AddAd(new JydAd({id:"ad3",fileType:"swf",fileUrl:"img/ads/ad3",width:488,height:95, link:""}));
AdsManager.AddAd(new JydAd({id:"ad4",fileType:"gif",fileUrl:"img/ads/ad4",width:238,height:95, link:"aspx/ask/WebAsk.aspx"}));
AdsManager.AddAd(new JydAd({id:"ad5",fileType:"gif",fileUrl:"img/ads/ad5",width:238,height:137,link:""}));
AdsManager.AddAd(new JydAd({id:"ad6",fileType:"swf",fileUrl:"img/ads/ad6",width:978,height:95, link:""}));
AdsManager.AddAd(new JydAd({id:"ad7",fileType:"gif",fileUrl:"img/ads/ad7",width:733,height:95, link:""}));
AdsManager.AddAd(new JydAd({id:"ad8",fileType:"gif",fileUrl:"img/ads/ad8",width:238,height:95, link:""}));
AdsManager.ads = $H(AdsManager.ads);
