
//--------------------------------------------------------------------------
//     c o m m o n   c o d e 
//--------------------------------------------------------------------------

// browser variables
var Nav   = navigator.appName ;
var isDOM = (document.getElementById ? true : false);
var isIE4 = (document.all);


//--------------------------------------------------------------------------
//     l e f t   v a r i a b l e s
//--------------------------------------------------------------------------

// LeftImageCourrante: Left pane current image
LeftImageCourrante = 0;

// Left pane play state: stopped = 0, running = 1
var LeftClickPlay = 0;

// LeftIncrement: loop flag 0=off, 1=on
LeftIncrement = 0;

// LeftIncrementStep: direction of the Left animation 1=fwd, -1=reverse
LeftIncrementStep = 1;

// LeftImageNum: Left pane current displayed image
LeftImageNum = 0;

// arrays
var LeftImages = new Array();
var LeftImagesComplete = new Array();


//--------------------------------------------------------------------------
//     l e f t   f u n c t i o n s
//--------------------------------------------------------------------------

function setLeftImages() {
	//
	// set_LeftImages: fill the array 'LeftImages' with
	//                a list of images
	//
	
	// set LeftIncrement to 0 to stop the Left animation loop
	LeftIncrement = 0;
	
	// set pause
	setLeftPause();

	// set the LeftImages array to the list of images
	for (LeftImageCourrante=0; LeftImageCourrante<LeftImageTot; LeftImageCourrante++) {
		LeftImages[LeftImageCourrante] = new Image();
		LeftImages[LeftImageCourrante].src = LeftImagesComplete[LeftImageCourrante];
	}

	// set the display to the last image in the list
	LeftImageNum = LeftImageTot-1;
	LeftNextFrame(0);
}


//----------------------------------------------------------------------

function LeftAnimate() {
    	//
    	// animate: start LeftAnimation loop
    	//

    	if (LeftIncrement != 0) {  
        	LeftNextFrame(LeftIncrement);
         	setTimeout ('LeftAnimate()',LeftDelay);
    	}
}


//----------------------------------------------------------------

function LeftNextFrame(inc) {
	//
	// LeftNextFrame: display the next image in the array LeftImages
	//

	// move forward/back by LeftIncrement
	LeftImageNum += inc;
	
	// test if within valid range, adjust
	if (Nav == 'Konqueror') {
		// go back to the first image
		if(LeftImageNum >= LeftImageTot + LeftPause - 1) {
				
			LeftImageNum = 0;  }
			
			// go to the last image
			if(LeftImageNum < 0 - LeftPause) {
				LeftImageNum = 0; }
 	} else {
		// go back to the first image
			if(LeftImageNum >= LeftImageTot + LeftPause - 1) {
				LeftImageNum = 0;
			}

		// go to the last image
			if(LeftImageNum < 0 - LeftPause ) {
				LeftImageNum = LeftImageTot - 1;  
			}
 		
		}

	// update Left image.src and text field
	if (LeftImageNum < LeftImageTot) {

		LeftImageCourrante = LeftImageNum;

		// change image
		document.LeftAnimation.src = LeftImages[LeftImageNum].src;
	
		// update Left text
		updateLeftImageText();
	}
}


//-----------------------------------------------------------------

function setLeftPause() {
	//
	// set LeftPause based on number of images
	//

	if (LeftImageTot > maxLeftPause) {
		LeftPause = maxLeftPause
	} else {
		LeftPause = LeftImageTot-1;
	}

}


//-----------------------------------------------------------------

function LeftLastImage() {
    	//
    	// LeftLastImage: display the last image in the array
    	//
    	
	LeftIncrement = 0;
    	LeftImageNum = LeftImageTot-1;
    	LeftNextFrame(0);
}


//------------------------------------------------------------------

function LeftFirstImage() {
    	//
    	// LeftFirstImage: display the first image in the array
    	//

    	LeftIncrement = 0;
    	LeftImageNum = 0;
    	LeftNextFrame(0);
}


//-------------------------------------------------------------------

function LeftStepBackward() {
    	//
    	// backward: display the previous image
    	//

    	LeftIncrement = 0;
    	if (LeftImageNum > 0) {
        	LeftNextFrame(-1);
	}	
}


//-------------------------------------------------------------------

function LeftStepForward() {
    	//
    	// forward: display the next image
    	//

    	LeftIncrement = 0;
    	if (LeftImageNum < LeftImageTot -1 )
    	{    LeftNextFrame(1);    }
}


//-------------------------------------------------------------------

