
var Timer_State = {
    Start: 1,
    Stop: 2,
    Pause: 3
};
//expression 计时器要执行的脚本字符串
//interval 执行间隔 单位毫秒
//nMaxExeCount 执行次数 为 Number.POSITIVE_INFINITY 时不断执行
//bFirstExe 为true时先执行表达式然后再进行下一次计时，为false时先执行下一次的计时再执行表达式

function Timer(expression, interval, nMaxExeCount, bFirstExe) {

    if (Timer._Initialized == undefined) {

        //开始
        Timer.prototype.Start = function() {

            if (this.State == Timer_State.Start) return;
            this.State = Timer_State.Start;
            this.doStart();
        }

        Timer.prototype.doStart = function() {
            this.CreateExpressionTimer();
        }

        Timer.prototype.CreateExpressionTimer = function() {

            var exp = this.BuildExpression(this.Expression);
            this._Timer = setTimeout(exp, this.Interval);
        }

        //表达式执行完毕
        Timer.prototype.ExecuteComplete = function() {

            this.ExeCount++;

            if (this.MaxExeCount != Number.POSITIVE_INFINITY && this.ExeCount >= this.MaxExeCount) {
                this.Stop();
                return;
            }

            if (this.State == Timer_State.Start) this.CreateExpressionTimer();
        }

        //停止
        Timer.prototype.Stop = function() {

            if (this.State == Timer_State.Stop) return;
            this.State = Timer_State.Stop;
            this.doStop();

        }

        Timer.prototype.doStop = function() {

            this.ClearCheckPause();
            if (this._Timer == null) return;
            clearTimeout(this._Timer);
            this._Timer = null;
        }

        //暂停
        Timer.prototype.Pause = function(fCheckPause, checkInterval) {

            if (fCheckPause == null || typeof (fCheckPause) != "function") {
                throw "参数类型异常";
            }

            if (this.State == Timer_State.Stop) return;
            this.ClearCheckPause();

            this.State = Timer_State.Pause;
            this.CheckPauseHandler = fCheckPause;
            if (checkInterval == null) checkInterval = 500; 
            
            this.CheckInterval = checkInterval;

            this.doStop();

            this.doPause();
        }

        Timer.prototype.doPause = function() {

            this._CheckPauseTimer = setTimeout("Timer.CheckPause(" + this.Id + ");", this.CheckInterval);
        }

        Timer.prototype.CheckPause = function() {

            if (this.CheckPauseHandler == null) return;

            if (this.CheckPauseHandler()) {
                this.Resume();
            }
            else {
                this.doPause();
            }
        }

        Timer.prototype.ClearCheckPause = function() {
            if (this._CheckPauseTimer == null) return;
            clearTimeout(this._CheckPauseTimer);
            this._CheckPauseTimer = null;
            this.CheckPauseHandler = null;
        }

        //恢复
        Timer.prototype.Resume = function() {

            this.ClearCheckPause();
            if (this.State == Timer_State.Stop) return;
            
            this.Start();
        }

        Timer.prototype.BuildExpression = function(expression) {
            var str = "Timer.ExecuteComplete(" + this.Id + ");";
            var _expression = this.FirstExe ? (expression + ";" + str) : (str + expression);

            return _expression;
        }

        //释放资源
        Timer.prototype.Dispose = function() {

            this.Stop();
            this.Expression = null;
            this.CheckPauseHandler = null;
            Timer.Timers.Remove(this);
        }
    }

    if (interval == null || expression == null) {
        throw "缺少参数";
    }

    if (typeof (expression) != "string") {
        throw "参数类型不正确";
    }
    if (nMaxExeCount == null) nMaxExeCount = Number.POSITIVE_INFINITY;
    if (bFirstExe == null) bFirstExe = false;

    this.MaxExeCount = nMaxExeCount;
    this.ExeCount = 0;
    this.FirstExe = bFirstExe;
    this.Interval = interval;
    this.State = Timer_State.Stop;
    this._Timer = null;
    this.CheckInterval = 500;
    this.CheckPauseHandler = null;
    this._CheckPauseTimer = null;
    this.Id = Timer.GetNewId();
    this.Expression = expression;
    Timer.Timers.push(this);
}

