//initialize global variables.
oldDiv = 'noObj';
oldDescriptionBlock = 'noObj';
newDescriptionBlock = 'noObj';

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_changeProp(objName,x,theProp,theValue) { //v6.0

	
	
	oldDiv = objName; //Record "in-focus" image object.
  
  var obj = MM_findObj(objName);

  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){

    if (theValue == true || theValue == false)

      eval("obj."+theProp+"="+theValue);

    else eval("obj."+theProp+"='"+theValue+"'");

  }
  
  //Begin description block handling section.
	var j = objName.slice(objName.length-1,objName.length);	
	if (j=='b' && theValue=='block') { //If function call is changing the "big" image's style property to "display:block".
		newDescriptionBlock = objName.slice(0,5) + '-d'; //Record the object name for the associated description block.		
		//alert(oldDescriptionBlock + "  " + newDescriptionBlock);
		
		toggleDescriptionBlock(newDescriptionBlock, 'img'); //Show associated description block.
	}	
	//End description block handling section.
}

function MM_changePropOldObject(theProp,theValue,theValue2) { //v6.0

  var oldDiv_array = oldDiv.split("-");

  //<<DEBUG>> alert(oldDiv_array[0]);
  
  // Hide a "big" image.
  var obj = MM_findObj(oldDiv_array[0] + '-b');

  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){

    if (theValue == true || theValue == false)

      eval("obj."+theProp+"="+theValue);

    else eval("obj."+theProp+"='"+theValue+"'");

  } 
  
	// Show its associated "small" image.
  var obj = MM_findObj(oldDiv_array[0] + '-s');

  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){

    if (theValue2 == true || theValue2 == false)

      eval("obj."+theProp+"="+theValue2);

    else eval("obj."+theProp+"='"+theValue2+"'");

  }

}

function toggleDisplay(strObjName) {
	if (document.getElementById && document.getElementById(strObjName) != null) {
		if (document.getElementById(strObjName).style.display=='none') {
			showDisplay(strObjName);}
		else {
			hideDisplay(strObjName);}
	}
}

function toggleDescriptionBlock(strObjName, strTrigger) {
	
	if (document.getElementById && document.getElementById(strObjName) != null) {
		if (strObjName != oldDescriptionBlock) {
			if (document.getElementById(strObjName).style.display == 'none') {
				showDisplay(strObjName);
				
				//alert(strObjName.slice(0,5) + "  " + oldDescriptionBlock.slice(0,5))
				//alert(strObjName.slice(3,5));
				var cellNum = strObjName.slice(3,5);
				scrollPage(cellNum);
				//window.scrollTo(0,0);								
				if (oldDescriptionBlock != 'noObj' && strObjName.slice(0,5) != oldDescriptionBlock.slice(0,5)) { 
					hideDisplay(oldDescriptionBlock);
				}
			}
			oldDescriptionBlock = strObjName;
		}
		else if (strTrigger != 'img' && document.getElementById(strObjName).style.display != 'none') {
			hideDisplay(strObjName);
		}
		else {
			showDisplay(strObjName);
		}			
	}
}

function showDisplay(object) {
	if (document.getElementById && document.getElementById(object) != null)
		 node = document.getElementById(object).style.display='block';
	else if (document.layers && document.layers[object] != null)
		document.layers[object].display = 'block';
	else if (document.all)
		document.all[object].style.display = 'block';
}

function hideDisplay(object) {
	if (document.getElementById && document.getElementById(object) != null)
		 node = document.getElementById(object).style.display='none';
	else if (document.layers && document.layers[object] != null)
		document.layers[object].display = 'none';
	else if (document.all)
		document.all[object].style.display = 'none';
}

function toggleObjVisibility(objectA, objectB) {

	if (document.getElementById && document.getElementById(objectA) != null) {
		if (document.getElementById(objectA).style.display=='none') {
			hideDisplay('portfolio');
			hideDisplay(objectB);
			showDisplay(objectA);}
		else {
			hideDisplay(objectA);
			hideDisplay(objectB);
			showDisplay('portfolio');}
	}
}

function showLink (strObjNameA, strObjNameB, strColorA, strColorB) {

	if (document.getElementById && document.getElementById(strObjNameA) != null) {
		if (document.getElementById(strObjNameB) != null){
			document.getElementById(strObjNameA).style.color = strColorA;
			document.getElementById(strObjNameB).style.color = strColorB;
		}
	}
}

function scrollPage(strCell) {
	
	var x,y
	switch (strCell) {
		case '01': x=0; y=140; break;
		case '02': x=0; y=140; break;
		case '03': x=0; y=300; break;
		case '04': x=0; y=300; break;
		case '05': x=0; y=425; break;
		case '06': x=0; y=425; break;
		case '07': x=0; y=550; break;
		case '08': x=0; y=550; break;
		case '09': x=0; y=800; break;
		case '10': x=0; y=800; break;
		case '11': x=0; y=1300; break;
		case '12': x=0; y=1500; break;
		default:	x=0; y=0;	
	}
	window.scrollTo(x,y);
}

var imageIndex = 0;

function displayImage() {

	if (document.images) {
	var target = document.getElementById("theImage");
	target.src = myImages[imageIndex];
	}
}

function stepPrevious() {

	var strDecriptionID = "description" + String(imageIndex+1);	
	hideDisplay(strDecriptionID);
	
	if (imageIndex > 0) {
		imageIndex--;
	}
	else {
		imageIndex = myImages.length - 1;
	}
		
	strDecriptionID = "description" + String(imageIndex+1);		
	showDisplay(strDecriptionID);
	displayImage();		
}

function stepNext() {

	var strDecriptionID = "description" + String(imageIndex+1);
	hideDisplay(strDecriptionID);
	
	if (imageIndex < myImages.length - 1)
		{imageIndex++;}
	else
		{imageIndex = 0;}
	
	strDecriptionID = "description" + String(imageIndex+1);
	showDisplay(strDecriptionID);				
	displayImage();		
}