$(document).ready(function(){
  setTimeout('update_nieuwsflash()', 30000);		
});

function update_nieuwsflash()
{
	var child = '';
	var i = 1;
	var k = 0;
	$.ajax({
        type: "GET",
		url: "ajax/nieuwsflash.php?rnd="+Math.floor(Math.random()*9999),
		dataType: "xml",
		success: function(xml) {
			$(xml).find('nieuws').each(function(){
 				var id = $(this).attr('id');
				var title = jQuery.trim($(this).find('titel').text());
				var tijdstip = $(this).find('tijdstip').text();
				var bron = $(this).find('bron').text();
				
				var add = true;
				$("#nieuwsflash li").each(function(){
					var tmp_title = jQuery.trim($(this).find(".news-msg-txt a").html());
				    var tmp_source = jQuery.trim($(this).find(".news-msg-txt .news-bron").html());
				    
					if (tmp_title == title) {
						add = false;
						return false;
					}
				});
				
				if ( add ) {
					child = '<li class="nieuws-item">';
					child+= '    <div class="autowidth">';
                    child+= '        <div class="timestamp">'+ tijdstip +'</div>';
                    child+= '        <div class="news-msg-bron">';
                    child+= '            <div class="news-msg-txt">';
                    child+= '                <a href="Pages/Nieuws/artikel.php?artikel='+ id +'" target="_blank">';
                    child+= '                    '+ title;
					child+= '                </a>';
                    child+= '                <div class="news-bron">('+ bron +')</div>';
                    child+= '            </div>';
					child+= '        </div>';
					child+= '        <div class="clear"></div>';
                    child+= '    </div>';
                    child+= '</li>';
					$("#nieuwsflash").prepend(child);
					
					$("#nieuwsflash li:last-child").remove();
					k++;
				} else {
				    return false;
				}
				i++;
			})
			
			for (var j = 0; j < k; j++) {
				$("#nieuwsflash li:nth-child("+ (j + 1) +")").effect("highlight", {}, 3000);
			}
		}
	});

	setTimeout('update_nieuwsflash()', 60000);
}


