var CurPic=0;
var AutoSwapL=false;
var AutoSwapR=true;
var SwapDelay=2000;

var cmdLenabled=false;
var cmdRenabled=false;

function ChangePic(nbr){
	CurPic+=nbr;
	if(CurPic==-1 && nbr==-1){CurPic=ArrFile.length-1;}
	if(CurPic>ArrFile.length-1 && nbr==1){CurPic=0;}
	changeImages('swapPic',"slideshow/" + ArrFile[CurPic]);
	if(AutoSwapL && AutoSwapR==false){window.setTimeout("TimerSwap(-1)",SwapDelay);}
	if(AutoSwapR && AutoSwapL==false){window.setTimeout("TimerSwap(1)",SwapDelay);}
	if((CurPic+1)>(ArrFile.length-1)){
		MM_preloadImages("slideshow/" + ArrFile[0]);
	}else{
		MM_preloadImages("slideshow/" + ArrFile[CurPic+1]);
	}
}

function TimerSwap(nbr){
	if(AutoSwapL || AutoSwapR){
		ChangePic(nbr);
	}
}

function StartL(){
	if(cmdLenabled){
		var OldL=AutoSwapL;
		AutoSwapL=true;
		AutoSwapR=false;
		if(OldL!=true){
			window.setTimeout("TimerSwap(-1)",SwapDelay);
		}
		cmdRenabled=false;
		cmdLenabled=false;
	}
}
function StartR(){
	if(cmdRenabled){
		var OldR=AutoSwapR;
		AutoSwapL=false;
		AutoSwapR=true;
		if(OldR!=true){
			window.setTimeout("TimerSwap(1)",SwapDelay);
		}
		cmdRenabled=false;
		cmdLenabled=false;
	}
}
function Stop(){
	AutoSwapL=false;
	AutoSwapR=false;
	cmdRenabled=true;
	cmdLenabled=true;
}
function changeImages(iObj,iFile) {
	var objImg=getObject(iObj);
	if(document.images) {
		objImg.src = iFile;
		objImg.style.filter=getfilter(Math.round(13 * Math.random()),1);
		objImg.filters[0].Apply();
		objImg.style.visibility="visible";
		objImg.filters[0].Play();
	}
}
function getfilter(num,spd){
	switch(num){
		case 0:  return "progid:DXImageTransform.Microsoft.Wheel(duration=" + spd + ",spokes=5)";
		case 1:  return "progid:DXImageTransform.Microsoft.Barn(duration=" + spd + ",orientation=horizontal)";
		case 2:  return "progid:DXImageTransform.Microsoft.Blinds(duration=" + spd + ",bands=5)";
		case 3:  return "progid:DXImageTransform.Microsoft.CheckerBoard(duration=" + spd + ")";
		case 4:  return "progid:DXImageTransform.Microsoft.Fade(duration=" + spd + ")";
		case 5:  return "progid:DXImageTransform.Microsoft.GradientWipe(duration=" + spd + ",wipeStyle=0)";
		case 6:  return "progid:DXImageTransform.Microsoft.Iris(duration=" + spd + ",irisStyle=STAR)";
		case 7:  return "progid:DXImageTransform.Microsoft.Iris(duration=" + spd + ",irisStyle=CIRCLE)";
		case 8:  return "progid:DXImageTransform.Microsoft.Iris(duration=" + spd + ",irisStyle=SQUARE)";
		case 9:  return "progid:DXImageTransform.Microsoft.Pixelate(duration=" + spd + ",maxSquare=40)";
		case 10: return "progid:DXImageTransform.Microsoft.RandomDissolve(duration=" + spd + ")";
		case 11: return "progid:DXImageTransform.Microsoft.Spiral(duration=" + spd + ")";
		case 12: return "progid:DXImageTransform.Microsoft.Stretch(duration=" + spd + ",stretchStyle=push)";
		case 13: return "progid:DXImageTransform.Microsoft.Strips(duration=" + spd + ",motion=rightdown)";
		default: return "progid:DXImageTransform.Microsoft.Fade(duration=" + spd + ")";
	}
}
function getObject(obj){
	if(document.all){
		if(typeof obj == "string")
			return document.all(obj)
		else
			return obj.style
	}
	if(document.getElementById){
		if(typeof obj=="string")
			return document.getElementById(obj)
		else
			return obj.style
	}
	return null
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
