//
//
// Copyright 2000-2001 SolidWorks Corporation.  All rights reserved.
//
// No part of these files may be reproduced or used outside of the 3D Instant Website product
// for any purpose, without the express written permission of SolidWorks Corporation.
//
//
//

var node;		// detect which node has been clicked
var curModelId = "";
var curTemplate = "";

var isIE4 = navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion.substring(0,1)) >= 4;


function mtspluginfunction() 
{
	var count = mtspluginfunction.arguments.length;

	if(count == 0)			return false;
	var argstr = mtspluginfunction.arguments[0] + '(';
	var last = count-1;
	
	for(i = 1; i < count; i++)
	{
		argstr+= mtspluginfunction.arguments[i];
		if(i < last)	argstr+= ',';
	}
	argstr+= ')';
	
	if (isIE4)	return document.all.MetaStreamCtl.PluginCommand(argstr, 0, 0);
	else		return document.MetaStreamCtl.DoCommand(argstr);
}

//____________________________________________________
//This function is used for MultiModel websites.
//____________________________________________________
function mtspluginfunction2() 
{

	var count = mtspluginfunction2.arguments.length;

	if(count == 0)			return false;
	var argstr = mtspluginfunction2.arguments[0] + '(';
	var last = count-1;
	
	for(i = 1; i < count; i++)
	{
		argstr+= mtspluginfunction2.arguments[i];
		if(i < last)	argstr+= ',';
	}
	argstr+= ')';

   var ObjectNode = "MetaStreamCtl" + curModelId

	if (isIE4 && document.all[ObjectNode]){
   	return document.all[ObjectNode].PluginCommand(argstr, 0, 0);
   }
	else
   {	
     if(typeof document[ObjectNode] != "undefined")
     	return document[ObjectNode].DoCommand(argstr);
     else if(typeof document.embeds[ObjectNode] != "undefined")
       	return document.embeds[ObjectNode].DoCommand(argstr);  
   }
}

function triggeranimation()	{

   if(arguments[0]!= "undefined" && typeof(arguments[0])!= "undefined"){ 
      if(arguments[1] != "undefined" && arguments[1] != null && typeof(arguments[1])!= "undefined"){
         curModelId = arguments[1]; //This is the ModelId

           if(arguments[0].match(/ExplodeSteps/g) != null)  //For persisting explode/unexplode
           {
               if(arguments[2] != "undefined" && arguments[2] != null && typeof(arguments[2])!= "undefined")
               {
                  curTemplate = arguments[2]; // This is the Template Name
                  if(curTemplate.toLowerCase() == "treepage"){
                    if(typeof parent.stateArr != "undefined" && parent.stateArr[arguments[1]] != null)
                       parent.stateArr[arguments[1]][0] = arguments[0];
                  }
                  else{ // for all other templates.
                    if(parent.stateArr)
                      parent.stateArr[arguments[1]] =  arguments[0];
                  }
               } // If Tree Template is passed
           }
           mtspluginfunction2("TriggerAnimation", arguments[0]);
      }
      else
         mtspluginfunction ("TriggerAnimation", arguments[0]);
   }
}

//__________________________________________
//This function is used for Tree template.
//__________________________________________
function restoreExplode()
{
  if(arguments[0]!= "undefined" && typeof(arguments[0])!= "undefined"){ 
      if(arguments[1] != "undefined" && arguments[1] != null && typeof(arguments[1])!= "undefined"){
         curModelId = arguments[1];
         if(arguments[0] == 'ExplodeSteps')    // For persisting explode/unexplode
         {
           if(parent.stateArr)
              parent.stateArr[arguments[1]][0] = arguments[0];
           else if(opener.stateArr)//For FullScaleView
                  opener.stateArr[arguments[1]][0] = arguments[0];
         }
         //For explode on startUp using Custom Event firing.
         var cmdstr = "PostEvent (ShowExplode,0)";//'ShowExplode' is the Tag Name in MTX file. '0' is the timedelay for event firing.
         mtspluginfunction2(cmdstr);  
      }
      else
         mtspluginfunction ("TriggerAnimation", arguments[0]);
   }
}

