var scroll_speed = 300;

function scroll_move(le_pas){
	var next_value = document.getElementById('afp_container').scrollTop + 1;
	var news_afp_height = document.getElementById('news_afp').offsetHeight;
	var afp_scroll_separator_height = document.getElementById('afp_scroll_separator').offsetHeight;
	
	// 15 et 15-5 pour les padding et tout le truc dans le genre
	if (next_value <= (news_afp_height+afp_scroll_separator_height+15+10-25)){
		document.getElementById('afp_container').scrollTop = document.getElementById('afp_container').scrollTop + le_pas;
	}else{
		document.getElementById('afp_container').scrollTop = 0;
	}
}

var intervalObj = null;
function start_scrolling(isTheFirstTime){
	if (isTheFirstTime){
		var container = document.getElementById('afp_container');
		container.innerHTML = container.innerHTML + '<p id="afp_scroll_separator"> - - - </p>' + container.innerHTML;
	}
	intervalObj = window.setInterval('scroll_move(1);', scroll_speed);
}

function stop_scrolling(){
	if (intervalObj){
		clearInterval(intervalObj);
		intervalObj = null;
	}
}

function findFirstChild(html_obj){
	var the_first = null;
	var childs = html_obj.childNodes;
	for (i=0; i<childs.length && the_first==null; i++){
		if (childs[i].nodeType == 1){
			the_first = childs[i];
		}
	}
	
	return the_first;
}