function setLeftDelay() {
    	// 
    	// setLeftDelay: set LeftDelay based on LeftSpeed
    	//

    	LeftDelay = (numberOfLeftSpeeds - LeftSpeed) * 50;

    	if (LeftDelay == 0) { LeftDelay = 50; }

}


//-------------------------------------------------------------------

function LeftSpeedReset() {
    	// 
    	// LeftSpeedReset: reset the frame LeftDelay to its initial value
    	//

    	LeftSpeed = initLeftSpeed;
    	setLeftDelay();
}


//----------------------------------------------------------------

function LeftSlower() {
    	//
    	// Left slower: increase the LeftDelay between images
    	//

    	if (LeftSpeed > 1) {
		LeftSpeed-=1;
		setLeftDelay();
    	}
}


//----------------------------------------------------------------

function LeftFaster() {
    	//
    	// Left faster: decrease the LeftDelay between images
    	//

    	if (LeftSpeed < numberOfLeftSpeeds) {
		LeftSpeed+=1;
        	setLeftDelay();
    	}

}


//-------------------------------------------------------------------

function stopLeftPlay() {
    	//
    	// stopLeftPlay: turn off the Left animation loop
    	//

    	LeftIncrement = 0;
}


//--------------------------------------------------------------------

function updateLeftImageText() {
    	//
    	// updateLeftImageText: update the Left text box with the current status
    	//

   	var t ; 	

	// update Left text box
	t = LeftFrames[LeftImageCourrante].date;
	document.LeftForm.LeftImageText.value = t;
}


//----------------------------------------------------------------

function startLeftPlay() {
	//
    	// startLeftPlay: change the direction of the LeftAnimation
    	//
	

	// set buttons to active state if not already active
	if(LeftClickPlay == 0) {
		document.LeftForm.pause.src=icon_dir+'/pause.gif';
		document.LeftForm.first.src=icon_dir+'/first.gif';
		document.LeftForm.last.src=icon_dir+'/last.gif';
		document.LeftForm.prev.src=icon_dir+'/prev.gif';
		document.LeftForm.next.src=icon_dir+'/next.gif';
		document.LeftForm.slowdown.src=icon_dir+'/slowdown.gif';
		document.LeftForm.speedup.src=icon_dir+'/speedup.gif';
		document.LeftForm.speedreset.src=icon_dir+'/speedreset.gif';
	}
	
	
	// set state to 'running'
	LeftClickPlay = 1;

	// set LeftIncrement to default
	LeftIncrement = LeftIncrementStep;
       	
	// run
	LeftAnimate();  
  
}



//--------------------------------------------------------------------------
//     r i g h t   v a r i a b l e s
//--------------------------------------------------------------------------

// RightImageCourrante: Right pane current image
RightImageCourrante = 0;

// Right pane play state: stopped = 0, running = 1
var RightClickPlay = 0;

// RightIncrement: loop flag 0=off, 1=on
RightIncrement = 0;

// RightIncrementStep: direction of the Right animation 1=fwd, -1=reverse
RightIncrementStep = 1;

// RightImageNum: Right pane current displayed image
RightImageNum = 0;

// arrays
var RightImages = new Array();
var RightImagesComplete = new Array();


//--------------------------------------------------------------------------
//     r i g h t   f u n c t i o n s
//--------------------------------------------------------------------------

function setRightImages() {
	//
	// set_RightImages: fill the array 'RightImages' with
	//                a list of images based on the start and
	//                end times in the SELECT widgets
	
	// set RightIncrement to 0 to stop the Right animation loop
	RightIncrement = 0;
	
	// set pause
	setRightPause();

	// set the RightImages array to the list of images
	for (RightImageCourrante=0; RightImageCourrante<RightImageTot; RightImageCourrante++) {
		RightImages[RightImageCourrante] = new Image();
		RightImages[RightImageCourrante].src = RightImagesComplete[RightImageCourrante];
	}

	// set the display to the last image in the list
	RightImageNum = RightImageTot-1;
	RightNextFrame(0);
}


//----------------------------------------------------------------------

function RightAnimate() {
    	//
    	// animate: start RightAnimation loop
    	//

    	if (RightIncrement != 0) {  
        	RightNextFrame(RightIncrement);
        	//if (Nav != 'Netscape'  && !isIE4 && Nav != 'Konqueror') {
          		setTimeout ('RightAnimate()',RightDelay);
        	//}
    	}
}


//----------------------------------------------------------------

