/* MOPC scripts
   Author: 			Kristina Masuwa-Morgan (October 2002)

 Functions:
  Getnowdate		Calls the current date and places it into a textbox
  Timeoutload
  locateit			Opens a link in the main window
  tick				starts an onscreen timer
  sendit			display message after sending data - accepts message and subject as parameter
  RotatePic
  PreloadRotate
*/


var n=0;
var timeout=0;
var remote;
var historyitems=0;
 var newgallery=0;
 var totgallery1=0;
 var totgallery2=0;
 var totgallery3=0;
 var gallery1 = new Array();
 var gallery2 = new Array();
 var gallery3 = new Array();
 var gallery1pos=0;
 var gallery2pos=0;
 var gallery3pos=0;



// Variables for RotatePic
var pic = new Array();
  pic[0]="images/gallery/land1.jpg";
  pic[1]="images/gallery/land2.jpg";
  pic[2]="images/gallery/land3.jpg";
  pic[3]="images/gallery/land4.jpg";
  pic[4]="images/gallery/land5.jpg";
  pic[5]="images/gallery/land6.jpg";
  pic[6]="images/gallery/land7.jpg";
  pic[7]="images/gallery/land8.jpg";
  
var picLabel = new Array;
  picLabel[0]="images/img1.gif";
  picLabel[1]="images/img5.gif";
  picLabel[2]="images/img8.gif";
  
var newpic = 0;
var totalpics = pic.length;

// Variables for RotatePreload
var myImage=new Array();
	myImage[0]="images/gallery/img1.jpg";
	myImage[1]="images/gallery/img2.jpg";
	myImage[2]="images/gallery/img3.jpg";
	myImage[3]="images/gallery/img4.jpg";
	myImage[4]="images/gallery/img5.jpg";
	myImage[5]="images/gallery/img6.jpg";
	myImage[6]="images/gallery/img7.jpg";
	myImage[7]="images/gallery/img8.jpg";
	myImage[8]="images/gallery/img9.jpg";
	myImage[9]="images/gallery/img10.jpg";
	myImage[10]="images/gallery/img11.jpg";
	myImage[11]="images/gallery/container.jpg";
	myImage[12]="images/gallery/josh.jpg";
	myImage[13]="images/gallery/marywilliams.jpg";
	myImage[14]="images/gallery/rowena.jpg";
	myImage[15]="images/denzel&chickenpostcard.jpg";
	
var reIntegrate = new Array();
	reIntegrate[0]="images/reintegration/img1.jpg";
	reIntegrate[1]="images/reintegration/img2.jpg";
	reIntegrate[2]="images/reintegration/img3.jpg";
	reIntegrate[3]="images/reintegration/img4.jpg";
	reIntegrate[4]="images/reintegration/img5.jpg";
	reIntegrate[5]="images/reintegration/img6.jpg";
	reIntegrate[6]="images/reintegration/img7.jpg";
	reIntegrate[7]="images/reintegration/img8.jpg";
	reIntegrate[8]="images/reintegration/img9.jpg";
	reIntegrate[9]="images/reintegration/img10.jpg";
	reIntegrate[10]="images/reintegration/img11.jpg";
	reIntegrate[11]="images/reintegration/img12.jpg";
	reIntegrate[12]="images/reintegration/img13.jpg";
	reIntegrate[13]="images/reintegration/img14.jpg";
	reIntegrate[14]="images/reintegration/img15.jpg";
	reIntegrate[15]="images/reintegration/img16.jpg";
	reIntegrate[16]="images/reintegration/img17.jpg";
	reIntegrate[17]="images/reintegration/img18.jpg";
	reIntegrate[18]="images/reintegration/img19.jpg";
	reIntegrate[19]="images/reintegration/img20.jpg";
	reIntegrate[20]="images/reintegration/img21.jpg";
	reIntegrate[21]="images/reintegration/img22.jpg";
	
var preload=new Array();
var j=0;
var i=0;

