///////////////////////////////////////////////////////////////////////////////
// logic for displaying images
// TODO: return json with image data, stop loading after 1000 images
///////////////////////////////////////////////////////////////////////////////
var http = createRequestObject();

function createRequestObject() 
{
   var ajax_o;
   var browser = navigator.appName;
   var views = 0;
   if(browser == "Microsoft Internet Explorer"){
      ajax_o = new ActiveXObject("Microsoft.XMLHTTP");
   }else{
      ajax_o = new XMLHttpRequest();
   }
   return ajax_o;
}

function update_count()
{
  getNewContent();
  views++;
}

function getNewContent()
{
   http.open('get','/spy_ajax.html');
   http.onreadystatechange = updateNewContent;
   http.send(null);
   return false;
}

function updateNewContent()
{
   if(http.readyState == 4){
	eval(http.responseText);
	document.getElementById('image_link').setAttribute("href","http://" + spyjson['image_id'] + ".openphoto.net");
	document.getElementById('image_id').innerHTML = spyjson['image_id'];
	document.getElementById('image_id').setAttribute("href","http://" + spyjson['image_id'] + ".openphoto.net");
	document.getElementById('image_title').innerHTML = spyjson['image_title'];
	document.getElementById('image_author').innerHTML = spyjson['image_author'];
        document.getElementById('image_author').setAttribute("href", "http://" + spyjson['image_author'] + ".openphoto.net");
        document.getElementById('spy_image').setAttribute("src", spyjson['image_url']);
   }
}

function init_page()
{
  setInterval(update_count, 10000);
}


