var scroll_global = true

// Voor Versie II van de homepage
//loop door alle links in div met id = source en toon inhoud in div met id = target
// gebruikt jQuery
//waitSeconds = aantal seconden wachten per bericht
//scrollIndex = teller; 
function scrollList( source, target, waitSeconds, scrollIndex, maxScrolls ) {
		
	var list = document.getElementById(source)
	 	
	if (list.childNodes[0] != null && scroll_global ) {				//childnodes[0] = UL node	
	
		//aList = <li><a></a></li>, <li><a></a></li>, ...
		var aList = list.childNodes[0].childNodes	//alle <a> tags binnen div 'list'

		if (aList=="undefined" || aList==null || aList.length==0) return;
				
		//ind = index van de getoonde link		
		var ind = (scrollIndex==null || scrollIndex=="undefined")? 0 : scrollIndex
		if (ind == aList.length) ind = 0
		
		//maxIter = aantal iteraties; stoppen na 10 keer door lijst te zijn gelopen 
		var maxIter = (maxScrolls==null || maxScrolls=="undefined")? 0 : maxScrolls
		if (maxIter == 9) scroll_global = false
											
		var newsLink = aList[ind].childNodes[0].href
						
				
		//haal nieuwsbericht op; speciale form in nieuwsdb hiervoor gemaakt  => zie form-formula in view NewsForHPTab	
		var jQueryLink = NewsDb + "/luNieuwsOpHomepage/" + newsLink.substring( newsLink.indexOf("#")+8, newsLink.length)
						
		$.get( jQueryLink, function(nieuwsbericht) {
												
			if (ind == aList.length-1) maxIter += 1
															
			$("#" + target).html(nieuwsbericht);
																					
			if (waitSeconds != 0) {
			
				if (waitSeconds < 0) waitSeconds = -waitSeconds			
			
				setTimeout(
					"scrollList(\"" +  source + "\", \"" + target + "\", \"" + waitSeconds + "\", " + (parseInt(ind)+1) + ", " + maxIter + ")",
					1000 * parseInt( waitSeconds )
				)
			}	
				
			//vorige link deactiveren in het linkertab (pijl weghalen)
			if (ind==0) 
				aList[aList.length-1].childNodes[0].className = "tabHPLinks"				
			else 
				aList[ind-1].childNodes[0].className = "tabHPLinks"
							
			//huidige link activeren in het linkertab (pijl tonen) 
			aList[ind].childNodes[0].className = "tabHPLinks_active"
								
		})
	} 
}

//open bericht in rechter tab - functie wordt aangeroepen na gebruikers-click in lijst in linker tab
//target = 'mondzorgbericht' of 'actueelbericht' (bericht aan de rechterkant)
//source = 'mondzorglijst' of 'actueellijst'  (lijst met links aan de linkerkant)
function openHPBericht( alink, link, target, source ) {

	//open bericht in target
	$.get( NewsDb + "/luNieuwsOpHomepage/" + link , function(nieuwsbericht) {
		$(target).html(nieuwsbericht); 
	})
	
	//deactiveer alle links 
	var list = document.getElementById(source)
	var aList = list.childNodes[0].childNodes
		
	for (x=0; x < aList.length; x++)
		aList[x].childNodes[0].className = "tabHPLinks"
		
	//activeer geklikte link	
	alink.className = "tabHPLinks_active"
	
	//zet het scrollen stop
	scroll_global = false				
	
	return false					//voer de href niet uit!  
}
