// Rollover
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_findObj(n, d) { //v4.01
  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() { //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];}
}

// Yes, this code needs work
// There's really no need for all these if statements
// but when you've only got so much time...
var groupCount=4;

// Switch out portfolio screenshot from server
function switchPhoto(shot,locus) {	
	// document.images[shot].src=locus;
	
	// show progress layer for photo load in IE
	if (isMinIE4) {
		if (shot == 's1' && groupCount >= 1){
		showLayer(s1_load);
		}
		else if (shot == 's2' && groupCount >= 2){
		showLayer(s2_load);
		}
		else if (shot == 's3' && groupCount >= 3){
		showLayer(s3_load);
		}
		else if (shot == 's4' && groupCount >= 4){
		showLayer(s4_load);
		}
		else if (shot == 's5' && groupCount >= 5){
		showLayer(s5_load);
		}
	}
	document.images[shot].src=locus;
}

// Switch out visible layers
function switchShot(groupNum,newNum) {
	if (!initialized) return;
	
	newID = groupNum[newNum];
	
	// For first case study
	if (groupNum == g1 && groupCount >= 1){
		oldID = groupNum[g1_activeNum];
		compareShot (newID,oldID);
		g1_activeNum = newNum;
	}
	
	// For second case study (repeat as needed)
	else if (groupNum == g2 && groupCount >= 2){		
		oldID = groupNum[g2_activeNum];
		compareShot (newID,oldID);
		g2_activeNum = newNum;
	}
	
	// For third case study (repeat as needed)
	else if (groupNum == g3 && groupCount >= 3){		
		oldID = groupNum[g3_activeNum];
		compareShot (newID,oldID);
		g3_activeNum = newNum;
	}
	
	// For fourth case study (repeat as needed)
	else if (groupNum == g4 && groupCount >= 4){		
		oldID = groupNum[g4_activeNum];
		compareShot (newID,oldID);
		g4_activeNum = newNum;
	}
	
	// For fifth case study (repeat as needed)
	else if (groupNum == g5 && groupCount >= 5){		
		oldID = groupNum[g5_activeNum];
		compareShot (newID,oldID);
		g5_activeNum = newNum;
	}
}

// Determine if a layer is already visible
// and swap it out with a new one when told to do so
// by the function above
function compareShot(newID,oldID) {
	var newShot = getLayer(newID);
	var oldShot = getLayer(oldID);
		
	if (oldShot && newShot) hideLayer(oldShot);
	if (newShot) showLayer(newShot);
}

// Initialize collection of layers
function init() {

	// Define layers for the links and captions below screenshots
	
	// First case study
	g1 = new Array();
	g1[0] = "p1_0" ;
	g1[1] = "p1_1" ;
	g1[2] = "p1_2" ;
	g1[3] = "p1_3" ;
	g1[4] = "p1_4" ;
	
	// Second case study (repeat as needed)
	g2 = new Array();
	g2[0] = "p2_0" ;
	g2[1] = "p2_1" ;
	g2[2] = "p2_2" ;
	g2[3] = "p2_3" ;
	g2[4] = "p2_4" ;

	// Third case study (repeat as needed)
	g3 = new Array();
	g3[0] = "p3_0" ;
	g3[1] = "p3_1" ;
	g3[2] = "p3_2" ;
	g3[3] = "p3_3" ;
	g3[4] = "p3_4" ;
	
	// Fourth case study (repeat as needed)
	g4 = new Array();
	g4[0] = "p4_0" ;
	g4[1] = "p4_1" ;
	g4[2] = "p4_2" ;
	g4[3] = "p4_3" ;
	g4[4] = "p4_4" ;
	
	// Fifth case study (repeat as needed)
	g5 = new Array();
	g5[0] = "p5_0" ;
	g5[1] = "p5_1" ;
	g5[2] = "p5_2" ;
	g5[3] = "p5_3" ;
	g5[4] = "p5_4" ;
			
	// Set to loading position
	//ActiveArrayName = LayerArray;
	if (groupCount >= 1){
		g1_activeNum = 1;
	} if (groupCount >= 2){
		g2_activeNum = 1;
	} if (groupCount >= 3){
		g3_activeNum = 1;
	} if (groupCount >= 4){
		g4_activeNum = 1;
	} if (groupCount >= 5){
		g5_activeNum = 1;
	}
	
	initialized = 1;
		
	window.setTimeout("preloadsite()", 500);
}

// Make sure to initialize every case study
function preloadsite() {
	if (groupCount >= 1){
		switchShot(g1,1);
	} if (groupCount >= 2){
		switchShot(g2,1);
	} if (groupCount >= 3){
		switchShot(g3,1);
	} if (groupCount >= 4){
		switchShot(g4,1);
	}
}