var image
var images = []
var legends = []
var imageindex
var imagemaxindex
var progress
var legend
var button1
var button2
var nd = String.fromCharCode(8211)

function initialise_slide_show()
  {
  // Initialise images
  image = document.getElementById('slideimage')
  for (var i = 0; i <= 48; i++)
    images[i] = 'images/slide'+two(i)+'.jpg'
  // Define the legends
  legends[ 0] = 'Main entrance to the mission grounds with garden on right'
  legends[ 1] = ''
  legends[ 2] = 'Puja (worship) at the old shrine' 
  legends[ 3] = 'Transfer of altar pictures from the old shrine to the new shrine'
  legends[ 4] = 'Inauguration of the new shrine'
  legends[ 5] = 'Devotees attending inauguration of the new shrine'
  legends[ 6] = 'Musicians (Dr. A.K.Banerjee centre) at the presentation of plans for the new school'
  legends[ 7] = 'Festival to celebrate the laying of the foundation stone of the new school'
  legends[ 8] = 'Main bookshop'
  legends[ 9] = 'On special occasions books are sold in front of the bookshop too'
  legends[10] = 'Books are published in many languages '+nd+' here books in Hindi, Bengali and English are sold'
  legends[11] = 'The mobile bookshop (van in front of bookshop) enables sales in neighbouring areas'
  legends[12] = 'Mobile bookshop'
  legends[13] = 'Mobile bookshop'
  legends[14] = 'Mobile bookshop'
  legends[15] = 'Dispensary building'
  legends[16] = 'Statue of Swami Vivekananda in front of dispensary'
  legends[17] = 'Health check-up of school children'
  legends[18] = 'Health check-up of adults'
  legends[19] = 'Eyesight test'
  legends[20] = 'Eye testing equipment'
  legends[21] = 'Checking blood pressure'
  legends[22] = 'Analysis in laboratory'
  legends[23] = 'Medicine store'
  legends[24] = 'Incubator, calorimeter and and freezer'
  legends[25] = 'Swami Bhavarupananda with doctors in the medical camp'
  legends[26] = 'Inauguration of library and computers'
  legends[27] = 'Main gate of school compound'
  legends[28] = 'Entrance to school compound decorated for an event'
  legends[29] = 'Main entrance to school administration building'
  legends[30] = 'Swami Vivekananda memorial in visitors\' room of school administration building'
  legends[31] = 'Distribution of textbooks ...'
  legends[32] = '... and exercise books to poor school children'
  legends[33] = 'Now that they all have their pencils too ...'
  legends[34] = '... the lessons can begin!'
  legends[35] = ''
  legends[36] = 'Computer room in school building'
  legends[37] = 'School administration building on left and classroom building on right'
  legends[38] = 'Veranda alongside classrooms'
  legends[39] = 'Independence Day festival'
  legends[40] = 'Independence Day festival'
  legends[41] = 'Independence Day festival'
  legends[42] = 'Independence Day festival'
  legends[43] = 'Swami Bhavarupananda at the Independence Day festival'
  legends[44] = 'Guest speaker giving discourse on the Ramayana, a famous Indian epic'
  legends[45] = 'The Ramayana is the story of Rama (large picture at top)'
  legends[46] = 'President of the school, Mr. K.C.Lahiry (left), offering thanks'
  legends[47] = 'Christmas celebration (with picture of the Madonna and the child Jesus)'
  legends[48] = 'Presents from Switzerland!'
  // Other initialisations
  imageindex = 0
  imagemaxindex = images.length-1
  progress = document.getElementById('slideprogress') // Progress "Picture x of y"
  legend = document.getElementById('slidelegend')
  button1 = document.getElementById('l') 
  button2 = document.getElementById('r') 
  load_new_image()
  }

function two(n)
  {
  return (n < 10) ? '0'+n : n
  }

function previous_image()
  {
  if (imageindex == 0)
    imageindex = imagemaxindex
  else
    imageindex--
  load_new_image()
  }

function next_image()
  {
  if (imageindex == imagemaxindex)
    imageindex = 0
  else
    imageindex++
  load_new_image()
  }
  
function load_new_image()
  {
  // Set hourglass
  document.body.style.cursor = 'wait'
  button1.style.cursor = 'wait'
  button2.style.cursor = 'wait'
  // Load next image
  image.src = images[imageindex]
  image.onload = function()
                   {
                   // Reset hourglass
                   document.body.style.cursor = 'default'
                   button1.style.cursor = 'default'
                   button2.style.cursor = 'default'
                   // Assign progress text
                   progress.innerHTML = 'Picture '+(imageindex+1)+' of '+(imagemaxindex+1)
                   // Centre the text between the buttons
                   progress.style.marginLeft = eval("'"+eval(369-progress.offsetWidth/2)+"px'")
                   // Assign the legend
                   legend.innerHTML = legends[imageindex]
                   }
  // Preload next image
  var i = new Image()
  i.src = images[imageindex+1]
  }
