if (document.addEventListener) 
{
    document.addEventListener("DOMContentLoaded", onloadHandler, null);
}

var state;
var speaker_time;
var player;
var player_currentPosition;
var isFlash = false;

function playerReady(obj)
{
	player = document.getElementById(obj.id);
	if(!isFlash)
	{
		isFlash = true;
	}
	
	player.addModelListener("TIME", "timeupdate");
	
	setTimeout("set_speakers_timeindexes ();", 1000);
		
	if (typeof(ISLIVE) == 'undefined')
	{
		do_poll();
	}
	setTimeout("player_state();", 15000);
}

function player_state()
{
	MEETING = document.getElementById('meeting_object_id');	
	
	if (player.getConfig().state == "PLAYING" && MEETING)	
	{		
		MEETING 		= MEETING.value;
		var streamer 	= player.getConfig().streamer;
		aplx_call_by_uri("/modules/risbis/risbis.php?g=check_state&meeting="+MEETING+"&streamer="+streamer, MEETING,streamer, callback_player_state);
		return;
	}
	setTimeout("player_state();", 15000);
}

function callback_player_state(response)
{
	prohibited = document.getElementById("meeting_prohibited");
	if (prohibited)
	{
		if(response == "REFRESH")
		{
			location.reload(true);
		}
		
		if (response == "RESUMED" && prohibited.value == "1")
		{
			prohibited.value = "0"
			removeMessage();
			player.sendEvent("STOP", "true");
			player.sendEvent("PLAY", "true");
		}
		else if (response == "PROHIBITED")
		{			
			generateMessage();
			prohibited.value = "1"
		}
		setTimeout("player_state();", 15000);
	}
}

function generateMessage()
{
	var message = document.getElementById('message');
	if(!message)
	{
		var live = document.getElementById('live');
		var myElement = document.createElement('div');	
		myElement.className = 'message';	
		myElement.id = 'message';
		myElement.innerHTML = '<h2>Info</h2><p>Uitzending wordt momenteel besloten uitgezonden.</p>';
		live.parentNode.insertBefore(myElement,live);
	}
}

function removeMessage()
{
	var message = document.getElementById('message');
	if(message)
		message.parentNode.removeChild(message);	
}

// function stateListener (obj)
// {
	// if (obj.newstate == 'IDLE' && ISLIVE == 1 && document.getElementById('live'))
	// {
		// player.sendEvent("PLAY", "true");
	// }
// }

function timeupdate(event)
{
	player_currentPosition = event['position'];
}

function onloadHandler()
{
	live_uitzending();
	if( typeof(window.checkFlashVersion ) == 'function')
	{
		checkFlashVersion();
	}
}
// fallback
window.onload = onloadHandler;

function update_live			(response) {update_id('live_film', response); }
function update_film			(response) {clear_films();update_id('film_'+AGENDAPUNT_ID, response);process_speaker();	}
function update_fragmenten		(response) {update_id('fragmenten_'+AGENDAPUNT_ID, response);				}
function update_spreker			(response) {update_id('aanhetwoord_'+AGENDAPUNT_ID, response);				}
function update_sprekers		(response) {update_id('sprekers_'+AGENDAPUNT_ID, response),set_height(); 				}
function agendapunt_documenten	(response) {update_id('agendapunt_documenten_'+AGENDAPUNT_ID, response); 	}
function gekoppelde_informatie	(response) {update_id('meerinformatie_'+AGENDAPUNT_ID, response); 			}

var MEETING		=	0;
var FRAGMENT	=	0;
var SPEAKERS	=	'';
var TIMEINDEXES	=	'';
var NOTE_TO_UPDATE 	= null;
var NOTE_ID_UPDATE 	= 0;
var AGENDAPUNT_ID 	= null;
var RUNFIRSTTIME 	= true;

