﻿// ==UserScript==
// @name                首页公告块的滚动
// @description         公告滚动
// @created date        2009/9/25   16:43
// @created author      Tiger(tigershi0507@gmail.com)
// @version             1.0.2
// @version owner       Copyright (C) 2009-2010 keerr.com All rights reserved.
// ==/UserScript==

/*************************************************
verified time 	:	2009/9/25   16:45
verified author	:	Tiger
verified purpose:	修改了鼠标一开后继续移动的回复时间长度
**************************************************/
function initScrollList(objName) {
    var Class = {
        create: function() {
            return function() {
                this.initialize.apply(this, arguments);
            }
        }
    };
    Function.prototype.bind = function(object) {
        var method = this;
        return function() {
            method.apply(object, arguments);
        }
    };
    var Scroll = Class.create();
    Scroll.prototype = {
        initialize: function(element, height) {
            this.element = $(element).get(0);
            this.element.innerHTML += this.element.innerHTML;
            this.height = height;
            this.maxHeight = this.element.scrollHeight / 2;
            this.counter = 0;
            this.scroll();
            this.timer = "";
            this.element.onmouseover = this.stop.bind(this);
            this.element.onmouseout = function() { this.timer = setTimeout(this.scroll.bind(this), 400); } .bind(this);
        },
        scroll: function() {
            if (this.element.scrollTop < this.maxHeight) {
                this.element.scrollTop++;
                this.counter++;
            } else {
                this.element.scrollTop = 0;
                this.counter = 0;
            }
            if (this.counter < this.height) {
                this.timer = setTimeout(this.scroll.bind(this), 20);
            } else {
                this.counter = 0;
                this.timer = setTimeout(this.scroll.bind(this), 3000);
            }
        },
        stop: function() {
            clearTimeout(this.timer);
        }
    };
    var myscroll = new Scroll(objName, 24);
}

$(function() {
    initScrollList(".notice");
});