//----------------------------------------------------------------------------------------------
//   Script Name:     Picture Cycler
//   Purpose:           Cycle pictures in 4 picture slots
//----------------------------------------------------------------------------------------------
//   Created By:      Recharge Web Design 
//                           www.rechargewebdesign.com
//   Creation Date:   May 2006
//
//   Fading script by http://www.brainerror.net
//----------------------------------------------------------------------------------------------
//   Several things need to be remembered when looking at this
//   script.  First of all, JavaScript apparently doesn't like the use
//   of 2D arrays.  So, you need to make an array of arrays to
//   make it work.  Do not forget to recursively call the function.
//   the delay doesnt work right if you dont.
//----------------------------------------------------------------------------------------------

		// create array of 4 then create an array of 2 in each slot

			var pics = new Array(4)
			for (i=0; i <4; i++)
			pics[i]=new Array(2)
		
		// insert the pictures into an array of arrays
		
			pics[0][0] = 'images/Home-1a.jpg'
			pics[0][1] = 'images/Home-1b.jpg'
			
			pics[1][0] = 'images/Home-2a.jpg'
			pics[1][1] = 'images/Home-2b.jpg'

			pics[2][0] = 'images/Home-3a.jpg'
			pics[2][1] = 'images/Home-3b.jpg'
			
			pics[3][0] = 'images/Home-4a.jpg'
			pics[3][1] = 'images/Home-4b.jpg'


		// insert the names into an array
			var names = new Array()
			names[0] = 'cycle'
			names[1] = 'cycle2'
			names[2] = 'cycle3'
			names[3] = 'cycle4'

		// create the temp array to avoid the stupid string comparison
			var current = new Array()
			current[0] = 'images/Home-1a.jpg'
			current[1] = 'images/Home-2a.jpg'
			current[2] = 'images/Home-3a.jpg'
			current[3] = 'images/Home-4a.jpg'

		// initialize variables
			var counter = 5000;
			var counter2 = 2000;
			var n = 0;
			var m=0;
			var y = 100;
			var maxm = names.length-1;


//----------------------------------------------------------------------------------------------
// Fading script by http://www.brainerror.net
//----------------------------------------------------------------------------------------------

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}
 
//----------------------------------------------------------------------------------------------

		function cycle_pics() {
		
			// call a random number between 0 and 3
			var randomnumber=Math.floor(Math.random()*4)
			// call a random number between 0 and 1
			var randomnumber2=Math.floor(Math.random()*2)
			

			if ( current[randomnumber] != pics[randomnumber][randomnumber2]) {
		
			// change the image
			document.images[names[randomnumber]].src = pics[randomnumber][randomnumber2];
			
			// set current value
			current[randomnumber] = pics[randomnumber][randomnumber2];

				// this works too --> document.images[names[m]].style.filter= "alpha(opacity=20)"
	
				switch (randomnumber) {
   				case 0: opacity('cycle', 25, 100, 1000); break;
   				case 1: opacity('cycle2', 25, 100, 1000); break;
     				case 2: opacity('cycle3', 25, 100, 1000); break;
   				case 3: opacity('cycle4', 25, 100, 1000); break;
				}
			}
	
			// recursively call the function again -- this is the only way it will work right
 			timer = setTimeout('cycle_pics();', counter);
		}

	