function live_uitzending()
{
	//make sure we only get here once
	if (arguments.callee.done)
	{
		return;
	}
	arguments.callee.done = true;
	
	var f_obj	=	document.getElementById('fragment');
	
	if (f_obj)
		FRAGMENT	=	f_obj.value;
		
	var m_obj	=	document.getElementById('meeting');
	
	if (m_obj)
		MEETING		=	m_obj.value;
	
	if (!isFlash)
	{
		setTimeout("set_speakers_timeindexes ();", 1500);
		
		if(typeof(ISLIVE) == 'undefined')
		{
			setTimeout("do_poll();",1500);
		}
	}
	
	if(typeof(ISLIVE) == 'undefined')
	{
		if (document.getElementById('agendapunten'))
		{
			onload_meeting();
		}
	}
}

function set_speakers_timeindexes ()
{
	if(typeof(document.MediaPlayer) != "undefined" || player != null)
	{
		aplx_call_by_uri("/modules/risbis/risbis.php?g=get_json_speakers", MEETING, set_speakers);
		aplx_call_by_uri("/modules/risbis/risbis.php?g=get_json_speaker_fragment&meeting="+MEETING+"&fragment="+FRAGMENT, MEETING, set_timeindexes);
	}
}

function do_poll()
{
	if(typeof(document.MediaPlayer) != "undefined"  || player != null)
	{
		get_speaker();
	}
	if (!isFlash)
	{
		setTimeout("do_poll();",1000);
	}
	else
	{
		setTimeout("do_poll();",200);
	}
}

function set_speakers(response)
{
	if(response != '')
	{
		SPEAKERS	=	eval("(" + response + ")");		
	}
}

function set_timeindexes(response)
{
	if(response != '')
	{
		TIMEINDEXES	=	eval("(" + response + ")");
		
		process_speaker();
	}
}


function get_note(id, type, mode)
{
	var noteid = 'note' + id + '_' + type;
	var note = $(noteid);
	var uri		= new String(document.location);
	var uri		= escape(uri);
	var update 	= true;
	
	closeOtherNotes();	
	
	if(note && mode != 'sluit')
	{		
		note.removeClassName('note_hide');
		//get note div from server and place it in to the last td form the newNote(tr)
		if(note.down('td'))
		{
			NOTE_TO_UPDATE = note.down('td');
			NOTE_ID_UPDATE = noteid;
		}else 
		{ // we gaan nu de vergadering notitie laten zien; dit is een div
			NOTE_TO_UPDATE = note;
			NOTE_ID_UPDATE = noteid;
		}	
		
		aplx_call_by_uri("/modules/risbis/risbis.php?g=handle_note_ajax&mode="+mode+"&object_id="+id+"&object_type="+type+"&uri="+uri, 0, function(response){update_note(response, mode);});		
	}else
	{
		/* Venster sluiten */
		var idx = new Array();
		idx[0] = id;
		idx[1] = type;
		iconControl(idx, mode);
	}
}

function closeOtherNotes()
{	
	$$('.note').each(function(s, index) 
	{		
		if(s.up('tr'))
		{
			s.up('tr').addClassName('note_hide');
			var id = s.up('tr').getAttribute('id');
		}else
		{
			s.up('div').addClassName('note_hide');
			var id = s.up('div').getAttribute('id');
		}

		/* acties weer resetten */ 
		id = id.replace(/note/g,'');
		var idx	=	id.split('_');
		iconControl(idx, 'sluit');
	});		
}

function update_note(response, mode)
{	
	var id = "";
	if(null!=NOTE_TO_UPDATE)
	{		
		NOTE_TO_UPDATE.update(response);
		
		if(NOTE_TO_UPDATE.up('tr'))
		{
			id = NOTE_TO_UPDATE.up('tr').getAttribute('id');
		}else
		{
			id = NOTE_TO_UPDATE.getAttribute('id');
		}
		id = id.replace(/note/g,'');
		var idx	=	id.split('_');

		update_note_links(idx);
		iconControl(idx, mode);
	}
}

