﻿
function ScrollText(text, fn, time) {  
    this.text = text;  
    this.fn = fn;  
    this.time = time || 1500;  
}  

ScrollText.prototype.start = function() {  
    var s = this.text;  
    var fn = this.fn;  
    clearInterval(this.interval);  
    this.interval = setInterval(function() {  
        var nowt = s.shift();
        fn(nowt);
        s.push(nowt); 
    }, this.time);  
};  

ScrollText.prototype.stop = function() {  
    clearInterval(this.interval);  
};  

var scrollText

function whoBuy(){
    var buys = [];
	 $.getJSON("/api/userpro.aspx?jsoncallback=?&"+Math.random(),
			{"action":"topUserBuy"},
			function(json){
				for(var i=0;i<json.length;i++)
				{
					buys.push(json[i].busername+"<i class=\"ml5\">订阅了</i><a href=\"/book/"+json[i].bookid+"\" target=\"_blank\">《"+json[i].booktitle+"》</a>");
				}
                scrollText = new ScrollText(buys, function(t) {  
                    $("#whobuy").html(t);
                });
                scrollText.start();
	});		
}

whoBuy();

$(function() {
    $("#whobuy").bind("mouseover", function() {scrollText.stop();});
    $("#whobuy").bind("mouseout", function() {scrollText.start();});
});



