function MM_swapImgRestore()
{
	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 bb_setImages()
{
	var x,y,d=document;
	if ( ((x=MM_findObj("bb_pause"))!=null) && ((y=MM_findObj("bb_play"))!=null) )
	{
		if(d.slideShow==true)
		{
			x.src="../images/bb_pause_d.jpg";
			y.src="../images/bb_play_l.jpg";
		}
		else
		{
			x.src="../images/bb_pause_l.jpg";
			y.src="../images/bb_play_d.jpg";
		}
	}
}

function bb_swapImgRestore()
{
	MM_swapImgRestore();
	bb_setImages();
}

function MM_preloadImages()
{
	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)
{
	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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage()
{
	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];}
}


function loadPictures()
{ /*	LPC 29-02-04
	New version 03-07-04
		
		Traverse the array of pictures and load them in turn
		returning here in 150ms if we haven't finished yet.
		Avoids javascript problem of loading pictures concurrently
		and/or busy wait.
		
  */
  
	var d=document;
	if(d.images)
	{
		var i=0,j,a=loadPictures.arguments;
		
		if(d.loadTimer)
			window.clearTimeout(d.loadTimer);
			
		if(!d.pictures)
		{
			d.pictures=new Array();
			d.curPic=new Number(0);
			d.maxPic=new Number(0);
			d.maxPic=(a.length);
			for(j=0;j<d.maxPic;j++)
			{
				d.pictures[j]=new Image;
			}
		}
		
		
		
		do
		{
			if (a[i].indexOf("#")!=0 && (d.pictures[i].src=="" || d.pictures[i].src==d.URL))
			{
				d.pictures[i].src=(d.path+a[i]);
				window.status = "loading "+a[i];
			}
		} while (d.pictures[i].complete && ++i<a.length);


		if(i<a.length)
		{
			//build a string with the command to load the pictures
			strNextRec="loadPictures("
			for(j=0;j<a.length;j++)
			{
				strNextRec=strNextRec+"\'"+a[j]+"\',";
			}
			strNextRec=strNextRec.substr(0,strNextRec.length-1)+")";
			d.loadTimer=window.setTimeout(strNextRec,150);
		}
		else
			window.status = "loading complete";
	}
}

function loadCaptions()
{ // LPC 29-02-04
	var d=document;
	d.captions=new Array();

	var i,c=0,a=loadCaptions.arguments;
	for(i=0; i<a.length; i=i+2)
	{
		if (a[i+1].indexOf("#")!=0)
		{
			d.captions[c]=new String("<b>"+a[i]+"</b><br>"+a[i+1]);
			c++;
		}
	}
}

function picSet(picNum)
{
	var x,d=document;
	
	if((!d.pictures[picNum].complete) || d.pictures[picNum].src=="")
	{
		return(false);
	}
		
	if ( ((x=MM_findObj("photograph"))!=null) && (picNum<d.maxPic) )
	{
		d.curPic=picNum;
		x.src=d.pictures[picNum].src;
	}
	else return(false);

	if ((x=MM_findObj("caption"))!=null)
	{
		if (picNum<d.captions.length)		
			x.innerHTML=d.captions[picNum].valueOf();
		else
			x.innerHTML="";
	}
}

function pauseAndForward()
{
	slidePause();
	picForward();
}

function pauseAndBackward()
{
	slidePause();
	picBackward();
}

function picForward()
{
	var d=document;
	if ((d.curPic+1)>=d.maxPic)
		picSet(0);
	else
		picSet(d.curPic+1);
}

function picBackward()
{
	var d=document;
	if (d.curPic<=0)
		picSet(d.maxPic-1);
	else
		picSet(d.curPic-1);
}

function slideResume()
{
	var d=document;
	if(d.slideShow==false)
	{
		var d=document;
		d.slideShow=true;
		//Halve the timer for the first change to give a smoother start
		d.slideTimer=window.setTimeout('slideAdvance()',d.slideSpeed/2);
	}
	bb_setImages();
}

function slidePause()
{
	var d=document;
	if(d.slideShow==true)
	{
		var d=document;
		d.slideShow=false;
		window.clearTimeout(d.slideTimer);
	}
	bb_setImages();
}

function slideAdvance()
{
	var d=document;
	if(d.slideShow==true)
	{
		picForward();
		d.slideTimer=window.setTimeout('slideAdvance()',d.slideSpeed);
	}
}

function contacts()
{
	/* pop up the contact sheet page */
	var d=document;
	slidePause();
	if (!d.popUpWindow.closed && d.popUpWindow.location)
	{
		d.popUpWindow.location.href = "contacts.html";
	}
	else
	{
		d.popUpWindow=window.open("contacts.html",'Contact Sheet','height=200,width=150');
		if (!d.popUpWindow.opener) d.popUpWindow.opener = self;
	}
	if (window.focus) {d.popUpWindow.focus()}
}

function contactsJump(picNum)
{
	/* jump to a slide and close the contacts sheet */
	var d=document;
	opener.picSet(picNum);
	opener.focus();
	self.close();
}

function contactsClose()
{
	/* resume slideshow and close contacts sheet */
	opener.slideResume();
	opener.focus();
	self.close();
}

function initDoc()
{
	var d=document;
	
	MM_preloadImages(
	'../images/larrow_l.jpg','../images/larrow_d.jpg',
	'../images/pause_l.jpg','../images/pause_d.jpg',
	'../images/play_l.jpg','../images/play_d.jpg',
	'../images/rarrow_l.jpg','../images/rarrow_d.jpg');
	
	// we use full pathnames for maximum browser compatability
	var s = new String(d.URL);
	d.path = new String(s.substring(0,s.lastIndexOf('/'))+"/");

	// the following command should be in the story.js file in each story directory
	storyConfig();
	
	d.slideTimer = new Object;
	d.slideSpeed = new Number (6000);
	d.slideShow = new Boolean (true);
	d.popUpWindow = new Object;
	d.curPic=-1;
	
	// start the slideshow
	picSet(0);
	d.slideTimer=window.setTimeout('slideAdvance()',d.slideSpeed);
	bb_setImages();	
}