function update_note_links(idx)
{	
	var note = $('note'+idx[0]+'_'+idx[1]);
	
	$$('.notesave').each(function (s, index) 
	{		
		s.previous('li').hide();
		s.removeClassName('note_hide');
		s.onclick = function()
							{								
								save_note(idx[0], idx[1]);
							}
	})
	
	if(note.down('.noteedit'))
	{
		var link = note.down('.noteedit').down('a');
		link.setAttribute('href','javascript:void(0)');
		link.onclick= function()
							{
								get_note(idx[0], idx[1],'bewerk');
							}
	}
	
	if(note.down('.notedelete'))
	{
		var link = note.down('.notedelete').down('a');
		link.setAttribute('href','javascript:void(0)');
		link.onclick= function()
							{
								get_note(idx[0], idx[1],'verwijder');
							}
	}
	if(note.down('.notehistorie'))
	{
		var link = note.down('.notehistorie').down('a');
		link.setAttribute('href','javascript:void(0)');
		link.onclick= function()
							{
								get_note(idx[0], idx[1],'historie');
							}
	}
	if(note.down('.historie_meer'))
	{
		var link = note.down('.historie_meer');
		link.setAttribute('href','javascript:void(0)');
		link.onclick=function()
							{
								get_note(idx[0], idx[1],'alles');
							}
	}
	
	
}

function iconControl(idx, mode)
{
	if($('notelink'+idx[0]+'_'+idx[1]+'_'+mode))
		var link = $('notelink'+idx[0]+'_'+idx[1]+'_'+mode);
	else
		var link = $('notelink'+idx[0]+'_'+idx[1]+'_sluit');
	
	if(link || mode == 'verwijder')
	{
		/* Bij normale gang van zaken komt hij hier altijd terecht, 
			Echter komt hij hier niet altijd vanaf functie closeOtherNotes. */ 
		switch (mode)
		{
			case 'maak':
			case 'toon':
			case 'bewerk':
			case 'historie':
				link.setAttribute('id', 'notelink'+idx[0]+'_'+idx[1]+'_sluit');
				break;
			case 'sluit':
				if(link.down().getAttribute('class')=='note_false')
					link.setAttribute('id', 'notelink'+idx[0]+'_'+idx[1]+'_maak');
				else
					link.setAttribute('id', 'notelink'+idx[0]+'_'+idx[1]+'_toon');
				break;
			case 'verwijder':
				if($('notelink'+idx[0]+'_'+idx[1]+'_toon'))
				{
					/* Bij verwijderen weet je zeker dat de notelink de actie toon bevat. 
						Dit in verband met de reset actie. */
					var link = $('notelink'+idx[0]+'_'+idx[1]+'_toon');
					link.setAttribute('id', 'notelink'+idx[0]+'_'+idx[1]+'_sluit');
					link.down().removeClassName('note_true');
					link.down().addClassName('note_false');	
				}
				break;
			case 'opslaan':
				link.setAttribute('id', 'notelink'+idx[0]+'_'+idx[1]+'_sluit');
				link.down().removeClassName('note_false');
				link.down().addClassName('note_true');	
				break;
		}
	}
}

function save_note(id, type)
{
	var noteTr 		= $('note'+ id + '_' + type);	
	var notediv 	= noteTr.down('div');	
	var uri			= new String(document.location);
	var uri			= escape(uri);
	NOTE_TO_UPDATE 	= notediv.up();	
	if(notediv)
	{		
		var notitie 	= notediv.down('textarea').value;	
		
		jQuery.post("/modules/risbis/risbis.php?g=handle_note_ajax&mode=opslaan&object_id="+id+"&object_type="+type+"&uri="+uri,
			{note: notitie},
			function(response){update_note(response, 'opslaan');}
		);
		
		// aplx_call_by_uri("/modules/risbis/risbis.php?g=handle_note_ajax&mode=opslaan&object_id="+id+"&note="+note+"&object_type="+type+"&uri="+uri, 0, function(response){update_note(response, 'opslaan');});
	}
}