//根据值取得索引
Array.prototype.IndexOf = function(oValue) {
    var count = this.length, value;

    for (var i = 0; i < count; i++) {
        if (this[i] == oValue) {
            return i;
        }
    }

    return -1;
}
//根据索引移除
Array.prototype.RemoveByIndex = function(iStartIndex, iDeleteCount) {
    if (iDeleteCount == null) iDeleteCount = 1;

    this.splice(iStartIndex, iDeleteCount);

    return this.length;
}

//移除项
Array.prototype.Remove = function(oValue) {
    var index = this.IndexOf(oValue);

    return this.RemoveByIndex(index);
}

Timer.Timers = new Array();

Timer.LastId = 0;
Timer.GetNewId = function() {

    ++Timer.LastId;

    return Timer.LastId;
}

Timer.GetTimerById = function(id) {

    var count = Timer.Timers.length;

    for (var i = 0; i < count; i++) {
        var timer = Timer.Timers[i];

        if (timer.Id == id) {
            return timer;
        }
    }

    return null;
}

Timer.ExecuteComplete = function(id) {

    var timer = Timer.GetTimerById(id);
    if (timer != null) timer.ExecuteComplete();
}

Timer.CheckPause = function(id) {

    var timer = Timer.GetTimerById(id);

    if (timer != null) timer.CheckPause();
}
//抖动效果
mfx=function(isWin){
	var t=0,z=4,del=function(){clearInterval(mfx.ID);return mfx};
	del().ID=setInterval(function(){
		var i=t/180*Math.PI,x=Math.sin(i)*z,y=Math.cos(i)*z,s=doudongk.style;
		isWin?window.moveBy(x,y):(s.top=x+'px',s.left=y+'px');
		if((t+=90)>1080)del();
	},30);
 
}
//启动事件
var timer = new Timer("mfx();",8000, Number.POSITIVE_INFINITY, false);
//timer.Stop(); //停止定时器
//timer.ExeCount = 0; //执行次数归零
//timer.MaxExeCount = 5; //改变最大执行次数
//timer.FirstExe = false; //改变执行顺序
//timer.Interval = 2000;  //改变执行间隔
//timer.Expression = "mfx()";   //改变表达式
timer.Start();  //启动定时器
function hide()  
{   
	document.getElementById("doudongk").style.visibility="hidden";
}
//固定在下方
var isie6 = window.XMLHttpRequest?false:true;
window.onload = function(){
    var guding = document.getElementById('dd');
   if(isie6){
         guding.style.position = 'absolute';
         window.onscroll = function(){
				guding.style.background = 'transparent';
          }
   }else{
      guding.style.position = 'fixed';
   }
     
      guding.style.bottom = '0';
}
//定义输出div
suspendcode="";
suspendcode="<div id='dd' style='position:absolute; right:0; bottom:0; width:218px; height:128px;z-index:2;overflow:hidden;'> \
  <div id='doudongk' style='float:left;width:214px; height:124px; position:relative; background:url(images/QQ.gif) no-repeat;' > \
    <a style='text-decoration:none; float:left; width:174px; height:20px;' title='成都协和耳鼻咽喉医院医生在线咨询' href='http://lut.zoosnet.net/LR/Chatpre.aspx?id=LUT62079707&lng=cn'  target='_blank'>&nbsp;</a> \
    <a style='float:right; width:40px; height:20px;text-decoration:none' onclick='javascript:window.hide();return false;' href='/' class=right_close></a>\
    <a style='text-decoration:none; float:left; width:100%; height:100%;' title='成都协和耳鼻咽喉医院医生在线咨询' href='http://lut.zoosnet.net/LR/Chatpre.aspx?id=LUT62079707&lng=cn'  target='_blank'>&nbsp;</a> \
  </div> \
</div>";
document.write(suspendcode);
