$(function() {
    var so1 = $("#so1");
    if(so1 != undefined){
        so1.everyTime(3000,function(){
            ProductScroll($(this).attr('id'));
        }).mouseover(function(){
            $(this).stopTime();
        }).mouseout(function(){
            $(this).everyTime(3000,function(){
                ProductScroll($(this).attr('id'));
            });
        });
    }
    var so2 = $("#so2");
    if(so2 != undefined){
        so2.everyTime(3000,function(){
            ProductScroll($(this).attr('id'));
        }).mouseover(function(){
            $(this).stopTime();
        }).mouseout(function(){
            $(this).everyTime(3000,function(){
                ProductScroll($(this).attr('id'));
            });
        });
    }
});

function ProductScroll(id) {
    var curTop = parseInt($("#" + id + " div.items").css('top'));
    curTop = (curTop > 0) ? curTop : 0;
    
    var itemHeight = parseInt($("#" + id + " div.items div.product:eq(0)").height());
    if(itemHeight > 0){
    
        var newTop = curTop - itemHeight - 10;
        $("#" + id + " div.items").animate({ top: newTop + 'px' },2000,function(){
            $("#" + id + " div.items div.product:eq(0)").appendTo($(this));
            $(this).css('top',curTop);
        });
    }
}

