	
	function nav_picture(dir,autoMode){
		// clear the auto scroll if the user clicked the picture navigation
		if(typeof autoMode == 'undefined' && autoScrollInterval){
			clearInterval(autoScrollInterval);
			autoScrollInterval = null;  
			manualMode = true;
		}
		// set the increment as +1 or -1 depending on +/1 in function argument
		var inc = dir == '+' ? 1 : -1;
		// get a reference to the picture element
		var pic = document.getElementById('selected_picture');
		// read the source attribute of the picture element
		var src = pic.getAttribute('src');
		// get the numeric value of the source attribute
		var id = src.match(/\d+/);
		// modify the numeric value
		id = Number(id) + Number(inc);
		// check that the id is still valid
		// if already at highes, loop around to first picture
		if(id > max_pic_cnt) id = 1;
		// if at the first picture, loop around to last picture
		if(id<1) id = max_pic_cnt;
		// construct a new source value
		var new_src = 'Images/' + img_dir + '/' + id + '.jpg';
		// alert("My new image file is " + new_src);
		// assign the new source value
		pic.setAttribute('src',new_src);   
		fade_in();
	}

	var autoScrollInterval = null;
	// set the interval before the scrolling begins, in milliseconds
	var startInterval = 2000;   

	var fadeTime = 1000;                        
	var fadeInts = 15; 
	var dwellTime = 1000;  
	var manualMode = false;
        
	// set the interval between pictures, in milliseconds
	var time_between_pics_interval = fadeTime * 2 + dwellTime;
	var auto;
	      
	                    
	function init(){    
		setTimeout("fade_out()",startInterval-fadeTime);
		setTimeout("start_scroll()",startInterval);
		//setTimeout(fade_in,1000);  
		
	}
	function start_scroll(){
		// do the first scroll
		nav_picture('+',true);
		// make it automatic until user clicks picture nav arrows        
		autoScrollInterval = setInterval("nav_picture('+',true)",time_between_pics_interval);
	}                                                                                     
	
function SetOpacity(elem, opacityAsInt)                                                            
{
    var opacityAsDecimal = opacityAsInt;
               
    if (opacityAsInt > 100)
        opacityAsInt = opacityAsDecimal = 100; 
    else if (opacityAsInt < 0)
        opacityAsInt = opacityAsDecimal = 0; 
    
    opacityAsDecimal /= 100;
    if (opacityAsInt < 1)
        opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
    
    elem.style.opacity = (opacityAsDecimal);
    elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}
function FadeOpacity(elemId, fromOpacity, toOpacity, time, fps)
{               
    var steps = Math.ceil(fps * (time / 1000));
    var delta = (toOpacity - fromOpacity) / steps;
    
    FadeOpacityStep(elemId, 0, steps, fromOpacity, 
                    delta, (time / steps));
}

function FadeOpacityStep(elemId, stepNum, steps, fromOpacity, 
                         delta, timePerStep)
{      
	if(manualMode){
		SetOpacity(document.getElementById(elemId),100);
	}else{
	    SetOpacity(document.getElementById(elemId), 
		       Math.round(parseInt(fromOpacity) + (delta * stepNum)));

	    if (stepNum < steps)
		setTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum+1) 
			 + ", " + steps + ", " + fromOpacity + ", "
			 + delta + ", " + timePerStep + ");", 
			   timePerStep);   
	}
}



function fade_in(){
	FadeOpacity('selected_picture',20,100,fadeTime,fadeInts);	
	setTimeout(fade_out,dwellTime + fadeTime);
}                                                          
function fade_out(){                          
	FadeOpacity('selected_picture',100,20,fadeTime,fadeInts);
	//setTimeout(fade_in,fadeTime);
}                           

