var totalThumbs = 50;
var thumbsPerRow = 7;
var flickrApiKey = '40581a2ed1967218d6ea1250b3b91785';
var flickrUsername = '';
function jsonFlickrApi(rsp) {
	if (rsp.stat != "ok") {
		document.getElementById('flickrContainer').appendChild(
			document.createTextNode('Flickr Error: ' + rsp.message)
		);
		return;
	} else if (rsp.user) {
		var flickrPhotoScript = document.createElement('script');
		flickrPhotoScript.type = 'text/javascript';
		flickrPhotoScript.src =
			'http://www.flickr.com/services/rest/?format=json&api_key=' + flickrApiKey +
				'&method=flickr.people.getPublicPhotos&per_page=' + totalThumbs +
				'&user_id=' + rsp.user.id;
		flickrUsername = rsp.user.username._content;
		document.getElementById('flickrContainer').appendChild(flickrPhotoScript);
	} else if (rsp.photos) {
		for (var ii = 0; ii < rsp.photos.photo.length; ii++) {
			var photo = rsp.photos.photo[ii];
			if (!ii) {
				var userAnchor = document.createElement('a');
				userAnchor.href = 'http://www.flickr.com/photos/' + photo.owner + '/';
				userAnchor.appendChild(document.createTextNode(flickrUsername));
				document.getElementById('flickrContainer').appendChild(
					document.createTextNode(totalThumbs + ' meest recente foto\'s ')
				);
				document.getElementById('flickrContainer').appendChild(userAnchor);
				document.getElementById('flickrContainer').appendChild(
					document.createTextNode('.')
				);
				document.getElementById('flickrContainer').appendChild(
					document.createElement('br')
				);
			}
			var anchor = document.createElement('a');
			anchor.href = 'http://www.flickr.com/photos/' + photo.owner + '/' + photo.id + '/';
			var img = document.createElement('img');
			img.height = 75;
			img.width = 75;
			img.border = 0;
			img.alt = photo.title;
			img.src = 'http://static.flickr.com/' + photo.server + '/' + photo.id + '_' + photo.secret + '_s.jpg';
			anchor.appendChild(img);
			document.getElementById('flickrContainer').appendChild(anchor);
			if (ii % thumbsPerRow == thumbsPerRow - 1) {
				document.getElementById('flickrContainer').appendChild(
					document.createElement('br')
				);
			}
		}
	}
}
function flickrLoad() {
	var flickrUserScript = document.createElement('script');
	flickrUserScript.type = 'text/javascript';
	flickrUserScript.src = 'http://www.flickr.com/services/rest/?format=json&api_key=' + flickrApiKey +
		'&method=flickr.people.findByUsername&username=' + escape('Survivalgroep Fit Zeist');
	document.getElementById('flickrContainer').appendChild(flickrUserScript);
}
if (document.attachEvent) {
	window.attachEvent('onload', flickrLoad);
} else if (document.addEventListener) {
	window.addEventListener('load', flickrLoad, false);
}