		// global variable
		var divs_to_fade;
		var isRunning = 0;
	 	// the starting index in the above array.  It should be set to the value of the div which doesn't have the CSS Display property set to "none"
		var i = 0;

		// the number of milliseconds between swaps.  
		var wait = 7000;


		// the onload event handler that starts the fading.
		function startPage(numberofimages, prefix) {
			this.value = numberofimages;
			buildArray(this, prefix);
			if (isRunning == 1) {
				clearInterval(runFunction);
			}
			runFunction = setInterval('swapFade(this)',wait);
			isRunning = 1;
			
			
		}

		// builds the array according to the number of items passed by startPage()
		function buildArray(numberofitems, prefix) {
			// this array consists of the id attributes of the divs we wish to alternate between
			var randomArray = new Array();
			for (count = 0; count< numberofitems.value; count++) {
				randomArray[count] =  prefix + "_" + "image" + count;
			}
			// call randomOrder() to give a random number .sort will resort
		   //randomArray.sort(randomOrder);
		   divs_to_fade = randomArray;
  
			// get first element from randomized array
			var firstElement = divs_to_fade[0]; 
      
			// array and display it on html page
			var divImage1 = document.getElementById(firstElement);
		   if (isRunning == 0) {
				divImage1.style.display = 'block';
			}
		}
		
		//to randomize an array items
		function randomOrder() {
			return (Math.round(Math.random())-0.5); 
		}


		// the function that performs the fade
		 function swapFade(numberofimages) {
		 	var index = numberofimages.value;
			   Effect.Fade(divs_to_fade[i], { duration:0.8, from:1.0, to:0.0 });
	 			i++;
	 			if (i == index) i = 0;
	 			Effect.Appear(divs_to_fade[i], { duration:1, delay:0.8, from:0.0, to:1.0 });
 			}

