


function firstTimeLoad () {
		
		var time = $('T').value;
		
		new Ajax.Request('?P=ajaxmod', {	
			method: 'get',
			parameters: 'T=' + time,
			onFailure: function(resp) {
				alert('error');
			},
			onSuccess: function(resp) {
				if(resp.responseText != false)
				{					
					var array = resp.responseText.evalJSON(true);
					var t = 1; 
					var i = 0;
					var randomId = Math.floor(Math.random()*(array.length));
					array.each( function (data) {
						if (data.id == randomId) { 
							$('project_image_' + (i+1)).setStyle({
								display : ''
							});
						} 
						$('project_image_' + (i+1)).update('<img width="776" height="152" src="/uploads/afbeeldingen/' + array[i].image + '" />');
						i++;
					})
										
					var html = '';	
					var a = 'active';
					var b = 'normal';
					
									
					html += '<div class="normal" style="width: 14px;"></div>';
					
					array.each( function (data) {
						html += '<div id="box-' + t + '" class="'; 
                       	if (data.id == randomId) { html += a + '">'; }
                       	else { html += b + '">'; }
                       	html += '  <div class="tekstbox" >';
                        html += '    <div class="title">' + data.title + '</div>';
                        html += '    <div class="tekst">' + data.body;
                        html += '        <a href="' + data.blog_url + data.url_title + '">' + '[&raquo;]' + '</a>';  
                        html += '    </div>' ;
                        html += '  </div>';  
                        html += '</div>';                          
                        t++;
					});

					html += '<div class="normal" style="width: 25px;"></div>'; 

					$('project_teksten').update(html);
					
					for (var teller = 1; teller <= array.length; teller++) { 
						if (teller != (randomId+1)) {
							addSwitchObserver('box-' + teller);
						}
					};
					
				}
			}
		});	
	
}

function addSwitchObserver(id)
{
	$(id).observe('mouseover', function(event) {
		switchProject(id);		
	});
}

function switchProject (prjId) 
{
	
	var new_id = prjId.replace("box-", "");
	var old_id = '';
		
	Event.stopObserving(prjId, 'mouseover'); 

	$$('div.active').each(function(el) {
		$(el.id).removeClassName('active');
		$(el.id).addClassName('normal');
		addSwitchObserver(el.id);
		old_id = el.id;
	});
	
	old_id = old_id.replace("box-", "");

	$(prjId).removeClassName('normal');
	$(prjId).addClassName('active');

	/* wijzigen afbeelding */  
	
	switchImg(new_id, old_id);
}

function switchImg (nid, oid) {
	//alert('help');
	
	var queue = Effect.Queues.get('laag');
	queue.each( function(effect) { 
		effect.cancel(); 
	});
	
	Effect.Fade($('project_image_' + oid), {
		queue: {
			position : 'front',   
			scope: 'tag', 
			limit: 1 
		} , 
		duration:0.2 
	});	
	
	Effect.Appear($('project_image_' + nid), {
		queue: {
			position : 'end',   
			scope: 'laag', 
			limit: 1 
		} , 
		duration:0.8 
	});
}