var currentStatus = "PAUSE"; 
var arrayItem = 0
var Myspeed = 1500;
var MyMain = 3250;
var ImageArray = new Array();
ImageArray[0] = "0.7mm 3D TOF MRA Brain.jpg";
ImageArray[1] = "2mm Coronal Fat Supressed  PD Knee.jpg";
ImageArray[2] = "2mm Coronal PD Knee.jpg";
ImageArray[3] = "2mm Sagittal Fat-Supressed Proton Density Knee.jpg";
ImageArray[4] = "2mm Sagittal Proton Density Knee.jpg";
ImageArray[5] = "3mm Axial T2 Brain, 512x512 Matrix.jpg";
ImageArray[6] = "3mm Axial T2 Cervical Spine.jpg";
ImageArray[7] = "3mm Axial T2 FLAIR Brain.jpg";
ImageArray[8] = "3mm Axial T2 Posterior Fossa.jpg";
ImageArray[9] = "3mm Sagittal T2 Cervical Spine.jpg";
ImageArray[10] = "4mm Sagittal T1 Lumbar Spine.jpg";
ImageArray[11] = "4mm Sagittal T2 Lumbar Spine.jpg";
ImageArray[12] = "5mm Sagittal T1 FLAIR.jpg";

function blendimage(divid, imageid, imagefile, millisec, arrayItem) { 


	if (currentStatus == "PAUSE"){
		return false;
	}

    var speed = Math.round(millisec / 100); 
    var timer = 0; 
     
    //set the current image as background 
	document.getElementById('slideshowCaption').innerText = imagefile.substring(0,imagefile.length-4)
	imagefile = "/Alpha3TMRI/"+imagefile
//	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")"; 
	 
    //make image transparent 
 //   changeOpac(0, imageid); 
     
    //make new image 
	imagefile = imagefile.replace(' ','%20');
    document.getElementById(imageid).src = imagefile; 

    //fade in image 
//    for(i = 0; i <= 100; i++) { 
//        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed)); 
//        timer++; 
//    } 
	
	// set time out on array
	if (currentStatus == "PLAY"){
		setTimeout("blendimage('blenddiv','blendimage', ImageArray["+arrayItem+"],Myspeed,"+getArrayItem(arrayItem,1)+")",MyMain);
	}
} 

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 ControlSlideShow(action){
	// PREVIOUS, NEXT, PAUSE, PLAY
	if (action == "PAUSE"){
		currentStatus = action;
		return false;
	}else if(action == "NEXT"){
		currentStatus = action;
		blendimage('blenddiv','blendimage', ImageArray[arrayItem],Myspeed,getArrayItem(arrayItem,1));
	}else if (action == "PREVIOUS"){
		currentStatus = action;
		blendimage('blenddiv','blendimage', ImageArray[arrayItem],Myspeed,getArrayItem(arrayItem,-1));
	}else{
		if (currentStatus != "PLAY"){
			currentStatus = action;
			blendimage('blenddiv','blendimage', ImageArray[arrayItem],Myspeed,arrayItem);
			currentStatus = "PLAY";
		}
	}
}

function getArrayItem(ArrayItemNumber,Incremental){
	var newValue = parseInt(ArrayItemNumber) + parseInt(Incremental);
	if ( newValue >= ImageArray.length - 1){
		arrayItem = 0;
		return 0;
	}else if(newValue < 0){
		arrayItem = ImageArray.length - 1;
		return ImageArray.length - 1;
	}else{
		arrayItem = newValue;
		return newValue;
	}
}
