/// <reference path="jquery-vsdoc.js" />
function newsScroller(contentDiv, speed, spaceBetween)
{
    contentDiv = "#"+contentDiv;
    var scrollSpeed = (speed==null) ? 5 : parseInt(speed);
//	var divHeight, divTop;

    // double make sure the autoScroller-container has the correct css position and overflow property
    $(contentDiv).parent().css({ position: 'relative', overflow: 'hidden' });

    // get contentDiv height
    contentDivHeight = $(contentDiv).height();


    // Do a copy of the content and add it after it, to get the rolling effect
    var originalDiv = $(contentDiv)
    var altDiv = originalDiv.clone();

    // set contentDiv style
    originalDiv.css({ position: 'absolute', top: 60 });

    // set altDiv style
    altDiv.css({ position: 'absolute', top: 60 + contentDivHeight + spaceBetween });

    //startTop = contentDivHeight + spaceBetween + "px";
    startTop = 60 + contentDivHeight + (spaceBetween * 2) + "px";

    // Add the content copy after the content, to get the rolling effect
    altDiv.insertAfter(originalDiv);

    originalDiv.everyTime(100, function(i) {
        scrollContent(originalDiv, contentDivHeight, scrollSpeed, startTop);
        scrollContent(altDiv, contentDivHeight, scrollSpeed, startTop);
    });
	
		// on mouse over event, pause the scroller
    $(contentDiv).parent().mouseover(function ()
    {
        speed = scrollSpeed;
        scrollSpeed = 0; 	
//		divHeight = $(contentDiv).height();
//		divTop = $(contentDiv).top();
		$(contentDiv).parent().css({ overflow: 'scroll'});
    });
    
    // on mouse out event, start the scroller
    $(contentDiv).parent().mouseout(function ()
    {
        scrollSpeed = speed;
		$(contentDiv).parent().css ({overflow: 'hidden'});
    });

/*
    originalDiv.mouseover(function ()
    {
        speed = scrollSpeed;
        scrollSpeed = 0; 	
//		divHeight = $(contentDiv).height();
//		divTop = $(contentDiv).top();
		$(contentDiv).parent().css({ overflow: 'scroll'});
    });
    
    // on mouse out event, start the scroller
    originalDiv.mouseout(function ()
    {
        scrollSpeed = speed;
		$(contentDiv).parent().css ({overflow: 'hidden'});
    });
	
    altDiv.mouseover(function ()
    {
        speed = scrollSpeed;
        scrollSpeed = 0; 	
//		divHeight = $(contentDiv).height();
//		divTop = $(contentDiv).top();
		$(contentDiv).parent().css({ overflow: 'scroll'});
    });
    
    // on mouse out event, start the scroller
    altDiv.mouseout(function ()
    {
        scrollSpeed = speed;
		$(contentDiv).parent().css ({overflow: 'hidden'});
    });
   */
}

function scrollContent(container, contentHeight, scrollContentSpeed, originalTop) {
    try {

        if (parseInt($(container).css('top')) > (contentHeight * (-1) - 60)) {
            // move scroller upwards
            offset = parseInt($(container).css('top')) - scrollContentSpeed + "px";
            $(container).css({ 'top': offset });
        }
        // reset to original position
        else {
            // reset to original position
            $(container).css({ 'top': originalTop });
        }
    }
    catch (error) {
    }

}