/* global variables for functions */
    moveAmount = 3;
    moveDelay = 30; //in milliseconds
    scrollTimer = null;
/* end globals */

function showReach()
{
	document.getElementById('reach').style.display = 'block';
	return false;
}

function hideReach()
{
	document.getElementById('reach').style.display = 'none';
	return false;
}

function toggleReach()
{
	if( document.getElementById('reach').style.display != 'block' )
		return showReach();
	else
		return hideReach();
}

// goto page
// skip if default value
// see featured.html (zelle)
function gotoPage(url)
{
	if (url != '**')
		window.location = url;
}

//
function scrollNewsDown(speed, amount, norepeat)
{
	if(!speed)
		speed = moveDelay;
		
	if(!amount)
		amount = moveAmount;
		
	norepeat = !!norepeat;

	// reduce the margin of the top item
	var firstItem = $('#newsScroller li:first');
	
	topMargin = parseInt(firstItem.css('marginTop')) - amount;
	
	if(Math.abs(topMargin) > firstItem.outerHeight())
	{
		firstItem.css('marginTop', 0);
		firstItem.appendTo(firstItem.parent());
		return scrollNewsDown(speed, amount, norepeat)
	}
	else
		firstItem.css('marginTop', topMargin);
	
   	stopScroll();
   	if( !norepeat )
		scrollTimer = setTimeout("scrollNewsDown("+speed+","+amount+","+norepeat+")",speed);  
}
//
function scrollNewsUp(speed, amount, norepeat)
{
	if(!speed)
		speed = moveDelay;
		
	if(!amount)
		amount = moveAmount;
		
	norepeat = !!norepeat;

	// increase the margin of the top item
	var firstItem = $('#newsScroller li:first');
	
	var topMargin = parseInt(firstItem.css('marginTop')) + amount;
	
	// if this item is already flush with the top, leave it there
	if(topMargin > 0)
	{
		firstItem.css('marginTop', 0);
		
		//get the last item in the list
		var lastItem = $('#newsScroller li:last');
		
		// give it a negative margin equal to its height minus
		// whatever was left over from the scroll action
		lastItem
		.css('marginTop', 0-lastItem.outerHeight()+topMargin )
		.prependTo(lastItem.parent());
		
		return scrollNewsUp(speed, amount, norepeat)
	}
	else
		firstItem.css('marginTop', topMargin);
	
   	stopScroll();
   	
   	if( !norepeat )
		scrollTimer = setTimeout("scrollNewsUp("+speed+","+amount+","+norepeat+")",speed);  
}

function stopScroll()
{
    try{ clearTimeout(scrollTimer) } catch(error){ }
}



$( function(){
	if($('#newsScroller').outerHeight() > 80 )
		scrollNewsDown(100, 1)
	else
	{
		scrollNewsDown = scrollNewsUp = function(){};	
	}		
});
