﻿var	  MoodPictures, MoodPanes, MoodWhich;
var	  MoodImages, MoodTotal;

/*
Initialize with how many total, separate mood zones there are in the page.
(1 for business, one for personal images ...).
*/
function prep_moods(total)
{
  MoodTotal = total;

  MoodPictures = new Array(total);
  MoodPanes = new Array(total);
  MoodImages = new Array(total);
  MoodWhich = new Array(total);
}

/*
Initialize a single zone:
   Which matches total.
   pictures = how many separate imates.
   panes = how many separate image panes in the zone.
   ext matches the common name of the image files (business, personal, mb, mp ...).
*/
function init_moods(which, pictures, panes, ext)
{
  var			  i;

  MoodPictures[which] = pictures;
  MoodPanes[which] = panes;  
  MoodImages[which] = new Array(pictures);
  MoodWhich[which] = 1;
  
  for (i = 0; (i < MoodPictures[which]); i++)
	{
	MoodImages[which][i] = new Image();
	MoodImages[which][i].src = 'images/' + ext + MoodWhich[which]++ + '.jpg';
	}
	
  set_moods(which);	
}

function set_moods(which)
{
  var			  i;
  
  MoodWhich[which] = Math.round((Math.random()) * (MoodPictures[which] - 1));

  for (i = 0; (i < MoodPanes[which]); i++)
    {
    set_picture(which, i);
    }

  timer();
}   

function set_picture(which, pindex)
{
  var			object;

  object = document.getElementById('mood' + which + pindex);
  object.src = MoodImages[which][MoodWhich[which]].src;

  if (++MoodWhich[which] == MoodPictures[which])
    {
    MoodWhich[which] = 0;
    }
}    
  
function timer()
{
  var			  i, j;
  
  for (i = 0; (i < MoodTotal); i++)
  {  
	for (j = 0; (j < MoodPanes[i]); j++)
	  {
	  if (Math.random() > 0.9)
		{
		set_picture(i, j);
		}
	  }
  }

  timerID = setTimeout("timer()", 1000);  
}


