// JavaScript Document

// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}

// Accepts a variable number of arguments, in triplets as follows:
// arg 1: simple name of a layer object, such as "Layer1"
// arg 2: ignored (for backward compatibility)
// arg 3: 'hide' or 'show'
// repeat...
//
// Example: showHideLayers(Layer1,'','show',Layer2,'','hide');

function showHideLayers()
{ 
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  {
    if ((obj = findObj(args[i])) != null)
    {
      visStr = args[i+2];
      if (obj.style)
      {
        obj = obj.style;
        if(visStr == 'show') visStr = 'visible';
        else if(visStr == 'hide') visStr = 'hidden';
      }
      obj.visibility = visStr;
    }
  }
}

function getCenterX() {
  if (document.all) {
    /* the following is only available after onLoad */
    w = document.body.clientWidth;
    x = window.screenLeft;
  } else {
    w = window.innerWidth;
    x = window.screenX+((window.outerWidth-window.innerWidth)/2);
  }
  return x+(w/2);
}
function getCenterY() {
  if (document.all) {
    /* the following is only available after onLoad */
    h = document.body.clientHeight;
    y = window.screenTop;
  } else {
    h = window.innerHeight;
    y = window.screenY+((window.outerHeight-window.innerHeight)/2);
  }
  return y+(h/2);
}

function showLayers()
{ 
  var i, obj, args = showLayers.arguments;
  for (i=0; i<(args.length); i+=1)
  {
    if ((obj = findObj(args[i])) != null)
    {
      if (obj.style)
      {
        obj = obj.style;
      }
      obj.display = 'block';
    }
  }
}

function hideLayers()
{ 
  var i, visStr, obj, args = hideLayers.arguments;
  for (i=0; i<(args.length); i+=1)
  {
    if ((obj = findObj(args[i])) != null)
    {
      if (obj.style)
      {
        obj = obj.style;
      }
      obj.display = 'none';
    }
  }
}

function swap()
{
  var i, visStr, obj1, obj2, args = swap.arguments;
  for (i=0; i<(args.length); i+=1)
  {
    if (((obj1 = findObj('thumb'+args[0])) != null) && ((obj2 = findObj('full'+args[0])) != null))
    {
      if (obj1.style)
      {
        obj1 = obj1.style;
      }
      if (obj2.style)
      {
        obj2 = obj2.style;
      }
      visStr = obj1.display;
	  obj1.display = obj2.display;
	  obj2.display = visStr;
    }
  }
}

function swapImage()
{
  var i, visStr, obj1, obj2, args = swapImage.arguments;

    if (((obj1 = findObj(args[0])) != null))
    {
	strng = new String();
	strng = obj1.src;
	strng = strng.substring(strng.lastIndexOf('images/'),strng.length);


	  if ( strng == args[1][args[1][0]] ) {
	  	obj1.src = args[1][1];
	  } else {
  for (i=(args[1][0]-1); i>0; i-=1)
  {
	  if ( strng == args[1][i] ) {
	  	obj1.src = args[1][i+1];
	  }  
  }	  	
	  }
    }
  
}

function goUp()
{
  var i, strng, strng2, visStr, obj1, obj2, args = goUp.arguments;

    if (((obj1 = findObj('image'+args[0])) != null))
    {
	strng = new String();
	strng = obj1.innerHTML;
	strng = strng.substring(strng.lastIndexOf('images/'),strng.length);

  for (i=(args[1][0]-1); i>0; i-=1)
  {
  	  	obj2 = findObj(args[1][i]);	
			strng2 = new String();
	strng2 = obj2.innerHTML;
	strng2 = strng2.substring(strng2.lastIndexOf('images/'),strng2.length);
	  if ( strng == strng2 ) {
	  	obj2 = findObj(args[1][i+1]);	 
	  	obj1.innerHTML = obj2.innerHTML;
	  }  
  }	  	
    }
  
}

function goDown()
{
  var i, strng, strng2, visStr, obj1, obj2, args = goDown.arguments;

    if (((obj1 = findObj('image'+args[0])) != null))
    {
	strng = new String();
	strng = obj1.innerHTML;
	strng = strng.substring(strng.lastIndexOf('images/'),strng.length);

	// obj2 = findObj(args[1][1]);
	 // alert(obj1);
	 // alert(strng);

  for (i=2; i<=(args[1][0]); i+=1)
  {
	  
	obj2 = findObj(args[1][i]);	 
	strng2 = new String();
	strng2 = obj2.innerHTML;
	strng2 = strng2.substring(strng2.lastIndexOf('images/'),strng2.length);
    //alert(strng+', '+strng2);
	if ( strng == strng2 ) {
	//alert('eq');
	obj2 = findObj(args[1][i-1]);	
  	obj1.innerHTML = obj2.innerHTML;
	  }  
  }	  	

    }
  
}

function active()
{
  var i, visStr, obj1, obj2, args = active.arguments;
  for (i=1; i<=layercount; i+=1)
  {
    if ((obj1 = findObj('full'+i)) != null)
    {
      if (obj1.style)
      {
        obj1 = obj1.style;
      }
	  obj1.display = 'none';
    }
    if ((obj2 = findObj('thumb'+i)) != null)
    {
      if (obj2.style)
      {
        obj2 = obj2.style;
      }
	  obj2.display = 'block';
    }
  }
  if ((obj1 = findObj(args[0])) != null && (obj2 = findObj(args[1])) != null)
    {
      if (obj1.style)
      {
        obj1 = obj1.style;
      }
      if (obj2.style)
      {
        obj2 = obj2.style;
      }
	  obj1.display = 'block';
	  obj2.display = 'none';
    }
}

