function twitterCallback(twitters) {
  var statusHTML = [];
  for (var i=0; i<twitters.length; i++){
    var username = twitters[i].user.screen_name;
    var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
      return '<a href="'+url+'" target="_blank">'+url+'</a>';
    }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
      return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'" target="_blank">'+reply.substring(1)+'</a>';
    });
    statusHTML.push('<li><span>'+status+'</span> <a style="font-size:85%" href="http://twitter.com/'+username+'/statuses/'+twitters[i].id+'" target="_blank">'+relative_time(twitters[i].created_at)+'</a></li>');
  }

height_ = $('twitter_update_list').down('li').getHeight();
  document.getElementById('twitter_update_list').innerHTML = statusHTML.join('');

  var i=1;
  new PeriodicalExecuter(function(pe) {
    new Effect.Move('twitter_update_list', {x: 0, y: -height_ * (i++ % $('twitter_update_list').select('li').length), mode: "absolute"});
  }, 4);
}

function relative_time(time_value) {
  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 'less than a minute ago';
  } else if(delta < 120) {
    return 'about a minute ago';
  } else if(delta < (60*60)) {
    return (parseInt(delta / 60)).toString() + ' minutes ago';
  } else if(delta < (120*60)) {
    return 'about an hour ago';
  } else if(delta < (24*60*60)) {
    return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
  } else if(delta < (48*60*60)) {
    return '1 day ago';
  } else {
    return (parseInt(delta / 86400)).toString() + ' days ago';
  }
}

CarrouselHelper = Class.create({
  initialize: function(element_, items_, callback_, options_) {

    this.preloaded_ = [];
    this.element = element_.identify();
    this.preloading_ = items_.pluck('foto_url');

    this.items = items_;

    this.options = $H( {
	    'minClicks': 3,
	    'interval': 1.0,
	    'useCallback': true,
	    'startPos': 0
    } ).update(options_ || {});

    this.pos = 1;
    this.prev = 0;
    this.currentClick = this.options.get('startPos');
    this.isAnimating = false;
    this.callback = callback_.bind(this);

    this.start();
  },
  timerEvent: function() {

	if (! this.getElement()) { this.stop(); return }

	if (document.images && this.preloading_.length) {
		var url_ = this.preloading_.shift();

		img_ = new Image();
		img_.src = url_;

		this.preloaded_.push(img_);
	}

	this.currentClick++;

	if (this.currentClick > this.options.get('minClicks'))
	{
		if (this.isAnimating || ! this.options.get('useCallback')) return;
		this.isAnimating = true;
		this.currentClick = 0;

		this.prev = this.pos;
		this.pos++;
		if (this.pos > this.items.length-1) this.pos = 0;

		this.callback(this.pos, this.prev);
	}
  },
  isReadyAnimating: function() {
	this.isAnimating = false;
  },
  getElement: function() {
      return $(this.element);
  },
  getItem: function(iIndex) {
      return this.items[iIndex];
  },
  getItems: function() {
      return this.items;
  },
  stop: function() {
      if (this.fxI) window.clearInterval(this.fxI); this.fxI = false;
  },
  start: function() {
      this.stop();
      this.fxI = window.setInterval(this.timerEvent.bind(this), this.options.get('interval') * 1000);
  },
  setPosition: function(pos, draw) {
      this.pos = pos;
      this.currentClick = 0;

      if (draw) {
	  this.isAnimating = false;
	  this.callback(this.pos, this.prev);
	  this.start();
      }
  },
  getPosition: function() {
      return this.pos;
  }
});

document.observe("dom:loaded", function() {


});

var markers = [];
var map;
//load Google Map
function load() {
  if (GBrowserIsCompatible()) {
  	map = new GMap2(document.getElementById("map"));
	var geocoder = new GClientGeocoder();

	 map.setCenter(new GLatLng(51.463901,5.506039), 12);
	//add controls



	//create randomnumber to prevent caching and retrieve xml file

    GDownloadUrl(window.website_url +"xml.locaties.php", function(data, responseCode) {
    var xml = GXml.parse(data);

	//store markers in info array
    var xml_info = xml.documentElement.getElementsByTagName("marker");

    // create marker icon
    var icon = new GIcon();
    icon.image = "http://www.google.com/mapfiles/marker.png";

    icon.iconAnchor = new GPoint(0, 20);
    icon.infoWindowAnchor = new GPoint(5, 1);

	//loop over the markers array

        for (i = 0; i < xml_info.length; i++) {

            var url = xml_info[i].getAttribute("url");
            var longitude = xml_info[i].getAttribute("longitude");
            var latitude = xml_info[i].getAttribute("latitude");
            var adres = xml_info[i].getAttribute("address");

            var marker = createMarker(new GLatLng(longitude,latitude),url,icon, adres);

            markers.push(marker);
	    map.addOverlay(marker);

        } //close for loop

	map.addControl(new GSmallMapControl());
	map.addControl(new GMenuMapTypeControl());

	  }
); //close GDownloadUrl
        //
        //Create marker and set up event window
        function createMarker(point,html,icon, adres){
          var marker = new GMarker(point,icon);

          marker.address = adres;
          GEvent.addListener(marker, "click", function() {

              window.location=html;
          });

            GEvent.addListener(marker, "mouseover", function() {
                    marker.openInfoWindowHtml(adres);
            });
          return marker;
        }



  } //close GBrowserIsCompatible
} //close load

