 
function showPage() {
   getEXIF(this.identifier);
   var main = aaElem('main');

   // Usuwa bieżącą zawartość
   var current = aaElem('photo');
   if (current) main.removeChild(current);

   var img = document.createElement("img");
   img.src=this.identifier;
   img.id='photo';
   main.appendChild(img);
}

function getEXIF(photo) {
   var url = 'get_photo.php?photo=' + photo;
   var script = document.createElement('script');
   script.type = 'text/javascript';
   script.src = url + '&callback=printEXIF';
   document.getElementsByTagName('head')[0].appendChild(script);
}

function createListItem(text,ul) {
   var li = document.createElement('li');
   var txt = document.createTextNode(text);
   li.appendChild(txt);
   ul.appendChild(li);
   return ul;
}

function printEXIF(exifObj) {

   // Dostęp do elementu z metadanymi i wyczyszczenie go
   var meta = aaElem('meta');
   var metacontent =aaElem('metacontent'); 
   if (metacontent) meta.removeChild(metacontent);

   var ul = document.createElement('ul');
   ul=createListItem(exifObj.Model,ul); 
   ul=createListItem(exifObj.ISOSpeedRatings,ul);
   ul=createListItem(exifObj.ExposureTime,ul);
   ul=createListItem(exifObj.DateTimeOriginal,ul);
   ul=createListItem(exifObj.COMPUTED.ApertureFNumber,ul); 
   ul.id="metacontent";
   meta.appendChild(ul);
   
}

aaManageEvent(window,'load',function() {
   var home;
   var current;

   var photos = new Array();
   photos[0] = 'bollingerforestthumb.jpg';
   photos[1] = 'robin1thumb.jpg';
   photos[2] = 'silverthaw1thumb.jpg';
   photos[3] = 'robin2thumb.jpg';

   var index;
   var hash = window.location.hash;
   if (hash) {
      index = hash.split("#")[1];
   }

   var past;
   for (var i = 0; i < photos.length; i++) {
      var id = photos[i];
      var nav = Navigation.addNavigationNode(past,id,showPage);
      if (!past) {
        home = nav;
      }
      past = nav;
      if (index && id == index)
        current = nav;
   }

   Navigation.setHome(home);

   if (!current) {
      Navigation.setCurrentPage(home);
   } else {
      Navigation.setCurrentPage(current);
   }

   aaManageEvent(aaElem('next'),'click',aaBindObjMethod(Navigation,Navigation.nextPage));
   aaManageEvent(aaElem('previous'),'click',aaBindObjMethod(Navigation,Navigation.prevPage));
   aaManageEvent(aaElem('home'),'click', Navigation.returnHome);
});
