// JavaScript Document
var ImageArry= new Array("missoula001","missoula002","missoula003","missoula004","missoula005","missoula006","missoula007","missoula008","missoula009","missoula010","missoula011","missoula012","missoula013","missoula014","missoula015","missoula016","missoula017","missoula018","missoula019","missoula020","missoula021","missoula022","missoula023","missoula024","missoula025","missoula026","missoula027","missoula028","missoula029","missoula030","missoula031","missoula032");

var ChangeSize=new Array();
 ChangeSize[0]=new Array("0","0","0","40","13");
 ChangeSize[1]=new Array("0","0","53","40","13");
 ChangeSize[2]=new Array("0","0","53","40","13");
 ChangeSize[3]=new Array("0","0","53","40","13");
 ChangeSize[4]=new Array("0","0","53","40","13");
 ChangeSize[5]=new Array("0","0","53","40","13");
 ChangeSize[6]=new Array("0","0","53","40","13");
 ChangeSize[7]=new Array("0","0","53","40","13");
 ChangeSize[8]=new Array("0","0","53","40","13");
 ChangeSize[9]=new Array("0","0","0","40","13");
//bigger flag, smaller flag,x,y
var folder="images/";
var ImageArraySize=ImageArry.length;
var RotateCnt=3;
var resetRotateCnt=3;
var WidthAdjustBy=3; // pixels
var DoAgain=50; // mS
var ImagePointer=0;
var LAgain;
var Lwidth=53; 
var ResetLwidth=53;
var Rwidth=0;
var ResetRwidth=0;
var next=0;
var goLswitch=0;
var goRswitch=0;
var run_switch=false;
var ReSize;

function MousedInPic(mIn){
  if(ChangeSize[mIn][0]==0 && ChangeSize[mIn][1]==0 && ChangeSize[mIn][2]==53){ChangeSize[mIn][0]=1;ChangeSize[mIn][1]=0;
  }else{ChangeSize[mIn][0]=0;ChangeSize[mIn][1]=1;}
  
  if(run_switch==false){run_switch=true;clearTimeout(ReSize);ReSize=setTimeout("PicReSize();",2);}
}

function PicReSize(){
  var sstop=0;

  for(var loop=0;sstop<2;loop++){
	if(loop==10){loop=0;sstop++;}
     
    if(sstop < 2){ 
	  if(ChangeSize[loop][0]==1 && ChangeSize[loop][1]==0){
	    ChangeSize[loop][2]++;
	    if(ChangeSize[loop][2] > 76){ChangeSize[loop][2]=76;}
	    ChangeSize[loop][3]=Math.round((40/53)*ChangeSize[loop][2]);
	    if(ChangeSize[loop][2]>75){ChangeSize[loop][0]=0;
		}else{sstop=0;}
	  }
	  if(ChangeSize[loop][1]==1 && ChangeSize[loop][0]==0){
	    ChangeSize[loop][2]--;
	    if(ChangeSize[loop][2] < 53){ChangeSize[loop][2]=53;}
	    ChangeSize[loop][3]=Math.round((40/53)*ChangeSize[loop][2]);
	    if(ChangeSize[loop][2]< 54){ChangeSize[loop][1]=0;
		}else{sstop=0;}  //Stop Values
	  }
	  var newpad=(ChangeSize[loop][3]);
      ChangeSize[loop][4] = 52-newpad;
	  EndRepeat(loop); 
	}else{run_switch=false;}
  }
}

function EndRepeat(where){
  document.getElementById("img"+where).style.width=ChangeSize[where][2]+"px";
  document.getElementById("img"+where).style.height=ChangeSize[where][3]+"px";
  document.getElementById("img"+where).style.marginTop=ChangeSize[where][4]+"px";
}

function WhupsReset(){
 for(var tmpJ=1;tmpJ<9;tmpJ++){
   ChangeSize[tmpJ][2]=53;
   ChangeSize[tmpJ][3]=40;
 }
 for(var tmpI=1;tmpI<9;tmpI++){
  document.getElementById("img"+tmpI).style.width=53+"px";
  document.getElementById("img"+tmpI).style.height=40+"px";
 }
}

function GoLeft(){  
  if((ImagePointer+8) < ImageArraySize){
     if(next==0){
	   document.getElementById("img9").src=folder+ImageArry[(ImagePointer+8)]+".jpg";
	   XShrink();
	 }else{
	   next=0;
  	   ImagePointer++; 	   
	   document.getElementById("img1").style.width=53+"px";
	   document.getElementById("img9").style.width=0+"px";
	   document.getElementById("img9").src="";
	   document.getElementById("img0").src="";
	   for(var Xagain=0;Xagain<10;Xagain++)
	     {document.getElementById("img"+Xagain).src=folder+ImageArry[(ImagePointer+Xagain-1)]+".jpg";}
	   if(RotateCnt > 1){RotateCnt--;XShrink();}
	   else{RotateCnt=resetRotateCnt;}
	 }
  }
}

function XShrink(){
  Lwidth=Lwidth-WidthAdjustBy;
  if(Lwidth<0){Lwidth=0;}
  document.getElementById("img1").style.width=Lwidth+"px";
  
  Rwidth=Rwidth+WidthAdjustBy;
  if(Rwidth>53){Rwidth=53;}
  document.getElementById("img9").style.width=Rwidth+"px";
  
  if(Rwidth == 53){Lwidth=ResetLwidth;Rwidth=ResetRwidth;next=1;}
  clearTimeout(LAgain);LAgain=setTimeout("GoLeft();",DoAgain);
}

function GoRight(){
  if(ImagePointer> 0){     
     if(next==0){
	   document.getElementById("img0").src=folder+ImageArry[(ImagePointer-1)]+".jpg";
	   XExpand();
	 }else{
	   next=0;
  	   ImagePointer--;
	   for(var Xagain=0;Xagain<10;Xagain++)
	     {document.getElementById("img"+Xagain).src=folder+ImageArry[(ImagePointer+Xagain-1)]+".jpg";}
		 	   
	   document.getElementById("img0").style.width=ResetRwidth+"px";
	   document.getElementById("img0").src="";
	   document.getElementById("img9").src="";
	   document.getElementById("img8").style.width=ResetLwidth+"px";
	   
	   if(RotateCnt > 1){RotateCnt--;XExpand();}
	   else{RotateCnt=resetRotateCnt;}	
	 }
  }
}

function XExpand(){
  Lwidth=Lwidth-WidthAdjustBy;
  if(Lwidth<0){Lwidth=0;}
  document.getElementById("img8").style.width=Lwidth+"px";
  
  Rwidth=Rwidth+WidthAdjustBy;
  if(Rwidth>53){Rwidth=53;}
  document.getElementById("img0").style.width=Rwidth+"px";
  
  if(Rwidth == 53){Lwidth=ResetLwidth;Rwidth=ResetRwidth;next=1;}
  clearTimeout(LAgain);LAgain=setTimeout("GoRight();",DoAgain);
}

function MouseClick(ClickPick){
  document.getElementById("dispImage").src=folder+ImageArry[(ClickPick-1+ImagePointer)]+"_large.jpg";
} 