function set_active(id,fragment_id,update_movie)
{
	update_spreker(' ')
	
	if (fragment_id)
	{
		update_live('');
		document.getElementById('live_film').className = 'hide';
	}
	else
	{
		if (document.getElementById('live_film').className == 'hide')
		{
			document.getElementById('live_film').className = '';
			aplx_call_by_uri("/modules/risbis/risbis.php?g=get_live_html", update_live);
		}
	}
	
	$$('#agendapunten tr.attachement').each(function(s, index) 
	{
		s.removeClassName('show');
		s.addClassName('hide');
	});
	
	AGENDAPUNT_ID = id;
	
	var current_agendapunt = $('attachements_'+id);
	current_agendapunt.removeClassName('hide');
	current_agendapunt.addClassName('show');
	
	// $$('tr.actief td').each(function(s, index) 
	// {
		// s.style.borderBottom = 'none';
	// });
	
	var p = document.getElementsByClassName('pause','agendapunten');
	var a = document.getElementsByClassName('actief','agendapunten');
	
	for(i=0;i<p.length;i++)
	{
		p[i].removeClassName('pause');
		p[i].addClassName('play');
	}
	
	for(i=0;i<a.length;i++)
	{
		a[i].removeClassName('actief');
	}
	
	var ap = $('agendapunt'+id+'_'+fragment_id);
	if(ap)
	{
		ap.addClassName('actief');
	}
	if(fragment_id > 0)
	{
		var b = $('button'+id);
		if(b)
		{
			b.removeClassName('play');
			b.addClassName('pause');
		}	
	}
	
	if(fragment_id > 0)
	{
		var uri		=	new String(document.location);
		
		uri2 = uri.replace ('http://', '');
		uri2 = uri2.split ('/');
		
		var uri		=	escape(uri);
		FRAGMENT	=	fragment_id;
		
		if (update_movie)
		{
			if(uri2[8] && RUNFIRSTTIME == true)
			{
				// fix: Wel javascript en verwijzing rechtstreeks naar spreker fragment.
				RUNFIRSTTIME = false;				
			}else{
				aplx_call_by_uri("/modules/risbis/risbis.php?g=start_film_fragment&fragment_object_id="+fragment_id+"", fragment_id, update_film);
			}	
		}
		aplx_call_by_uri("/modules/risbis/risbis.php?g=get_sprekers&meeting="+MEETING+"&fragment_object_id="+fragment_id+"&uri="+uri+"", fragment_id, update_sprekers);
		aplx_call_by_uri("/modules/risbis/risbis.php?g=get_fragmenten&agendapunt_object_id="+id+"&uri="+uri+"", id, update_fragmenten);
		aplx_call_by_uri("/modules/risbis/risbis.php?g=get_json_speaker_fragment&meeting="+MEETING+"&fragment="+FRAGMENT, MEETING, set_timeindexes);
	}
	if(fragment_id == 0)
	{
		FRAGMENT	=	0;
		update_film('');
		update_fragmenten('');
		update_spreker('');
		update_sprekers('');
		
	}
	aplx_call_by_uri("/modules/risbis/risbis.php?g=get_docs_for_ag&agendapunt_object_id="+id+"", fragment_id, agendapunt_documenten);
	aplx_call_by_uri("/modules/risbis/risbis.php?g=get_gekoppelde_informatie&agendapunt_object_id="+id+"", fragment_id, gekoppelde_informatie);
}

function set_speaker(obj, time)
{
	if (isFlash)
	{
		speaker_time = time;
		if (state != "PLAYING")
		{
			player.sendEvent('PLAY', 'true');
			setTimeout ('setSpeakerTime ()', 400);
		}
		else
		{
			player.sendEvent('SEEK', speaker_time);
		}
	}
	else
	{
		var obj_id	=	obj.getAttribute('id');
		var id_arr	=	obj_id.split("_");
		var film_id =	id_arr[1];
		var frag	=	id_arr[2];
		var sp_frag	=	id_arr[3];
		aplx_call_by_uri("/modules/risbis/risbis.php?g=start_film_speaker&meeting="+MEETING+"&frag="+frag+"&sp_frag="+sp_frag+"&film_id="+film_id, MEETING, update_film);
	}
}

function setSpeakerTime ()
{
	player.sendEvent('SEEK', speaker_time);
}

