﻿(function($) {
    $.fn.extend({
        Scroll: function(option, callback) {
            //参数初始化
            if (!option) var option = {};
            var _this = this.eq(0).find('ul:first');
            var _lineHeight = _this.find("li:first").height(), //获取行高
            _line = option.line ? parseInt(option.line, 10) : parseInt(this.height() / _lineHeight, 10), //每次滚动的行数，默认为一屏，即父容器高度
            _speed = option.speed ? parseInt(option.speed, 10) : 500, //卷动速度，数值越大，速度越慢（毫秒）
            _timer = option.timer ? parseInt(option.timer, 10) : 3000; //滚动的时间间隔（毫秒）
            if (_line == 0) _line = 1;
            var _height = 0 - _line * _lineHeight;
            //滚动函数
            scrollUp = function() {
                _this.animate({
                    marginTop: _height
                }, _speed, function() {
                for (_index = 1; _index <= _line * 2; _index++) {
                        _this.find("li:first").appendTo(_this);
                    }
                    _this.css({ marginTop: 0 });
                });
            }
            //鼠标事件绑定
            _this.hover(function() {
                clearInterval(timerID);
            }, function() {
                timerID = setInterval("scrollUp()", _timer);
            }).mouseout();
        }
    })
})(jQuery);


$(function() {
    $('#category > ul > li > a.item').click(function() {
        $('#category > ul > li > a.item').each(function() {
            $(this).removeClass('active');
        });
        $(this).addClass('active');
        $(this).blur();
        $('#type').val($(this).attr('title'));
    });

    $("#new").Scroll({ line: 2, timer: 5000, speed: 500 });

    $('#key').focus();
});