var needs=new Array();
	needs[0]="images/gallery/needs/p1.jpg";
	needs[1]="images/gallery/needs/p2.jpg";
	needs[2]="images/gallery/needs/p3.jpg";
	needs[3]="images/gallery/needs/p4.jpg";
	needs[4]="images/gallery/needs/p5.jpg";
	needs[5]="images/gallery/needs/p6.jpg";
	needs[6]="images/gallery/needs/p7.jpg";
	needs[7]="images/gallery/needs/p8.jpg";

	
function RotatePic() {
  if (newpic == totalpics) {
    newpic = 0;
  }
  
  document.images.banner1.src=pic[newpic];
  //document.images.banner.title=picLabel[newpic];
  // i.e. "4*1000" is 4 seconds
  timeout=window.setTimeout("RotatePic(); Swapit();", 6000);
  newpic++;
}


function RotatePreload()
{
 for(i=0; i<myImage.length; i++)
  {
   preload[i]=new Image();
   preload[i].src=myImage[i];
  }
}

function RotateNeeds()
{
 for(i=0; i<needs.length; i++)
  {
   preload[i]=new Image();
   preload[i].src=needs[i];
  }
}

function RotateReintegrate()
{
 for(i=0; i<reIntegrate.length; i++)
  {
   preload[i]=new Image();
   preload[i].src=reIntegrate[i];
  }
}


function Swapit()
 {	
  // for(j=0; j<preload.length; j++)
  // {
  	if (j==preload.length) j=0;
  	document.images.banner2.src=preload[j].src;	
  	j++;
 // }
 }


function getGalleries()
{for (n = 0; n < 30; n++) {    
  gallery1[n]="images/gallery/apr2008/p" + n + ".jpg";
 }
 totgallery1=n-1;

   
 for (n = 0; n < 86; n++) {  
  gallery2[n]="images/gallery/apr2009/p" + n + ".jpg";
 }
 totgallery2=n-1;
    
 for (n = 0; n < 34; n++) {
  gallery3[n]="images/gallery/apr2010/p" + n + ".jpg";
 } 
 
 totgallery3=n-1; 
 
 getFirst1();
 getFirst2();
 getFirst3();
}


function ScrollDown1() {
  if (gallery1pos==totgallery1)
  		gallery1pos=0
  	else gallery1pos++;
  ScrollGallery1();
}

function getFirst1() {
  gallery1pos=0;
  ScrollGallery1();
}

function getLast1() {
  gallery1pos=totgallery1-2;
  ScrollGallery1();
}

function ScrollUp1() {
  if (gallery1pos<5)
  	{
  	gallery1pos=(totgallery1+gallery1pos-4)}
  else 
  	gallery1pos=(gallery1pos-5);
  	
  ScrollGallery1();
}


function checkpos1()
{gallery1pos++;
 if(gallery1pos==totgallery1+1) 
	{
	 gallery1pos=0;}
	
}	
	
function ScrollGallery1() {
	document.images.ga1_0.src=gallery1[gallery1pos];
  	document.images.ga1_0.title="p" + (gallery1pos);
  	
  	checkpos1()
  	document.images.ga1_1.src=gallery1[gallery1pos];
  	document.images.ga1_1.title="p" + (gallery1pos)
  	
  	checkpos1();
  	document.images.ga1_2.src=gallery1[gallery1pos];
 	document.images.ga1_2.title="p" + (gallery1pos);
 }


function ScrollDown2() {
  if (gallery2pos==totgallery2)
  		gallery2pos=0
  	else gallery2pos++;
  ScrollGallery2();
}

function getFirst2() {
  gallery2pos=0;
  ScrollGallery2();
}

function getLast2() {
  gallery2pos=totgallery2-2;
  ScrollGallery2();
}

function ScrollUp2() {
  if (gallery2pos<5)
  	{
  	gallery2pos=(totgallery2+gallery2pos-4)}
  else 
  	gallery2pos=(gallery2pos-5);
  	
  ScrollGallery2();
}


function checkpos2()
{gallery2pos++;
 if(gallery2pos==totgallery2+1) 
	{
	 gallery2pos=0;}
	
}	
	