//______________________________________________________
//This function is used for non-Tree template.
//______________________________________________________
function restoreExplode2()
{
  if(arguments[0]!= "undefined" && typeof(arguments[0])!= "undefined"){ 
      if(arguments[1] != "undefined" && arguments[1] != null && typeof(arguments[1])!= "undefined"){
         curModelId = arguments[1];
         if(arguments[0] == 'ExplodeSteps')    // For persisting explode/unexplode
         {
           if(parent.stateArr)
              parent.stateArr[arguments[1]] = arguments[0];
           else if(opener.stateArr)//For FullScaleView
                  opener.stateArr[arguments[1]] = arguments[0];
         }
         // For explode on startUp using Custom Event firing.
         var cmdstr = "PostEvent (ShowExplode,0)";//'ShowExplode' is the Tag Name in MTX file. '0' is the timedelay for event firing.
         mtspluginfunction2(cmdstr);
      }
      else
         mtspluginfunction ("TriggerAnimation", arguments[0]);
   }
}

function persistExplode(item,mode)
{
  if(mode == "SP")
    return;
  if(!parent.stateArr)
    return;
  if(!parent.stateArr[item])
   return;

  if(parent.stateArr[item] == "ExplodeSteps" )
      restoreExplode2(parent.stateArr[item],item);
}

function getproperty(object, prop, type) { 
    if(arguments[3] != "undefined" && arguments[3] != null && typeof(arguments[3])!= "undefined"){
         curModelId = arguments[3];
         return mtspluginfunction2("GetProperty ", object, prop, type);
      }
    else
         return mtspluginfunction("GetProperty ", object, prop, type);    			
}

function togglecollapsed()	{
  if(arguments[1] != "undefined" && arguments[1] != null && typeof(arguments[1])!= "undefined"){
     curModelId = arguments[1];
     mtspluginfunction2("ToggleCollapsed", arguments[0]);
  }
  else    
     mtspluginfunction("ToggleCollapsed", arguments[0]);
}

function setproperty(object, prop, value, type)
{
   if(arguments[4]!= "undefined" && typeof(arguments[4])!= "undefined")
   { 
         curModelId = arguments[4]; //This is the ModelId        
         return  mtspluginfunction2("SetProperty ",object, prop, value, type);
   }
   else
      return mtspluginfunction ("SetProperty ", object, prop, value, type);
}

function render()
{
   if(arguments[0]!= "undefined" && typeof(arguments[0])!= "undefined")
   { 
         curModelId = arguments[0]; //This is the ModelId        
         mtspluginfunction2("Render");
   }
   else
    mtspluginfunction ("Render");
}

function togglevisible()	{
  if(arguments[1] != "undefined" && arguments[1] != null && typeof(arguments[1])!= "undefined"){
     curModelId = arguments[1];
     mtspluginfunction2("ToggleVisible", arguments[0]);
  }
  else    
     mtspluginfunction("ToggleVisible", arguments[0]);
}

function reverseanimation ()	{mtspluginfunction ("ReverseAnimation ", arguments[0]);}
function stopanimation ()	{mtspluginfunction ("StopAnimation ", arguments[0]);}
function startanimation ()	{mtspluginfunction ("StartAnimation ", arguments[0]);}
function resetanimation ()	{mtspluginfunction ("ResetAnimation ", arguments[0]);}
function togglepano()		{mtspluginfunction ("TogglePano", arguments[0]);}
function resetcamera()		{mtspluginfunction ("ResetCamera", arguments[0]);}
function removeobject()		{mtspluginfunction ("RemoveObject", arguments[0]);}
function clearscene()		{mtspluginfunction ("ClearScene", arguments[0]);}
function loadmtx()		{mtspluginfunction ("LoadMTX", arguments[0]);}