function set_fragment(obj)
{
	var uri		=	new String(document.location);
	var uri		=	escape(uri);
	
	var obj_id	=	obj.getAttribute('id');
	var id_arr	=	obj_id.split("_");
	
	var frag	=	id_arr[1];
	FRAGMENT	=	frag;
	aplx_call_by_uri("/modules/risbis/risbis.php?g=start_film_fragment&fragment_object_id="+frag+"", frag, update_film);
	aplx_call_by_uri("/modules/risbis/risbis.php?g=get_sprekers&meeting="+MEETING+"&fragment_object_id="+frag+"&uri="+uri+"", frag, update_sprekers);
	aplx_call_by_uri("/modules/risbis/risbis.php?g=get_json_speaker_fragment&meeting="+MEETING+"&fragment="+FRAGMENT, MEETING, set_timeindexes);
}

function preload_speakers(speakers)
{
	var img_obj	=	new Image();
	
	speakers	=	new String(speakers).split('id');
	var imre	=	/.*"img_src": "([^"]+)".*/gi;
	var pre		=	/\\/gi;
	
	for (var n = 0; n < speakers.length; n++)
	{
		imgsrc	=	speakers[n].replace(imre, '$1');
		imgsrc	=	imgsrc.replace(pre, '');
		if (imgsrc.indexOf('Afbeelding') > -1)
		{
			img_obj.src = imgsrc;
		}
	}
}

var CURRENTSPEAKER = -1;

function get_speaker()
{
	var i			=	CURRENTSPEAKER;
	var non_speaker	=	false;
	var seconds;
	//windows mediaplayer
	if(typeof(document.MediaPlayer) != "undefined" && typeof(document.MediaPlayer.CurrentPosition) != "undefined" && TIMEINDEXES != '')
	{
		seconds	=	Math.round(document.MediaPlayer.CurrentPosition);
	}
	
	//flashplayer
	if(typeof(player_currentPosition) != "undefined" && TIMEINDEXES != '')
	{
		seconds	=	Math.round(player_currentPosition);
	}
	

	
	if(!isNaN(seconds))
	{
		var last		=	TIMEINDEXES.last;
		if(seconds > last)
		{
			update_spreker('');
		}
		else if (CURRENTSPEAKER > -1 && seconds < TIMEINDEXES['sp' + CURRENTSPEAKER].start)
		{
			if (CURRENTSPEAKER > -1)
			{
				var sf_li = document.getElementById('sf_' + TIMEINDEXES['sp' + CURRENTSPEAKER].sf_id);
	
				if (sf_li)
				{
					sf_li.className = '';
				}
			}


			non_speaker	=	false;
			doit		=	true;
			
			while (i != -1 && TIMEINDEXES['sp' + i].start >= seconds && doit.valueOf() == true)
			{
				if (TIMEINDEXES['sp' + i].stop < seconds)
				{
					non_speaker	=	true;
					doit		=	false;
				}
				i--;
			}
	
			CURRENTSPEAKER = i;
	
			if (non_speaker.valueOf() == true || i == -1)
			{
				update_spreker('');
			}
			else
			{
				write_speaker();
			}
		}
		else if (CURRENTSPEAKER == -1)
		{
			if (TIMEINDEXES['sp0'].start <= seconds)
			{
				doit	= true;
				i 		= 0;
				while (TIMEINDEXES['sp'+ i].stop < seconds && doit.valueOf() == true)
				{
					non_speaker = false;
					i++;

					if (TIMEINDEXES['sp'+ i].start > seconds)
					{
						non_speaker = true;
						doit 		= false;
					}
				}
				if (non_speaker.valueOf() == true)
				{
					update_spreker('');
				}
				else
				{
					CURRENTSPEAKER = i;
					write_speaker();
				}
			}
		}
		else if (seconds > TIMEINDEXES['sp' + CURRENTSPEAKER].stop)
		{
			if (CURRENTSPEAKER > -1)
			{
				var sf_li = document.getElementById('sf_' + TIMEINDEXES['sp' + CURRENTSPEAKER].sf_id);
	
				if (sf_li)
				{
					sf_li.className = '';
				}
			}

			doit = true;
			while (TIMEINDEXES['sp' + i].stop < seconds && doit.valueOf() == true)
			{
				non_speaker = false;
				i++;
				if (TIMEINDEXES['sp' + i].start > seconds)
				{
					non_speaker = true;
					doit 		= false;
				}
			}
			if (non_speaker.valueOf() == true)
			{
				update_spreker('');
			}
			else
			{
				CURRENTSPEAKER = i;
				write_speaker();
			}
		}
//			setTimeout("process_speaker();",1000);
	}
}

