
// ImageRef is an object that stores the information
// about the image that was most recently replaced
// with a 3D viewer so that it can be restored when
// another image is selected.
function ImageRef( id, type, width, height, alttext, resPath ) {
  this.id = id;
  this.type = type;
  this.width = width;
  this.height = height;
  this.alttext = alttext;
  this.resPath = resPath;
}

imageRefObj = new ImageRef( "-1", "", 0, 0, "" );

// showPicture is a function that replaces the named
function showPicture( id, width, height, type, alttext, resPath ) {
  if( document.getElementById ) {
    x = document.getElementById( id );
    var text = 
    '<a style="color:black;" href="javascript:showViewer(\'' + id + '\', ' + width + ', ' + height
      + ', \'' + type + '\', \'' + alttext + '\', \'' + resPath + '\')">\n'
    + '<img src=\"' + id + '.' + type + '\" ALT=\"' + alttext + '\" border=1 title=\"Click to View in 3D\">\n'
    + '</a>';
    imageRefObj = new ImageRef( "-1", "", 0, 0, "", "" );
    x.innerHTML = '';
    x.innerHTML = text;
  }
}

function showViewer( id, width, height, type, alttext, resPath ) {
  if( document.getElementById ) {
    if( imageRefObj.id != "-1" ) {
      showPicture( imageRefObj.id, imageRefObj.width, imageRefObj.height,
		   imageRefObj.type, imageRefObj.alttext, imageRefObj.resPath );
    }
    imageRefObj = new ImageRef( id, type, width, height, alttext, resPath );

    x = document.getElementById( id );
    var text =
      '<table class=FigureTable><TR><TD class=Figure3D>'
      +'<object classid="clsid:A275118D-C647-468F-8E99-49D5C7CF232F" '
      +'name=' + id + ' '
      +'id="3DViewer" '
      +'standby="Plugin Loading... Please wait!" '
      +'width="' + width + '" '
      +'height="' + height + '" '
      +'data=' + id + '.cvf>\n'
      +'<div style="position:relative;">'
      +'<a style="text-decoration:none; color:black;" href="javascript:showPicture(\''
      + id + '\', ' + width + ', ' + height
      + ', \'' + type + '\', \'' + alttext + '\', \'' + resPath + '\')">\n'
      +'<div style="position:absolute; top:' + eval( height / 5 )
      +'px; left:0px; width:' + width + 'px; height:0">'
      +'<center>'
      +'<span style="background-color:CCCCFF; font-size:140%; padding:5px 15px 5px 15px">'
      +'<b>3D Viewer Not Supported</b>'
      +'</span><br><br>'
      +'<span style="background-color:CCCCFF; font-size:100%; padding:5px 15px 5px 15px">'
      +'Click to cancel viewer mode'
      +'</span>'
      +'</center>'
      +'</div>\n'
      +'<img src="' + id + '.' + type + '" ALT="' + alttext + '" border=0 title="3D Not Supported">\n'
      +'</a>'
      +'</div>\n'
      +'</object>\n'
      +'</TD><TD class=FigureClose3D>\n'
      +'<a href="javascript:showPicture(\'' + id + '\', ' + width + ', ' + height
      + ', \'' + type + '\', \'' + alttext + '\', \'' + resPath + '\')">\n'
      +'<img src="' + resPath + 'Close3DViewer.png" border=0 title="Close 3D Viewer">\n'
      +'</a>'
      +'</TD></TR></table>';
    x.innerHTML = '';
    x.innerHTML = text;
  }
}
