﻿function ItemInfo(image,offsetLeft,offsetTop,text,popupName)
{
   this.image = image;
   this.offsetLeft = offsetLeft;
   this.offsetTop = offsetTop;
   this.text = text;
   this.popupName = popupName;
}

function PageController()
{
   this.Items = new Array();
   this.CurrentItem = 0;
  
   this.AddItem = function(image,offsetLeft,offsetTop,text,popupName)
   {
      var item = new ItemInfo(image,offsetLeft,offsetTop,text,popupName);
      this.Items[this.Items.length] = item;
   }
   
   this.GetNumPages = function()
   {
      return this.Items.length;
   }

   this.Next = function()
   {
      this.CurrentItem++;
      if (this.CurrentItem >= this.Items.length)
      {
         this.CurrentItem = 0;
      }
      this.UpdatePage();
   }

   this.Previous = function()
   {
      this.CurrentItem--;
      if (this.CurrentItem < 0)
      {
         this.CurrentItem = this.Items.length - 1;
      }
      this.UpdatePage();
   }
   
   this.UpdatePage = function()
   {
      ContentLayer = document.getElementById('content');
      var Item = this.Items[this.CurrentItem];
      var Popup = '';
      var PopupEnd = '';
      var PopupLink = '';
      if (Item.popupName)
      {
         Popup = '<a href="#" onclick="popup(\'' + Item.popupName + '\'); return false;">';
         PopupEnd = '</a>';
         PopupLink = '<img src="images/view_popup.gif" />';
      }      
      ContentLayer.innerHTML = Popup + '<img src="images/work/' + Item.image + '" />' + PopupEnd;
      ContentLayer.style.left = 20 + Item.offsetLeft + 'px';
      ContentLayer.style.top = 115 + Item.offsetTop + 'px';      
      
      CategoryInfoLayer = document.getElementById('categoryInfo');
      
      CategoryInfoLayer.innerHTML = '<br />' + Popup + PopupLink + PopupEnd + '<br />' + Item.text;
      
      CurrentPageLayer = document.getElementById('CurrentPage');
      var CurrentPage = this.CurrentItem + 1;
      CurrentPageLayer.innerHTML = '&nbsp;' + CurrentPage + ' <span id="currentPageDisplaySmall">of</span> ' + this.Items.length + '&nbsp;';            
   }   
}

var Page = new PageController();