function RightNextFrame(inc) {
	//
	// RightNextFrame: display the next image in the array RightImages
	//

	// move forward/back by RightIncrement
	RightImageNum += inc;
	
	// test if within valid range, adjust
	if (Nav == 'Konqueror') {
		// go back to the first image
		if(RightImageNum >= RightImageTot + RightPause - 1) {
				
			RightImageNum = 0;  }
			
			// go to the last image
			if(RightImageNum < 0 - RightPause) {
				RightImageNum = 0; }
 	} else {
		// go back to the first image
			if(RightImageNum >= RightImageTot + RightPause - 1) {
				RightImageNum = 0;
			}

		// go to the last image
			if(RightImageNum < 0 - RightPause ) {
				RightImageNum = RightImageTot - 1;  
			}
 		
		}

	// update Right image.src and text field
	if (RightImageNum < RightImageTot) {

		RightImageCourrante = RightImageNum;

		// change image
		document.RightAnimation.src = RightImages[RightImageNum].src;
	
		// update Right text
		updateRightImageText();
	}
}


//-----------------------------------------------------------------

function setRightPause() {
	//
	// set RightPause based on number of images
	//

	if (RightImageTot > maxRightPause) {
		RightPause = maxRightPause
	} else {
		RightPause = RightImageTot-1;
	}

}


//-----------------------------------------------------------------

function RightLastImage() {
    	//
    	// RightLastImage: display the last image in the array
    	//
    	
	RightIncrement = 0;
    	RightImageNum = RightImageTot-1;
    	RightNextFrame(0);
}


//------------------------------------------------------------------

function RightFirstImage() {
    	//
    	// RightFirstImage: display the first image in the array
    	//

    	RightIncrement = 0;
    	RightImageNum = 0;
    	RightNextFrame(0);
}


//-------------------------------------------------------------------

function RightStepBackward() {
    	//
    	// backward: display the previous image
    	//

    	RightIncrement = 0;
//		Edited 10/14/05 roll over to last frame
//    	if (RightImageNum > 0) {
//        	RightNextFrame(-1);
//	}
		RightNextFrame(-1);	
}


//-------------------------------------------------------------------

function RightStepForward() {
    	//
    	// forward: display the next image
    	//

    	RightIncrement = 0;
//		Edited 10/14/05 -- rollover to first frame
//    	if (RightImageNum < RightImageTot -1 )
//   	{    RightNextFrame(1);    }
		RightNextFrame(1);
}


//-------------------------------------------------------------------

function setRightDelay() {
    	// 
    	// setRightDelay: set RightDelay based on RightSpeed
    	//

    	RightDelay = (numberOfRightSpeeds - RightSpeed) * 50;

    	if (RightDelay == 0) { RightDelay = 50; }

}


//-------------------------------------------------------------------

function RightSpeedReset() {
    	// 
    	// RightSpeedReset: reset the frame RightDelay to its initial value
    	//

    	RightSpeed = initRightSpeed;
    	setRightDelay();
}


//----------------------------------------------------------------

function RightSlower() {
    	//
    	// Right slower: increase the RightDelay between images
    	//

    	if (RightSpeed > 1) {
		RightSpeed-=1;
		setRightDelay();
    	}
}


//----------------------------------------------------------------

function RightFaster() {
    	//
    	// Right faster: decrease the RightDelay between images
    	//

    	if (RightSpeed < numberOfRightSpeeds) {
		RightSpeed+=1;
        	setRightDelay();
    	}

}


//-------------------------------------------------------------------

function stopRightPlay() {
    	//
    	// stopRightPlay: turn off the Right animation loop
    	//

    	RightIncrement = 0;
}


//--------------------------------------------------------------------

function updateRightImageText() {
    	//
    	// updateRightImageText: update the Right text box with the current status
    	//

   	var t ; 	

	// update Right text box
	t = RightFrames[RightImageCourrante].date;
	document.RightForm.RightImageText.value = t;
}


//----------------------------------------------------------------

function startRightPlay() {
	//
    	// startRightPlay: change the direction of the RightAnimation
    	//
	

	// set buttons to active state if not already active
	if(RightClickPlay == 0) {
		document.RightForm.pause.src=icon_dir+'/pause.gif';
		document.RightForm.first.src=icon_dir+'/first.gif';
		document.RightForm.last.src=icon_dir+'/last.gif';
		document.RightForm.prev.src=icon_dir+'/prev.gif';
		document.RightForm.next.src=icon_dir+'/next.gif';
		document.RightForm.slowdown.src=icon_dir+'/slowdown.gif';
		document.RightForm.speedup.src=icon_dir+'/speedup.gif';
		document.RightForm.speedreset.src=icon_dir+'/speedreset.gif';
	}
	
	
	// set state to 'running'
	RightClickPlay = 1;

	// set RightIncrement to default
	RightIncrement = RightIncrementStep;
       	
	// run
	RightAnimate();  
  
}


//------------------------------------------------------------------------
