// ================================
// Header-image voor gewone website
// ================================

// VARIABLE IMAGES IN HEADER EAB
// Set up the image files to be used.
var theImages = new Array() // do not change this
// To add more image files, continue with the
// pattern below, adding to the array. Rememeber
// to increment the theImages[x] index!

theImages[0] = '/images/headers/01.png'
theImages[1] = '/images/headers/02.png'
theImages[2] = '/images/headers/03.png'
theImages[3] = '/images/headers/04.png'
theImages[4] = '/images/headers/05.png'
theImages[5] = '/images/headers/06.png'
theImages[6] = '/images/headers/07.png'
theImages[7] = '/images/headers/08.png'
theImages[8] = '/images/headers/09.png'
theImages[9] = '/images/headers/10.png'
theImages[10] = '/images/headers/11.png'
theImages[11] = '/images/headers/12.png'
theImages[12] = '/images/headers/13.png'
theImages[13] = '/images/headers/14.png'
theImages[14] = '/images/headers/15.png'

var j = 0
var p = theImages.length;

var preBuffer = new Array()
for (i = 0; i < p; i++)
{
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
}

var whichImage = Math.round(Math.random()*(p-1));
function showImage()
{
document.write('<IMG SRC="'+theImages[whichImage]+'" WIDTH=640 HEIGHT=173>');
}


// =================================
// Header-image voor mobiele website
// =================================

// VARIABLE IMAGES IN HEADER EAB
// Set up the image files to be used.
var theMobileImages = new Array() // do not change this
// To add more image files, continue with the
// pattern below, adding to the array. Rememeber
// to increment the theImages[x] index!

theMobileImages[0] = '/images/headers/mobile/01.jpg'
theMobileImages[1] = '/images/headers/mobile/02.jpg'
theMobileImages[2] = '/images/headers/mobile/03.jpg'
theMobileImages[3] = '/images/headers/mobile/04.jpg'
theMobileImages[4] = '/images/headers/mobile/05.jpg'
theMobileImages[5] = '/images/headers/mobile/06.jpg'
theMobileImages[6] = '/images/headers/mobile/07.jpg'
theMobileImages[7] = '/images/headers/mobile/08.jpg'
theMobileImages[8] = '/images/headers/mobile/09.jpg'

var j = 0
var p = theMobileImages.length;

var preBuffer = new Array()
for (i = 0; i < p; i++)
{
preBuffer[i] = new Image()
preBuffer[i].src = theMobileImages[i]
}

var whichMobileImage = Math.round(Math.random()*(p-1));
function showMobileImage()
{
document.write('<IMG SRC="'+theMobileImages[whichMobileImage]+'" WIDTH=100%>');
}


// ========================
// Voor meest recente Tweet
// ========================

function relative_time(time_value) {
  var time_lt1min = 'Minder dan 1 minuut geleden';
  var time_1min = '1 minuut geleden ';
  var time_mins = '%1 minuten geleden';
  var time_1hour = '1 uur geleden';
  var time_hours = '%1 uur geleden';
  var time_1day = '1 dag geleden';
  var time_days = '%1 dagen geleden';
  
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
  var parsed_date = Date.parse(time_value);
  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
  delta = delta + (relative_to.getTimezoneOffset() * 60);

  if (delta < 60) {
    return time_lt1min;
  } else if(delta < 120) {
    return time_1min;
  } else if(delta < (60*60)) {
    return time_mins.replace('%1', (parseInt(delta / 60)).toString());
  } else if(delta < (120*60)) {
    return time_1hour;
  } else if(delta < (24*60*60)) {
	return time_hours.replace('%1', (parseInt(delta / 3600)).toString());
  } else if(delta < (48*60*60)) {
    return time_1day;
  } else {
    return time_days.replace('%1', (parseInt(delta / 86400)).toString());
  }
}

function twitterCallback1(twitters) {
	
  var statusHTML = [];
  var statusHTMLI = [];
  for (var i=0; i<twitters.length; i++){
    var username = twitters[i].user.screen_name;
	
	var FollowersCount = twitters[i].user.followers_count;
	var FriendsCount = twitters[i].user.friends_count;
	var ProfileImageUrl = twitters[i].user.profile_image_url;
	var StatusesCount = twitters[i].user.statuses_count;
	
    pic = twitters[i].user.profile_image_url;
    var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
      return '<a href="'+url+'" TARGET="Twitter">'+url+'</a>';
    }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
      return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'" TARGET="test">'+reply.substring(1)+'</a>';
    });
	if (i==0){
		statusHTMLI.push('<H3>Onze meest recente Tweet</H3>');
	}
	statusHTML.push(status+'<div class="timeago"><a href="http://twitter.com/'+username+'/statuses/'+(twitters[i].id_str)+'" TARGET="Twitter">'+relative_time(twitters[i].created_at)+'</a></div>');
  }
  document.getElementById('twitter_info_ws').innerHTML = statusHTMLI.join('');
  document.getElementById('twitter_update_list_ws').innerHTML = statusHTML.join('');
}

