﻿/*
* 企业专区广告构造函数
* 版本：1.0.0
*
* 配置方法示例：
* var slidebanner01 = new _slidebanner();
* slidebanner01.config.type = "gold"; //专区类型：gold|silver
* slidebanner01.config.time = 5000; //自动播放间隔，单位：毫秒
* slidebanner01.config.slide = false; //是否轮播：true|false
* slidebanner01.config.random = false; //是否随机：true|false
*
* //广告数据 begin
* slidebanner01.config.ads[0].bSrc = "images/001_470x80.jpg"; //大图或Flash，尺寸：470x80
* slidebanner01.config.ads[0].sSrc = "images/001_80x80.jpg"; //小图或Flash，尺寸：80x80
* slidebanner01.config.ads[0].links = "#"; //链接，大小图资源均为Flash时，可不填
*
* slidebanner01.config.ads[1].bSrc = "images/001_470x80.jpg";
* slidebanner01.config.ads[1].sSrc = "images/001_80x80.jpg";
* slidebanner01.config.ads[1].links = "http://www.sina.com.cn";
*
* slidebanner01.config.ads[2].bSrc = "images/001_470x80.jpg";
* slidebanner01.config.ads[2].sSrc = "images/001_80x80.jpg";
* slidebanner01.config.ads[2].links = "#";
*
* slidebanner01.config.ads[3].bSrc = "images/001_470x80.jpg";
* slidebanner01.config.ads[3].sSrc = "images/001_80x80.jpg";
* slidebanner01.config.ads[3].links = "#";
*
* slidebanner01.config.ads[4].bSrc = "http://d5.sina.com.cn/201008/27/247040.swf";
* slidebanner01.config.ads[4].sSrc = "http://d5.sina.com.cn/201008/27/247040.swf";
* slidebanner01.config.ads[4].links = "";
* //广告数据 end
*
* slidebanner01.initialization("slidebanner"); //初始化
*/
function _slidebanner() {
  this.config = {
    type: "gold",
    time: 5000,
    slide: true,
    random: true,
    ads: [this[0] = {
      bSrc: "",
      sSrc: "",
      links: ""
    },
		this[1] = {
		  bSrc: "",
		  sSrc: "",
		  links: ""
		},
		this[2] = {
		  bSrc: "",
		  sSrc: "",
		  links: ""
		},
		this[3] = {
		  bSrc: "",
		  sSrc: "",
		  links: ""
		},
		this[4] = {
		  bSrc: "",
		  sSrc: "",
		  links: ""
		},
		this[5] = {
		  bSrc: "",
		  sSrc: "",
		  links: ""
		}],
    asset: {
      goldBannerBackground: "url(http://d1.sina.com.cn/shh/ws/2010/12/28/slidebanner_bg_04.png) no-repeat",
      silverBannerBackground: "url(http://d1.sina.com.cn/shh/ws/2010/12/28/slidebanner_bg_04.png) no-repeat",
      box80x80Background: "url(http://d1.sina.com.cn/shh/ws/2010/12/28/slidebanner_bg_is4.png) no-repeat 1px 0",
      box470x80Background: "url(http://d1.sina.com.cn/shh/ws/2010/12/28/slidebanner_bg_ib4.png) no-repeat 1px 0"
    }
  }
};
_slidebanner.prototype = {
  version: "1.0.0",
  author: "wangshuo",
  email: "nbagonet@gmail.com",
  initialization: function (innerId) {
    var t = this;
    var writeIt = function () {
      var strRegex_img = "(.jpg|.JPG|.gif|.GIF|.png|.PNG)$";
      var re_img = new RegExp(strRegex_img);
      var strRegex_swf = "(.swf|.SWF)$";
      var re_swf = new RegExp(strRegex_swf);
      var boxId = "slidebanner_" + (new Date()).getTime();
      var html = "";
      html += '<style type="text/css">#' + boxId + ' .selected{display:none}</style>';
      html += '<div id="' + boxId + '" style="width:950px; height:90px; overflow:hidden;">';
      html += '	<div style="width:99px; height:90px; overflow:hidden; float:left;"></div>';
      html += '	<div style="width:851px; height:90px; overflow:hidden; float:left;">';
      for (var i = 0; i < t.config.ads.length; i++) {
        html += '<div id="' + boxId + '_btn' + i + '" style="width:90px; height:90px; overflow:hidden; float:left; background:' + t.config.asset.box80x80Background + '; padding-left:1px;">';
        if (re_img.test(t.config.ads[i].sSrc)) {
          html += '<a href="' + t.config.ads[i].links + '" target="_blank"><img src="' + t.config.ads[i].sSrc + '" width="80" height="80" style="margin:5px" alt="" border="0" /></a>'
        } else if (re_swf.test(t.config.ads[i].sSrc)) {
          html += '<div style="padding:5px"><object width="80" height="80" type="application/x-shockwave-flash" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="' + boxId + 'btn' + i + '_swf">';
          html += '<param value="' + t.config.ads[i].sSrc + '" name="movie"><param value="High" name="quality"><param value="opaque" name="wmode"><param value="always" name="allowscriptaccess">';
          html += '<embed width="80" height="80" allowscriptaccess="always" wmode="opaque" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="High" src="' + t.config.ads[i].sSrc + '" id="' + boxId + 'btn' + i + '_swf">';
          html += '</object></div>'
        }
        html += '</div>';
        html += '<div id="' + boxId + '_con' + i + '" style="width:392px; height:90px; overflow:hidden; float:left; background:' + t.config.asset.box470x80Background + '; padding-left:1px; display:none;">';
        if (re_img.test(t.config.ads[i].bSrc)) {
          html += '<a href="' + t.config.ads[i].links + '" target="_blank"><img src="' + t.config.ads[i].bSrc + '" width="382" height="80" style="margin:5px" alt="" border="0" /></a>'
        } else if (re_swf.test(t.config.ads[i].bSrc)) {
          html += '<div style="padding:5px"><object width="382" height="80" type="application/x-shockwave-flash" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="' + boxId + 'btn' + i + '_swf">';
          html += '<param value="' + t.config.ads[i].bSrc + '" name="movie"><param value="High" name="quality"><param value="opaque" name="wmode"><param value="always" name="allowscriptaccess">';
          html += '<embed width="382" height="80" allowscriptaccess="always" wmode="opaque" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="High" src="' + t.config.ads[i].bSrc + '" id="' + boxId + 'btn' + i + '_swf">';
          html += '</object></div>'
        }
        html += '</div>'
      }
      html += '	</div>';
      html += '</div>';
      document.getElementById(innerId).innerHTML = html;
      if (t.config.type == "gold") {
        document.getElementById(boxId).style.background = t.config.asset.goldBannerBackground
      } else if (t.config.type == "silver") {
        document.getElementById(boxId).style.background = t.config.asset.silverBannerBackground
      }
      if (typeof (SubShowClass) == "function") {
        var SubShow = new SubShowClass("none", "onmouseover");
        SubShow.addLabel(boxId + '_btn0', boxId + '_con0', "", "document.getElementById('" + boxId + "_btn0').style.display='none'", "document.getElementById('" + boxId + "_btn0').style.display='block'");
        SubShow.addLabel(boxId + '_btn1', boxId + '_con1', "", "document.getElementById('" + boxId + "_btn1').style.display='none'", "document.getElementById('" + boxId + "_btn1').style.display='block'");
        SubShow.addLabel(boxId + '_btn2', boxId + '_con2', "", "document.getElementById('" + boxId + "_btn2').style.display='none'", "document.getElementById('" + boxId + "_btn2').style.display='block'");
        SubShow.addLabel(boxId + '_btn3', boxId + '_con3', "", "document.getElementById('" + boxId + "_btn3').style.display='none'", "document.getElementById('" + boxId + "_btn3').style.display='block'");
        SubShow.addLabel(boxId + '_btn4', boxId + '_con4', "", "document.getElementById('" + boxId + "_btn4').style.display='none'", "document.getElementById('" + boxId + "_btn4').style.display='block'");
        SubShow.addLabel(boxId + '_btn5', boxId + '_con5', "", "document.getElementById('" + boxId + "_btn5').style.display='none'", "document.getElementById('" + boxId + "_btn5').style.display='block'");
        if (t.config.random == true) {
          SubShow.random(1, 1, 1, 1, 1, 1);
        }
        if (t.config.slide == true) {
          SubShow.play(t.time);
        }
      }
    };
    /*var loadScript = function(id, fileUrl) {
    var scriptTag = document.getElementById(id);
    var oHead = document.getElementsByTagName('HEAD').item(0);
    var oScript = document.createElement("script");
    oScript.id = id;
    oScript.type = "text/javascript";
    oScript.src = fileUrl;
    oHead.appendChild(oScript);
    oScript.onreadystatechange = function() {
    if (oScript.readyState == "loaded") {
    writeIt()
    }
    };
    oScript.onload = writeIt;
    document.body.insertBefore(oScript, null)
    };
    loadScript("subshowclass_script", "http://news.sina.com.cn/js/ui/subshowclass_v1.3.js")*/
    writeIt();
  }
};