function parseXML_status(response)
{
	var statusmsg = '';
	// Convert the string to an XML object
	try
	{
		//Internet Explorer
		var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		xmlDoc.loadXML(response);
	}
	catch(e)
	{
		try
		{
			//Firefox, Mozilla, Opera, etc.
			//xmlDoc=document.implementation.createDocument("","",null);
			var xmlDoc = (new DOMParser()).parseFromString(response, "text/xml");
		}
		catch(e)
		{
			alert(e.message)
		}
	}

	var root        = xmlDoc.getElementsByTagName('currentbroadcasts')[0];
	var broadcasts	= root.getElementsByTagName('broadcast');
	var aantalLiveUitzendingen = 0;

	var status = 'De huidige '+(secure=='1'?'besloten':'openbare')+' vergadering is gestopt.';

	for (var iBroadcast=0; iBroadcast < broadcasts.length; iBroadcast++)
	{
		var broadcast = broadcasts[iBroadcast];

		var locatie		= (broadcast.getElementsByTagName('locatie')[0].firstChild?broadcast.getElementsByTagName('locatie')[0].firstChild.nodeValue:'');
		var vergadering	= (broadcast.getElementsByTagName('vergadering')[0].firstChild?broadcast.getElementsByTagName('vergadering')[0].firstChild.nodeValue:'');
		var agendapunt	= (broadcast.getElementsByTagName('agendapunt')[0].firstChild?broadcast.getElementsByTagName('agendapunt')[0].firstChild.nodeValue:'');
		var secure		= (broadcast.getElementsByTagName('secure')[0].firstChild?broadcast.getElementsByTagName('secure')[0].firstChild.nodeValue:'');
		var starttime	= (broadcast.getElementsByTagName('starttime')[0].firstChild?broadcast.getElementsByTagName('starttime')[0].firstChild.nodeValue:'');
		var stoptime	= (broadcast.getElementsByTagName('stoptime')[0].firstChild?broadcast.getElementsByTagName('stoptime')[0].firstChild.nodeValue:'');
		var url			= (broadcast.getElementsByTagName('url')[0].firstChild?broadcast.getElementsByTagName('url')[0].firstChild.nodeValue:'');

		if (vergadering != '0')
		{
			aantalLiveUitzendingen++;
		
			if (vergadering == MEETING)
			{
				//Dit is de vergadering die we nu aan het bekijken zijn...
				status = 'De huidige '+(secure=='1'?'besloten':'openbare')+' vergadering (<a href="'+url+'">'+vergadering+'</a>) ';
				//'0000-00-00 00:00:00' => bezig met uitzenden, er is nog geen eindtijd bekend.
				if (stoptime == '0000-00-00 00:00:00')
				{
					status += 'loopt';
				}
				else
				{
					status += 'is gepauzeerd';
				}
				status += '<br/>';
			}
			else
			{
				//...
				status += 'Er is nog een andere vergadering (<a href="'+url+'">'+vergadering+'</a>) bezig:';
			}
		}



	}
		statusmsg += status+'<br/>';//+'['+locatie+'] vergadering='+vergadering+', agendapunt='+agendapunt+', '+(secure=='1'?'besloten':'openbaar')+', <br/>';
	
	statusmsg += 'Aantal live uitzendingen: '+aantalLiveUitzendingen+'<br/>';

	
	return statusmsg;
}



function update_status(response)
{
	var message = parseXML_status(response);

//	message += 'meeting='+MEETING+', fragment='+FRAGMENT+'<br/>';



	var dummy = response.replace(/</g,'&lt;');
	dummy = dummy.replace(/>/g,'&gt;');

	message += '<pre>'+dummy+'</pre>';

/*
	switch(response)
	{
		case "0":
			message = "Nergens mee bezig";
			break;
		case "1":
			message = "Afspelen";
			break;
		case "2":
			message = "<p>De uitzending is gepauseerd.</p>";
			break;
		default:
			message = "Onbekend ("+response+")";
	}
*/
	update_id('status_uitzending', message);
}

