﻿// JScript 文件
function SetCookie(name,value)
{
    var Mins = 30; 
    var exp  = new Date();   
    exp.setTime(exp.getTime() + Mins*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//取cookies函数        
{
    var arr =document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;

}


function AdTopChange(Obj,RightOrLeft)
{
    if(typeof(Obj)=="string")
    {
        this.AdLayerControl=document.getElementById(Obj);
    }
    else
    {
        this.AdLayerControl=Obj;
    }
    this.Dock=RightOrLeft;
}

AdTopChange.prototype.Ini=function(y)
{
    this.AdLayerControl.style.posTop = -200;
    this.AdLayerControl.style.display = 'none'
    this.AdLayerControl.style.position="absolute";
    this.AdLayerControl.style.zIndex="1000";

    if(this.Dock=="left")
    {
        this.MoveLeftLayer(y);
    }
    else
    {
        this.MoveRightLayer();
    }
}

AdTopChange.prototype.MoveLeftLayer=function(screeny)
{
    var x = 3;
    var y = 100;// 左侧广告距离页首高度
    if(screeny!=undefined&&screeny!=0)
    {
        y=screeny;
    }
    var diff = (document.body.parentNode.scrollTop + y - this.AdLayerControl.style.posTop)*.40;
    var y = document.body.parentNode.scrollTop + y - diff;
    this.AdLayerControl.style.posTop=parseInt(y);
    this.AdLayerControl.style.posLeft=x;
    if(getCookie(this.AdLayerControl.id)!="none")
    {
        setTimeout("new AdTopChange('"+this.AdLayerControl.id+"').MoveLeftLayer("+screeny+");",500);
    }
    else
    {
         this.AdLayerControl.style.display = 'none';
    }
}

AdTopChange.prototype.MoveRightLayer=function()
{
    var x = 5;
    var y = 100;// 右侧广告距离页首高度
    var diff = (document.body.parentNode.scrollTop + y - this.AdLayerControl.style.posTop)*.40;
    var y = document.body.parentNode.scrollTop + y - diff;
    this.AdLayerControl.style.posTop=parseInt(y);
    this.AdLayerControl.style.posRight=x;
    if(getCookie("divLayerRight")!="none")
    {
        setTimeout("new AdTopChange('"+this.AdLayerControl.id+"').MoveRightLayer();",500);
    }
    else
    {
        this.AdLayerControl.style.display = 'none';
    }
}


//用法说明
//document.write("<div id=AdLayer1 style='visibility:hidden' ><a href='http://www.cnzz.cc' target='_blank'><img src=images/ad-01.gif border='0'></a></div>"
//+"<div id=AdLayer2 style='visibility:hidden;'><a href='http://www.cnzz.cc' target='_blank'><img src=images/ad-01.gif border='0'></a></div>");
////initEcAd()
//new AdTopChange("AdLayer1","left").Ini();
//new AdTopChange("AdLayer2","right").Ini();