//向左滚动函数，demo包含demo1与demo2,speed是滚动速度，flag一个网页内有多个时设置为不同的任意字符。
function toleft(demo,demo1,demo2,speed,flag){
	demo=document.getElementById(demo);
	demo1=document.getElementById(demo1);
	demo2=document.getElementById(demo2);
	demo2.innerHTML=demo1.innerHTML;
	function Marquee(){
		if(demo2.offsetWidth-demo.scrollLeft<=0){
			demo.scrollLeft-=demo1.offsetWidth;
		}
		else{
			demo.scrollLeft++;
		}
	}
	flag=setInterval(Marquee,speed);
	demo.onmouseover=function(){
		clearInterval(flag);
	}
	demo.onmouseout=function(){
		flag=setInterval(Marquee,speed);
	}
}
//向右滚动函数，demo包含demo1与demo2,speed是滚动速度，flag一个网页内有多个时设置为不同的任意字符。
function toright(demo,demo1,demo2,speed,flag){
	demo=document.getElementById(demo);
	demo1=document.getElementById(demo1);
	demo2=document.getElementById(demo2);
	demo2.innerHTML=demo1.innerHTML;
	function Marquee(){
		if(demo.scrollLeft<=0){
			demo.scrollLeft=demo2.offsetWidth;
		}
		else{
			demo.scrollLeft--;
		}
	}
	flag=setInterval(Marquee,speed);
	demo.onmouseover=function(){
		clearInterval(flag);
	}
	demo.onmouseout=function(){
		flag=setInterval(Marquee,speed);
	}
}

/*
 * 说明：基于jQuery编写, 实现列表的垂直滚动
 * 作者：Gavin
 * 创建时间：2008-10-27
 * 最后一次修改时间：2008-12-25
-------------------------------------------------------*/
(function($){
     var ELMS = [];
     $.fn.jdNewsScroll = function(settings) {
        settings = $.extend({}, arguments.callee.defaults, settings);
    $(this).css({"position":"relative","overflow":"hidden","width":settings.divWidth,"height":settings.divHeight});
    $(this).find("ul").css({"position":"relative","list-style-type":"none","font-size":settings.fontSize,"margin":"0px"});
    $(this).find("li").css({"line-height":"130%","margin":"0px","padding":"0"});
        $(this).each(function(){
            this.$settings = settings;
            this.$pause = false;
            this.$counter = settings.beginTime;
            $(this).hover(function(){ $(this).jdNewsScrollPause(true) }, function(){ $(this).jdNewsScrollPause(false) });
            ELMS.push(this);
        });
        return this;
    };
	//默认参数
    $.fn.jdNewsScroll.defaults = {
        beginTime: 20,
        fontSize: '12px',
        divWidth: '100%',
        divHeight: '200px',
        lineHeight: '130%',
        delay: 20,
        step: 8
    };
    $.fn.jdNewsScrollPause = function(pause) {
        return this.each(function() {
            this.$pause = pause;
        });
    }
    $.fn.outerHeight=function(options){
        if (!this[0]) 0;
        options = $.extend({ margin: false }, options || {});
        return this[0] == window || this[0] == document ?
            this.height() : this.is(':visible') ?
                this[0].offsetHeight + (options.margin ? (num(this, 'marginTop') + num(this, 'marginBottom')) : 0) :
                this.height() 
                    + num(this,'borderTopWidth') + num(this, 'borderBottomWidth') 
                    + num(this, 'paddingTop') + num(this, 'paddingBottom')
                    + (options.margin ? (num(this, 'marginTop') + num(this, 'marginBottom')) : 0);
    }

    setInterval(scroll, 80);
    function scroll() {
        for (var i = 0; i < ELMS.length; i++) {
            var elm = ELMS[i];
            if (elm && !elm.$pause) {
                if (elm.$counter == 0) {
                    var ul     = $('> ul', elm)[0];
                    if (!elm.$steps) {
                        elm.$steps = $('> li:first-child', ul).outerHeight();
                        elm.$step = 0;
                    }
                    if ((elm.$steps + elm.$step) <= 0) {
                        elm.$counter = elm.$settings.delay;
                        elm.$steps = false;
                        $(ul).css('top', '0').find('> li:last-child').after($('> li:first-child', ul));
                        $('> *', ul).not('li').remove();
                    } else {
                        elm.$step -= elm.$settings.step;
                        if (-elm.$step > elm.$steps) {
                            elm.$step = -elm.$steps;
                        }
                        ul.style.top = elm.$step + 'px';
                    }
                } else {
                    elm.$counter--;
                }
            }
        }
    };
})(jQuery);
