﻿/*
* 显示顶部动画广告
* (c) jiang zheng 2009.09.30
* QQ: 470192616
*/

/*
    
new JzTopAnimal('xyz',500,319,3).Init(); //把div层xyz设置成顶部动画显示，宽度500像素，高度319像素，停留3秒钟后消失
    
手动关闭时才需要使用下面的关闭按钮样式
<style>
.JzTopAnimalBtn {position:absolute; width:40px; height:20px; cursor:pointer; line-height:20px; background-color:#FFFFFF; border:solid 1px #CCCCCC; text-align:center; right:5px;top:5px;}
</style>
    
*/

function JzTopAnimal(divIdStr, width, height, keepSeconds) {
    //顶部广告展示信息	
    this.divIdStr = divIdStr;
    this.Height = height; //显示高度
    this.KeepSeconds = keepSeconds * 1000; //停留的时间
    this.scrollTmp = 0;
    this.anTimer = null;
    this.anPanel = $(divIdStr);

    this.anPanel.style.display = 'none';
    this.anPanel.style.overflow = 'hidden';
    this.anPanel.style.position = 'relative';
    this.anPanel.style.height = '0px';
    this.anPanel.style.width = width + 'px';
    this.anPanel.style.margin = '0 auto';
}

JzTopAnimal.prototype.Init = function() {
    //初始化
    var me = this;

    /*
    //这里自动关闭，不用手动关闭
    var st = me.anPanel.innerHTML;		
    var d = document.createElement('div');
    d.innerHTML = st;		
	
	var btn = document.createElement('div');
    btn.className = 'JzTopAnimalBtn';
    btn.innerHTML = '关闭';
    btn.onclick = function(){me.Hide();};
		
	me.anPanel.innerHTML = '';
    me.anPanel.appendChild(btn);
    me.anPanel.appendChild(d);
    */

    me.anPanel.style.display = 'block';
    me.anTimer = setTimeout(function() {
        me.Show();
    }, 1000);
};

JzTopAnimal.prototype.Show = function() {
    //显示
    var me = this;
    if (me.scrollTmp + 10 < me.Height) {
        me.scrollTmp = me.scrollTmp + 10;
        me.anPanel.style.height = me.scrollTmp + "px";
        me.anTimer = setTimeout(function() {
            me.Show();
        }, 1);
    } else {
        me.anPanel.style.height = me.Height + "px";
        clearTimeout(me.anTimer);
        me.anTimer = setTimeout(function() {
            me.Hide();
        }, me.KeepSeconds);
    }
};

JzTopAnimal.prototype.Hide = function() {
    //隐藏
    var me = this;
    if (me.Height - 10 > 0) {
        me.Height = me.Height - 10;
        me.anPanel.style.height = me.Height + "px";
        me.anTimer = setTimeout(function() {
            me.Hide();
        }, 1);
    } else {
        me.anPanel.style.height = "0px";
        me.anPanel.style.display = 'none';
        clearTimeout(me.anTimer);
    }

};
