function addEvent(elm, evType, fn, useCapture){
  if (elm.addEventListener) 
  {
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent) { 
    var r = elm.attachEvent('on' + evType, fn);
    return r;
  } else {
    elm['on' + evType] = fn;
  }
}

function $(id){
	return document.getElementById(id);
}

var taggedImagesContainer;

var imageList = new Object();

function init(){
	
	req = new Ajax.Request('http://www.hauntology.net/flickr.getByTag.psp?tag=hauntology', 
	{
		method: 'get',
		onSuccess: function(transport){
			callBackHandler(transport);
		}
    });

}

function callBackHandler(result){

	imageList = eval("("+result.responseText+")");
	printPhotos();
}

function printPhotos(result){

	for(a in imageList){
		if (imageList[a].photo_id){
			getPhoto(imageList[a].photo_id);
		}
	}

	
}

function getPhoto(id){

	req = new Ajax.Updater('taggedImages', 'http://www.hauntology.net/flickr.getPhoto.psp?photoid='+id, {
		method: 'get',
		insertion: Insertion.Bottom
	});

}


addEvent(window,'load',init,false); 
