// a couple of standard Dreamweaver functions
function MM_findObj(n, d) { //v3.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); 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];}
}

// define the main variables
var count = 0;
var numpics = mages.length;
var picarray = new Array();
var timerID = 0;
var start = 1;
var firstpic = 1;
// initialise the array
function loadPics(){
	for (i=0; i<numpics; i++){
		picarray[i] = new Image();
		picarray[i].src = mages[i];
	}
}

// Change the main picture function
function changePic(dir){
	var rtime = 5000;
	if (dir=="f"){
		count++;
	} else {
		count--;
	}
	if (count > numpics) {
		count = 1;
	} 
	if (count <=0) {
		count = numpics;
	} 
	MM_swapImage("mainpic","", mages[count-1],1);
	window.clearTimeout(timerID);
	if (firstpic==1){
		firstpic = 0;
		rtime = 10000;
	}
	if (start==1){
		timerID = window.setTimeout("changePic('"+dir+"')", rtime);
	}
}

// stops and starts the picture changer
function stopStart(){
	if (start == 1){
		window.clearTimeout(timerID);
		start = 0;	
	} else {
		start = 1;
		timerID = window.setTimeout("changePic('f')", 5000);
	}
}
