var cache_obj = { 'dummy' : null };
cache_obj.imgs = ['somprologo.gif', 'frontseq1.jpg',
		  'frontseq2.jpg', 'frontseq3.jpg',
		  'frontseq4.jpg', 'frontseq5.jpg',
		  'frontseq6.jpg', //'frontseq7.jpg',
		  'frontseq8.jpg', 'frontseq9.jpg',
		  'applet-firsttime','applet-load2','applet-hide1',
		  'frontseq10.jpg','frontseq11.jpg',
		  'frontseq12.jpg','applet-show2',
		  'applet-load3','applet-hide2',
		  'frontseq13.jpg','frontseq14.jpg',
		  'applet-show1','applet-load4','applet-hide1',
		  'frontseq15.jpg','applet-show2',
		  'applet-hide2',
		  'somprologo.gif','applet-load5'
];
cache_obj.captions = [
		   'Rotate model by dragging with the left-mouse'
];
		      
		      
//cache the images
cache_obj.imgsLen = cache_obj.imgs.length;
cache_obj.cache = [];
function preloadImgs()
{
  for(var i=0; i<cache_obj.imgsLen; i++)
    {
      cache_obj.cache[i] = new Image;
      window.status = "preloading - 0%";
      if (cache_obj.imgs[i].substr(0,6) != 'applet')
	{
	  window.status = "preloading - " + parseInt(100*i/cache_obj.imgsLen) + "%";
	  cache_obj.cache[i].src = "img/"+cache_obj.imgs[i];
	}
      window.status = "done";
    }
}

var zoomscript="setAppletParameter('rotateY',-2);\n\
animateAppletParameter('positionZ',-2.6,3000);\n\
synch();\n\
setAppletParameter('rotateY',0);\n\
sleep(2000);\n\
setAppletParameter('rotateY',4);\n\
animateAppletParameter('positionZ',-3.2,4000);";

var stopscript="synch();\n\
setAppletParameter('rotateX',0);\n\
setAppletParameter('rotateY',0);";

var allparams="<param name='textureQuality' value='best'>\n"+
"<param name='lighting' value='smooth'>\n"+
"<param name='frameLimit' value='20'>\n";

function frontpage()
{
  preloadImgs();
  showDemo(0);
} 


function handle_over()
{
  return "click to replay";
}

function showViewerInstructions()
{
  setHTML(getObj("cap_frontpage"),"Left-drag to rotate<br>model");
}

function hideViewerInstructions()
{
  setHTML(getObj("cap_frontpage"),"3D models <br>from images");
}
  
function doFadeApplet(name)
{
  var divname = "div_"+name;
  hideAppletDiv(divname);
  setVisible("div_imgarea","visible");
  hideViewerInstructions();
  setTimeout('setHTML(getObj("'+divname+'"), "<!--  --->");',1000);
}

var tmOut = null;
var lastframe=0;

function dopause()
{
  clearTimeout(tmOut);
  tmOut = null;
  addPlayButton();
}

function doplay()
{
  addPauseButton();
  showDemo(lastframe+1);
}

function addPauseButton()
{
  var bholder = getObj("button_frontpage");
  setHTML(bholder,"<img onClick='dopause()' alt='pause show' src='img/pausebutton.gif'>");
}
function addPlayButton()
{
  var bholder = getObj("button_frontpage");
  setHTML(bholder,"<img onClick='doplay()' alt='resume show' src='img/playbutton.gif'>");
}

var nojavacode='To see the interactive 3D content on this page you should have a Java Virtual Machine installed and enabled. Check you security settings and browser options to check that Java is enabled (see www.java.com).';

