/** * @地方站窄通广告对象 * 使用iframe形式时,调用广告页的iframe的id必须为sinaAdvIframe,一个页面中只能有一个iframe调用 * @author liushuai@staff.sina.com.cn * @date 2010-02-11 * @version 1.2 * @改动 * 1.优化了鼠标滑过切换素材时需重新加载的BUG */ var sinaExtAdvObj = { oc:null, //初始状态容器 ec:null, //扩展状态容器 mc:null, //广告主容器 params:{ o:'', //初始状态素材 e:'', //扩展状态素材 t:'', //链接地址 ow:1000, //初始宽度 oh:45, //初始高度 ew:1000, //扩展宽度 eh:180 //扩展高度 }, init:function(o,e,t){ //初始化参数 this.params.o = o; this.params.e = e; this.params.t = t; //初始化初始状态容器 this.oc = document.createElement('div'); this.oc.id = 'oc'; this.oc.style.position = 'absolute'; this.oc.style.left = 0; this.oc.style.top = 0; this.oc.style.zIndex = 9; this.oc.style.width = this.params.ow + 'px'; this.oc.style.height = this.params.oh + 'px'; this.oc.style.display = 'block'; this.oc.style.cursor = 'pointer'; this.oc.onmouseover = this.extend; //初始化扩展状态容器 this.ec = document.createElement('div'); this.ec.id = 'ec'; this.ec.style.position = 'absolute'; this.ec.style.left = 0; this.ec.style.top = 0; this.ec.style.zIndex = 8; this.ec.style.width = this.params.ew + 'px'; this.ec.style.height = this.params.eh + 'px'; this.ec.style.display = 'block'; this.ec.style.cursor = 'pointer'; this.ec.onmouseout = this.shrink; }, initObj:function(id,s,u,w,h){ var lst = s.substring(s.length-3).toLowerCase(); switch(lst){ case "swf": var to = document.createElement("div"); var fo = new sinaFlash( s, id, w, h, "7", "", false, "High"); fo.addParam("wmode", "transparent"); fo.addParam("allowScriptAccess", "always"); fo.addParam("menu", "false"); fo.write(to); break; case "jpg": case "gif": case "png": if(u!=""){ var to = document.createElement("a"); to.href = u; to.target = "_blank"; var io = new Image(); io.id = id; io.style.width = w+"px"; io.style.height = h+"px"; io.style.border = "none"; io.src = s; to.appendChild(io); }else{ var to = new Image(); to.id = id; to.style.width = w+"px"; to.style.height = h+"px"; to.style.border = "none"; to.style.cursor = "pointer"; to.src = s; } break; default: var to = document.createElement("a"); to.id = id; to.href = u; to.target = "_blank"; to.innerText = s; } return to; }, extend:function(){ this.parentNode.childNodes[0].style.zIndex = 8; this.parentNode.childNodes[1].style.zIndex = 9; this.parentNode.style.width = this.parentNode.childNodes[1].style.width; this.parentNode.style.height = this.parentNode.childNodes[1].style.height; if(self != top){//若广告为iframe形式,则修改iframe尺寸,此iframe的id必须为sinaAdvIframe top.document.getElementById('sinaAdvIframe').width = this.parentNode.childNodes[1].style.width; top.document.getElementById('sinaAdvIframe').height = this.parentNode.childNodes[1].style.height; } }, shrink:function(){ this.parentNode.childNodes[0].style.zIndex = 9; this.parentNode.childNodes[1].style.zIndex = 8; this.parentNode.style.width = this.parentNode.childNodes[0].style.width; this.parentNode.style.height = this.parentNode.childNodes[0].style.height; if(self != top){ top.document.getElementById('sinaAdvIframe').width = this.parentNode.childNodes[0].style.width; top.document.getElementById('sinaAdvIframe').height = this.parentNode.childNodes[0].style.height; } }, write:function(cid){ if(document.getElementById(cid)){ this.mc = document.getElementById(cid); //设置主容器样式 this.mc.style.position = 'relative'; this.mc.style.overflow = 'hidden'; this.mc.style.width = this.oc.style.width; this.mc.style.height = this.oc.style.height; var oObj = this.initObj('orialObj',this.params.o,this.params.t,this.params.ow,this.params.oh); var eObj = this.initObj('extendObj',this.params.e,this.params.t,this.params.ew,this.params.eh); this.oc.appendChild(oObj); this.ec.appendChild(eObj); this.mc.appendChild(this.oc); this.mc.appendChild(this.ec); }else{ return false; } } }