
// Vertical scroll, used in rss reader
$("#marquee").ready(function () { 
    
    // Start scroll
    verticalScroll();
    
    $("#marquee").mouseover(function () { 
        // Stop scroll on mouse over
        stopVerticalScroll();
    }).mouseout(function(){
        // Start scroll on mouse out
        startVerticalScroll();
    });
    
});


var scrollSpeed = 1;
var scroll = true;
var timeout = '';

/**
* Function that scroll an element the same way as the html element marquee
*/
function verticalScroll() {
    clearTimeout(timeout);
    
    var marqueeElement = $("#marquee");
    
    
    var elementHeight = marqueeElement.height();

    var marqueeElementFirstChild = marqueeElement.children(":first");
    // Set margin top and bottom to the height of marquee element
    // This is done because scrolling should start on the bottom of div, and it should
    // not start over again before the div is scrolled empty
    marqueeElementFirstChild.css('margin',elementHeight+'px 0');
    
    //if(el.scrollTop >= el.scrollHeight-elementHeight){
    if(marqueeElement.scrollTop() >= marqueeElement[0].scrollHeight-elementHeight){
        marqueeElement.scrollTop(0);
    };
    
    var newScrollTop = marqueeElement.scrollTop() + scrollSpeed;
    
    marqueeElement.scrollTop(newScrollTop);
    
    if(scroll == true){
        timeout = setTimeout("verticalScroll()",50);
    };
}

/**
* Function that stops vertical scroll
*/
function stopVerticalScroll(){
    scroll = false;
}
/**
* Function that starts vertical scroll
*/
function startVerticalScroll(){
    scroll = true;
    verticalScroll();
}