//play the next part of the demo
function showDemo(i)
{
  if (tmOut != null) clearTimeout(tmOut);
  tmOut = null;
  if (i >= cache_obj.imgsLen) i = 0;

  var imgName = "img/"+cache_obj.imgs[i];
  lastframe = i;
  var nexttime = 2500;
  if (i == 0) 
    {
      var appcode = "<applet id='modelarea1' mayscript='1' scriptable='1' archive='../viewerb.jar,background.jar,vase.jar,vase_0.jar,vase_1.jar,vase_2.jar,vase_3.jar' codebase='proexamples/vase_files' code='javaRenderer.JavaRenderer.class' alt='To see the 3D model, please enable Java from your browser preferences' width='300' height='300'>\n";
      appcode += "<p><b>"+nojavacode+"</b></p>";
      appcode += "<param name='model' value='vase.123'>\n";
      appcode += allparams;
      appcode += "<param name='ambientLight' value='0.6'>\n";
      appcode += "<param name='diffuseLight' value='0.8'>\n";
      appcode += "<param name='specularLight' value='0.4'>\n";
      appcode += "<param name='bgImage' value='background.jpg'>\n";
      appcode += "<param name='rotateY' value='2'>\n";
      appcode += "<param name='rotateX' value='0'>\n";
//      appcode += "<param name='positionZ' value='-10'>\n";
      appcode += "</applet>";
      setHTML(getObj("div_modelarea1"), appcode);

      addPauseButton();
      hideAppletDiv("div_modelarea1");
      hideAppletDiv("div_modelarea2");
      setVisible("div_imgarea","visible");
      getObj("imgarea").src = imgName;
      nexttime = 6000;
    }

  if (cache_obj.imgs[i].substr(0,6) != 'applet')
    {
      crossfade(getObj("imgarea"),imgName,"0.8","");
      if (tmOut != null) clearTimeout(tmOut);
      }
  else if (cache_obj.imgs[i] == 'applet-firsttime')
    {
      try {
	var appref = getObj("modelarea1");
	appref.setAppletParameter("rotateX",0);
	appref.setAppletParameter("orientationX",-32.8);
	appref.setAppletParameter("orientationY",-70.7);
	appref.setAppletParameter("orientationZ",-50.7);
	appref.setAppletParameter("positionZ", -10);
	appref.setAppletParameter("script",zoomscript);
	appref.startScript();
      }
      catch (er) {}
      setTimeout("showAppletDiv('div_modelarea1');setVisible('div_imgarea','hidden');", 400);
      showViewerInstructions();
      nexttime=15000; // startloading the next model after 5 secs
    }
   else if (cache_obj.imgs[i] == 'applet-load2')
     {
      var appcode = "<applet id='modelarea2' mayscript='1' scriptable='1' archive='camcorder.jar,camcorder_0.jar,camcorder_1.jar,camcorder_2.jar,../viewerb.jar' codebase='proexamples/camcorder_files' code='javaRenderer.JavaRenderer.class' alt='"+nojavacode+"' width='300' height='300'>\n";
      appcode += "<p><b>"+nojavacode+"</b></p>";
//      appcode += "<param name='onInit' value='showDemo("+(i+1)+");'>\n";
      appcode += "<param name='model' value='camcorder.123'>\n";
      appcode += allparams;
	appcode += "<param name='rotateY' value='2'>\n";
      appcode += "<param name='ambientLight' value='0.8'>\n";
      appcode += "<param name='diffuseLight' value='0.2'>\n";
      appcode += "<param name='specularLight' value='0.1'>\n";
      appcode += "<param name='specularType' value='metal'>\n";
      appcode += "</applet>";
      setHTML(getObj("div_modelarea2"), appcode);
      nexttime=4000;
//      return;
     }
  else if (cache_obj.imgs[i] == 'applet-load3')
     {
      var appcode = "<applet id='modelarea1' mayscript='1' scriptable='1' archive='reebok.jar,reebok_0.jar,reebok_1.jar,reebok_2.jar,../viewerb.jar' codebase='proexamples/reebok_files' code='javaRenderer.JavaRenderer.class' alt='"+nojavacode+"' width='300' height='300'>\n";
      appcode += "<p><b>"+nojavacode+"</b></p>";
//      appcode += "<param name='onInit' value='showDemo("+(i+1)+");'>\n";
      appcode += "<param name='model' value='reebok.123'>\n";-10.0,71.7,-26
      appcode += allparams;
	appcode += "<param name='rotateY' value='2'>\n";
      appcode += "<param name='orientationX' value='-10'>\n";
      appcode += "<param name='orientationY' value='72'>\n";
      appcode += "<param name='orientationZ' value='-26'>\n";
      appcode += "<param name='ambientLight' value='0.7'>\n";
      appcode += "<param name='diffuseLight' value='0.4'>\n";
      appcode += "<param name='specularLight' value='0.0'>\n";
      appcode += "</applet>";
      setHTML(getObj("div_modelarea1"), appcode);
      nexttime=4000;
//      return;
     }
  else if (cache_obj.imgs[i] == 'applet-load4')
     {
      var appcode = "<applet id='modelarea2' mayscript='1' scriptable='1' archive='backdrop.jar,shell.jar,shell_0.jar,shell_1.jar,shell_2.jar,../viewerb.jar' codebase='proexamples/shell_files' code='javaRenderer.JavaRenderer.class' alt='"+nojavacode+"' width='300' height='300'>\n";
      appcode += "<p><b>"+nojavacode+"</b></p>";
//      appcode += "<param name='onInit' value='showDemo("+(i+1)+");'>\n";
      appcode += "<param name='model' value='shell.123'>\n";
      appcode += allparams;
	appcode += "<param name='rotateY' value='2'>\n";
      appcode += "<param name='ambientLight' value='0.6'>\n";
      appcode += "<param name='diffuseLight' value='0.4'>\n";
      appcode += "<param name='specularLight' value='0.0'>\n";
      appcode += "<param name='bgImage' value='backdrop.jpg'>\n";
      appcode += "</applet>";
      setHTML(getObj("div_modelarea2"), appcode);
//      return;
     }
  else if (cache_obj.imgs[i] == 'applet-load5')
     {
      var appcode = "<applet id='modelarea1' mayscript='1' scriptable='1' archive='background.jar,vase.jar,vase_0.jar,vase_1.jar,vase_2.jar,vase_3.jar,../viewerb.jar' codebase='proexamples/vase_files' code='javaRenderer.JavaRenderer.class' alt='To see the 3D model, please enable Java from your browser preferences' width='300' height='300'>\n";
      appcode += "<p><b>"+nojavacode+"</b></p>";
//      appcode += "<param name='onInit' value='lastframe=1;dopause();'>\n";
      appcode += "<param name='model' value='vase.123'>\n";
      appcode += allparams;
	appcode += "<param name='rotateY' value='2'>\n";
      appcode += "<param name='ambientLight' value='0.6'>\n";
      appcode += "<param name='diffuseLight' value='0.8'>\n";
      appcode += "<param name='specularLight' value='0.4'>\n";
      appcode += "<param name='bgImage' value='background.jpg'>\n";
      appcode += "</applet>";
      setHTML(getObj("div_modelarea1"), appcode);
      lastframe=1;
      dopause();
      return;
     }
  else if (cache_obj.imgs[i] == 'applet-hide1')
    {
      try { 
	getObj("modelarea1").animateAppletParameter("positionZ",-15,1500); 
      }
      catch (er) {}
      setTimeout('doFadeApplet("modelarea1");',1500);
    }
  else if (cache_obj.imgs[i] == 'applet-hide2')
    {
      try { 
	getObj("modelarea2").animateAppletParameter("positionZ",-15,1500); 
      }
      catch (er) {}
      setTimeout('doFadeApplet("modelarea2");',1500);
    }
  else if (cache_obj.imgs[i] == 'applet-show2')
    {
      try {
	var appref = getObj("modelarea2");
	appref.setAppletParameter("rotateX",0);
	appref.setAppletParameter("positionZ", -10);
	appref.setAppletParameter("script",zoomscript);
	appref.startScript();
      }
      catch (er) {}
      setTimeout("showAppletDiv('div_modelarea2');setVisible('div_imgarea','hidden');",400);
      showViewerInstructions();
      nexttime=15000;
    }
  else if (cache_obj.imgs[i] == 'applet-show1')
    {
      try {
	var appref = getObj("modelarea1");
	appref.setAppletParameter("rotateX",0);
	appref.setAppletParameter("positionZ", -10);
	appref.setAppletParameter("script",zoomscript);
	appref.startScript();
      }
      catch (er) {}

      setTimeout("showAppletDiv('div_modelarea1');setVisible('div_imgarea','hidden');",400);
      showViewerInstructions();
      nexttime=15000;
    }
      
    tmOut = setTimeout("showDemo("+(i+1)+");", nexttime);

}

function pauseapplet(name)
{
 try {
   var appref = getObj(name);
   appref.setAppletParameter("script",stopscript);
   appref.startScript();
 }
 catch (er) {}
}

var viewerwin =null;
function viewshowreel() {
  dopause();
  pauseapplet("modelarea1");
  pauseapplet("modelarea2");

  if (!(viewerwin==null))
    if (!viewerwin.closed) viewerwin.close();
  viewerwin = window.open("proexamples/showreel.html","SOMViewer","toolbar=0,width=500,height=420,status=1");
  viewerwin.focus();
}  