function SubShowClass(ID, eventType, defaultID, openClassName, closeClassName) { var t = this; this.parentObj = this.$(ID); if (this.parentObj == null && ID != "none") { throw new Error("SubShowClass(ID)参数错误:ID 对像不存在!(value:" + ID + ")") }; this.lock = false; this.label = []; this.defaultID = defaultID == null ? 0 : defaultID; this.selectedIndex = this.defaultID; this.openClassName = openClassName == null ? "selected" : openClassName; this.closeClassName = closeClassName == null ? "" : closeClassName; this.mouseIn = false; var mouseInFunc = function () { t.mouseIn = true }; var mouseOutFunc = function () { t.mouseIn = false }; if (ID != "none" && ID != "") { if (this.parentObj.attachEvent) { this.parentObj.attachEvent("onmouseover", mouseInFunc) } else { this.parentObj.addEventListener("mouseover", mouseInFunc, false) } }; if (ID != "none" && ID != "") { if (this.parentObj.attachEvent) { this.parentObj.attachEvent("onmouseout", mouseOutFunc) } else { this.parentObj.addEventListener("mouseout", mouseOutFunc, false) } }; if (typeof (eventType) != "string") { eventType = "onmousedown" }; eventType = eventType.toLowerCase(); switch (eventType) { case "onmouseover": this.eventType = "mouseover"; break; case "onmouseout": this.eventType = "mouseout"; break; case "onclick": this.eventType = "click"; break; case "onmouseup": this.eventType = "mouseup"; break; default: this.eventType = "mousedown" }; this.autoPlay = false; this.autoPlayTimeObj = null; this.spaceTime = 5000 }; SubShowClass.prototype = { version: "1.31", author: "mengjia", _setClassName: function (obj, type) { var temp; temp = obj.className; if (temp) { temp = temp.replace(this.openClassName, ""); temp = temp.replace(this.closeClassName, ""); temp += " " + (type == "open" ? this.openClassName : this.closeClassName) } else { temp = (type == "open" ? this.openClassName : this.closeClassName) }; obj.className = temp }, addLabel: function (labelID, contID, parentBg, springEvent, blurEvent) { var t = this; var labelObj = this.$(labelID); var contObj = this.$(contID); if (labelObj == null && labelID != "none") { throw new Error("addLabel(labelID)参数错误:labelID 对像不存在!(value:" + labelID + ")") }; var TempID = this.label.length; if (parentBg == "") { parentBg = null }; this.label.push([labelID, contID, parentBg, springEvent, blurEvent]); var tempFunc = function () { t.select(TempID) }; if (labelID != "none") { if (labelObj.attachEvent) { labelObj.attachEvent("on" + this.eventType, tempFunc) } else { labelObj.addEventListener(this.eventType, tempFunc, false) } }; if (TempID == this.defaultID) { if (labelID != "none") { this._setClassName(labelObj, "open") }; if (this.$(contID)) { contObj.style.display = "" }; if (this.ID != "none") { if (parentBg != null) { this.parentObj.style.background = parentBg } }; if (springEvent != null) { eval(springEvent) } } else { if (labelID != "none") { this._setClassName(labelObj, "close") }; if (contObj) { contObj.style.display = "none" } }; var mouseInFunc = function () { t.mouseIn = true }; var mouseOutFunc = function () { t.mouseIn = false }; if (contObj) { if (contObj.attachEvent) { contObj.attachEvent("onmouseover", mouseInFunc) } else { contObj.addEventListener("mouseover", mouseInFunc, false) }; if (contObj.attachEvent) { contObj.attachEvent("onmouseout", mouseOutFunc) } else { contObj.addEventListener("mouseout", mouseOutFunc, false) } } }, select: function (num, force) { if (typeof (num) != "number") { throw new Error("select(num)参数错误:num 不是 number 类型!(value:" + num + ")") }; if (force != true && this.selectedIndex == num) { return }; var i; for (i = 0; i < this.label.length; i++) { if (i == num) { if (this.label[i][0] != "none") { this._setClassName(this.$(this.label[i][0]), "open") }; if (this.$(this.label[i][1])) { this.$(this.label[i][1]).style.display = "" }; if (this.ID != "none") { if (this.label[i][2] != null) { this.parentObj.style.background = this.label[i][2] } }; if (this.label[i][3] != null) { eval(this.label[i][3]) } } else if (this.selectedIndex == i || force == true) { if (this.label[i][0] != "none") { this._setClassName(this.$(this.label[i][0]), "close") }; if (this.$(this.label[i][1])) { this.$(this.label[i][1]).style.display = "none" }; if (this.label[i][4] != null) { eval(this.label[i][4]) } } }; this.selectedIndex = num }, random: function () { if (arguments.length != this.label.length) { throw new Error("random()参数错误:参数数量与标签数量不符!(length:" + arguments.length + ")") }; var sum = 0, i; for (i = 0; i < arguments.length; i++) { sum += arguments[i] }; var randomNum = Math.random(), percent = 0; for (i = 0; i < arguments.length; i++) { percent += arguments[i] / sum; if (randomNum < percent) { this.select(i); break } } }, order: function () { if (arguments.length != this.label.length) { throw new Error("order()参数错误:参数数量与标签数量不符!(length:" + arguments.length + ")") }; if (!(/^\d+$/).test(SubShowClass.sum)) { return }; var count = 0, i; for (i = 0; i < arguments.length; i++) { count += arguments[i] }; var num = SubShowClass.sum % count; if (num == 0) { num = count }; var sum = 0; for (i = 0; i < arguments.length; i++) { sum += arguments[i]; if (sum >= num) { this.select(i); break } } }, play: function (spTime) { var t = this; if (typeof (spTime) == "number") { this.spaceTime = spTime }; clearInterval(this.autoPlayTimeObj); this.autoPlayTimeObj = setInterval(function () { t.autoPlayFunc() }, this.spaceTime); this.autoPlay = true }, autoPlayFunc: function () { if (this.autoPlay == false || this.mouseIn == true) { return }; this.nextLabel() }, nextLabel: function () { var t = this; var index = this.selectedIndex; index++; if (index >= this.label.length) { index = 0 }; this.select(index); if (this.autoPlay == true) { clearInterval(this.autoPlayTimeObj); this.autoPlayTimeObj = setInterval(function () { t.autoPlayFunc() }, this.spaceTime) } }, previousLabel: function () { var t = this; var index = this.selectedIndex; index--; if (index < 0) { index = this.label.length - 1 }; this.select(index); if (this.autoPlay == true) { clearInterval(this.autoPlayTimeObj); this.autoPlayTimeObj = setInterval(function () { t.autoPlayFunc() }, this.spaceTime) } }, stop: function () { clearInterval(this.autoPlayTimeObj); this.autoPlay = false }, $: function (objName) { if (document.getElementById) { return eval('document.getElementById("' + objName + '")') } else { return eval('document.all.' + objName) } } }; SubShowClass.readCookie = function (l) { var i = "", I = l + "="; if (document.cookie.length > 0) { var offset = document.cookie.indexOf(I); if (offset != -1) { offset += I.length; var end = document.cookie.indexOf(";", offset); if (end == -1) end = document.cookie.length; i = unescape(document.cookie.substring(offset, end)) } }; return i }; SubShowClass.writeCookie = function (O, o, l, I) { var i = "", c = ""; if (l != null) { i = new Date((new Date).getTime() + l * 3600000); i = "; expires=" + i.toGMTString() }; if (I != null) { c = ";domain=" + I }; document.cookie = O + "=" + escape(o) + i + c }; SubShowClass.sum = SubShowClass.readCookie("SSCSum"); if ((/^\d+$/).test(SubShowClass.sum)) { SubShowClass.sum++ } else { SubShowClass.sum = 1 }; SubShowClass.writeCookie("SSCSum", SubShowClass.sum, 12);
