// Pojedynczy węzeł nawigacyjny
function NavigationNode(identifier,prev,method) {
   this.identifier = identifier;
   this.previous = prev;
   this.showPage = aaBindObjMethod(this,method);
   this.next;
}

// Globalny obiekt Navigation służący do przechowywania stanu strony
// i koordynowania nawigacji
var Navigation = {
   setHome : function(node) {
      this.homeNode = node;
      },
   returnHome : function(evnt) {
      evnt = evnt ? evnt : window.event;
      aaCancelEvent(evnt);
      Navigation.setCurrentPage(Navigation.homeNode);
   },
   nextPage : function(evnt) {
      evnt = evnt ? evnt: window.event;
      aaCancelEvent(evnt);
      if (this.currentPage.next) {
         this.setCurrentPage(this.currentPage.next);
      }
   },
   adjustNavigation : function() {

      var node = this.currentPage;

      // Dostosowanie nawigacji do następnego zdjęcia
      var next = aaElem('next');
      if (!node.next) {
         next.className='hiddennavlink';
      } else {
         next.className = 'displaynavlink';
      }

      var previous = aaElem('previous'); 
      if (!node.previous) {
         previous.className = 'hiddennavlink';
      } else {
         previous.className = 'displaynavlink';
      }
      
   },
      
   prevPage : function(evnt) {
      evnt = evnt ? evnt: window.event;
      aaCancelEvent(evnt);
      if(this.currentPage.previous) {
         this.setCurrentPage(this.currentPage.previous);
      }
   },
   setCurrentPage : function(current) {
       this.currentPage = current;
       this.adjustNavigation();
       current.showPage();
   },
   addNavigationNode : function(past,index,method) {
       var nav = new NavigationNode(index,past,method);
       if (past) past.next = nav;
       return nav;
   }
};