function get_status()
{
	if(ISLIVE == 1)
	{
		aplx_call_by_uri("/modules/risbis/risbis.php?g=get_status", update_status);
	}
}

function process_speaker()
{
	if(typeof(ISLIVE) == 'undefined' && FRAGMENT != '0')
	{
		get_speaker();
	}
}
function write_speaker()
{
	var sf_li = $('sf_' + TIMEINDEXES['sp' + CURRENTSPEAKER].sf_id);
	if (sf_li)
	{
		sf_li.addClassName('active_sf');
		
		var persons = $('persons_' + AGENDAPUNT_ID);
		
		var newOffset = sf_li.offsetTop - 175;
		
		if (newOffset < 0)
		{
			newOffset = 0;
		}
		
		persons.scrollTop = newOffset;
	}

	var obj		=	SPEAKERS['id' + TIMEINDEXES['sp' + CURRENTSPEAKER].speaker];
	if(obj)
	{
		var resp	=	'<h3>Aan het woord:</h3>';
		if(obj.img != '')
		{
			resp	+=	obj.img;
		}
		
		resp	+=	'<p class="right"><strong>';
		resp	+=	obj.name;
		resp	+=	'</strong><br />';
		resp	+=	obj.group;
		resp	+=	'<br />';
		resp	+=	obj.p;
		resp	+=	'</p>';
		
		update_spreker(resp);
	}
}

function onload_meeting()
{
	var activeElement	=	false;

	var uri	= new String(document.location);
	uri = uri.replace ('http://', '');
	uri = uri.split ('/');
	
	if (!uri[6] && $$('#agendapunten h3 a')[0])
	{
		var agendapunt_id = $$('#agendapunten h3 a')[0].parentNode.parentNode.parentNode.id;
		var temp = agendapunt_id.split('_');
		
		if (temp[1] != 0)
		{
			var agendapunt_id	=	agendapunt_id.replace(/agendapunt/g,'');
			var idx	=	agendapunt_id.split('_');
			set_active(idx[0],idx[1],true);
			activeElement = true;
			return;
		}
	}

	if(!activeElement && $$('#agendapunten tr.actief h3 a')[0])
	{
		var agendapunt_id =$$('#agendapunten tr.actief h3 a')[0].parentNode.parentNode.parentNode.id;
		
		var agendapunt_id	=	agendapunt_id.replace(/agendapunt/g,'');
		var idx	=	agendapunt_id.split('_');
		set_active(idx[0],idx[1],true);
		activeElement = true;
		return;
	}
}

var security_level = 0;
var oldStatus1 = '';
var oldStatus2 = '';
var oldAgenda1 = '';
var oldAgenda2 = '';
var loc_nr = 1;

function get_security_level()
{
	aplx_call_by_uri("/modules/risbis/risbis.php?g=get_security_level", check_security);
}

function check_security(level)
{
	security_level = level;
}

function get_media_status()
{
	//aplx_call_by_uri("/modules/risbis/risbis.php?g=get_status_media", check_media);
	// settimeout staat nu op 5 sec voor test, moet worden aangepast naar 30
	//setTimeout("get_media_status()", 5000);
}