function ScrollGallery2() {
	document.images.ga2_0.src=gallery2[gallery2pos];
  	document.images.ga2_0.title="p" + (gallery2pos);
  	
  	checkpos2()
  	document.images.ga2_1.src=gallery2[gallery2pos];
  	document.images.ga2_1.title="p" + (gallery2pos)
  	
  	checkpos2();
  	document.images.ga2_2.src=gallery2[gallery2pos];
 	document.images.ga2_2.title="p" + (gallery2pos);
 }


function ScrollDown3() {
  if (gallery3pos==totgallery3)
  		gallery3pos=0
  	else gallery3pos++;
  ScrollGallery3();
}

function getFirst3() {
  gallery3pos=0;
  ScrollGallery3();
}

function getLast3() {
  gallery3pos=totgallery3-2;
  ScrollGallery3();
}

function ScrollUp3() {
  if (gallery3pos<5)
  	{
  	gallery3pos=(totgallery3+gallery3pos-4)}
  else 
  	gallery3pos=(gallery3pos-5);
  	
  ScrollGallery3();
}


function checkpos3()
{gallery3pos++;
 if(gallery3pos==totgallery3+1) 
	{
	 gallery3pos=0;}
	
}	
	
function ScrollGallery3() {
	document.images.ga3_0.src=gallery3[gallery3pos];
  	document.images.ga3_0.title="p" + (gallery3pos);
  	
  	checkpos3()
  	document.images.ga3_1.src=gallery3[gallery3pos];
  	document.images.ga3_1.title="p" + (gallery3pos)
  	
  	checkpos3();
  	document.images.ga3_2.src=gallery3[gallery3pos];
 	document.images.ga3_2.title="p" + (gallery3pos);
 }



function stoptimer()
    {
     clearTimeout(timeout);
    }
//-->
function getnowdate()
  {
   var days=new Array("Sun","Mon","Tue","Wed","Thur","Fri","Sat");
   var mons=new Array ("January","February","March","April","May","June","July","August","September","October","November","December");
   var today=new Date();
   dayofweek=today.getDay();
   dayno=today.getDate();
   monthno=today.getMonth();
   year=today.getFullYear();
   hr=today.getHours();
   mn=today.getMinutes();
   ss=today.getSeconds();
   ms=today.getTime();
   datetoday=days[dayofweek]+", "+dayno+" "+mons[monthno]+" "+year;

  }

function setnowdate()
  {getnowdate();
   window.document.dateform.datebox.value=datetoday;
  }

function tick()
  {getnowdate();
   if(hr<=9) hr="0"+hr;
   if(mn<=9) mn="0"+mn;
   if(ss<=9) mn="0"+ss;

   var tt=" ("+hr+":"+mn+":"+ss+")";

   window.document.dateform.datebox.value=datetoday+tt;
   ticktime=window.setTimeout("tick()",1000);
  }


function timeoutload()
  {timeout=window.setTimeout("window.location.href='ShapevleFullyFramed.htm';clearTimeout(timeout);",60000);	
  }


function openwin(windoc,winname)
 {var w_width=window.screen.width;
  var w_height=window.screen.height;

  if(document.layers)
  {
   remote=window.open(windoc,winname,"top=0,left=0,resizable, scrollbars, status, height=w_height, width=w_width");
   
  }
  else
  {
   remote=window.open(windoc,winname, "left=0,top=0, toolbar,menubar, resizable, scrollbars, directories, height=700, width=1000");
  }
   if (remote.opener==null) remote.opener = window;
   remote.opener.name=winname+"Opener";	
  }


function locateit(wantedurl)
 {
  if(parent!=window) {parent.location=wantedurl;}
    else window.location.href=wantedurl;
    historyitems=historyitems+1;
 }


function backone()
 {window.history.go(-1);
 }



//Change colour of button
function ChangeColor(btnid)
  {//var btn=document.getElementById(btnid);
   btnid.bgcolor="#0000FF";
   btnid.fgcolor="#FFFF00";
  }

function sendit(themessage,thesubject)
{document.feedbackform.subject=thesubject;
 document.feedbackform.action="mailto:km22@cant.ac.uk" ;
 alert(themessage);
 backone();
}


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) { //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];}
}