function check_media(response)
{
	try
	{
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		xmlDoc.loadXML(response);
	}
	catch(e)
	{
		try
		{
			xmlDoc = (new DOMParser()).parseFromString(response, "text/xml");
		}
		catch(e)
		{
			alert(e.message)
		}
	}
	
	var root    = xmlDoc.getElementsByTagName('streams')[0];
	var streams	= root.getElementsByTagName('stream');

	for (var i=0; i < streams.length; i++)
	{
		var stream  = streams[i];
		var locatie	= (stream.getElementsByTagName('location')[0].firstChild?stream.getElementsByTagName('location')[0].firstChild.nodeValue:'');
		var status	= (stream.getElementsByTagName('status')[0].firstChild?stream.getElementsByTagName('status')[0].firstChild.nodeValue:'');
		var agendapunt	= (stream.getElementsByTagName('agendapunt')[0].firstChild?stream.getElementsByTagName('agendapunt')[0].firstChild.nodeValue:'');
		
	}
	
	var status1 = loc1[0];
	var agenda1 = loc1[1];
	var status2 = loc2[0];
	var agenda2 = loc1[1];
	
	if ((status1 == 0 && status2 == 0) || status1 != 0)
	{
		var loc_nr	  = 1;
		location_id	  = 'live';
		newStatus	  = status1;
		oldStatus	  = oldStatus1;
	}
	else
	{
		var loc_nr    = 2;
		location_id	  = 'live_audio';
		newStatus	  = status2;
		oldStatus	  = oldStatus2;
	}
	
	if (document.getElementById(location_id) && oldStatus != '')
	{
		switch (newStatus)
		{
			case '0':
				// stop
				document.getElementById(location_id).style.display = 'none';
				break;
			case '1':
				// play
				if (oldStatus == 0 || oldStatus == 2 || oldStatus == 3)
				{
					aplx_call_by_uri("/modules/risbis/risbis.php?g=get_url_mediaplayer&status=openbaar&locatie="+loc_nr, change_media);
					document.getElementById(location_id).style.display = 'block';
				}
				break;
			case '2':
				// pause
				break;
			case '3':
				// besloten
				if ((security_level > 0) && (oldStatus == 0 || oldStatus == 1 || oldStatus == 2))
				{
					aplx_call_by_uri("/modules/risbis/risbis.php?g=get_url_mediaplayer&status=besloten&locatie="+loc_nr, change_media);
					document.getElementById(location_id).style.display = 'block';
				}
				else if ((oldStatus == 0 || oldStatus == 1 || oldStatus == 2))
				{
					document.getElementById(location_id).style.display = 'none';
				}
				break;
		}
	}
	
	if ((status1 == 0 && status2 == 0) || status1 != 0)
	{
		if (document.getElementById('live_audio'))
		{
			switch (status2)
			{
				case '0':
					// text 'Of luister live mee' display = none
					document.getElementById('live_audio').style.display = 'none';
					break;
				case '1':
					document.getElementById('live_audio').style.display = 'block';
					break;
				case '2':
					// pauze
					break;
				case '3':
					if (security_level > 0)
					{
						document.getElementById('live_audio').style.display = 'block';
					}
					else
					{
						document.getElementById('live_audio').style.display = 'none';
					}
					break;
			}
		}
	}
	
	oldStatus1 = status1;
	oldStatus2 = status2;
	
	if (status1 != 0 && oldAgenda1 != agenda1)
	{
		//alert ('oud agendapunt = ' + oldAgenda1 + ' nieuw agendapunt = ' + agenda1);
		oldAgenda1 = agenda1;
	}
	else if (status2 != 0 && oldAgenda2 != agenda2)
	{
		oldAgenda2 = agenda2;
	}
}

function change_media(url)
{
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		// option 1: IE
		if (loc_nr == 1)
			player = document.getElementById('MediaPlayer')
		else
			player = document.getElementById('MediaPlayer_audio');
		player.filename = url;
	}
	else
	{
		// option 2: firefox
		if (loc_nr == 1)
			player = document.getElementById('MediaPlayer2')
		else
			player = document.getElementById('MediaPlayer2_audio');
		player.data = url;
	}
}

function clear_films()
{
	var divs = document.getElementsByClassName("film");
	if (divs)
	{
		for(i=0;i<divs.length;i++)
		{
			divs[i].innerHTML = '';
		}
	}
}

/* fix height */
function set_height()
{	
	//Haal browser informatie op, check is eigenlijk alleen bedoeld voor IE6.
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	if ((browser=="Netscape"||browser=="Microsoft Internet Explorer")  && (version>=4)){
		
		
		var current_attachement_div = $$('#attachements_'+AGENDAPUNT_ID+' .persons')[0];
		var current_spreker_div = $$('#sprekers_'+AGENDAPUNT_ID)[0];
		//alert(current_spreker_div.innerHTML);
		if(current_spreker_div.innerHTML == '')
		{
			//alert('leeg');
			//current_attachement_div.style.border = '1px solid red';
			current_attachement_div.style.height = '0px';
		}

	}
}


