/*
 * VRMLObject embed
 * http://Blink3d.blogspot.com/
 *
 * by Michał Małaj (mmalaj@gmail.com, http://www.enzo.pl/)
 *
 * v.0.1 - 01-01-2007
 *
 * Embeds a vrml world to the page, includes plugin detection
 *
 * Usage:
myVRMLObject = new VRMLObject("nistlogo.wrl", "myVRML", "650", "400", "model/wrml", "Cortona");
myVRMLObject.write();
 
"application/x-blaxxunCC3D", "BS Contact"
"application/octaga", "Octaga"
"x-world/x-fx3d", "Flux"
"model/wrml", "Cortona"
 *
 */
if (navigator.appName == "Microsoft Internet Explorer") {
  if (navigator.appVersion.indexOf('Win') != -1) {
    document.writeln('<SCRIPT LANGUAGE="VBScript">');
    document.writeln('function IEDetectObject(activeXControlName)');
    document.writeln('  On Error Resume Next');
    document.writeln('  IEDetectObject = IsObject(CreateObject(activeXControlName))');
    document.writeln('End function');
    document.writeln('</SCR' + 'IPT>');
 }
}

VRMLObject = function(vrml,id,szer,wys,typ, nazwa){
    this.vrml = vrml;
    this.type = typ;
    this.id = id;
    this.width = szer;
    this.height = wys;
    this.namePlugin = nazwa;
    this.params = new Object();
}
VRMLObject.prototype.addParam = function(name, value) {
    this.params[name] = value;
}
VRMLObject.prototype.getParams = function() {
    return this.params;
}
VRMLObject.prototype.getParam = function(name) {
    return this.params[name];
}

VRMLObject.prototype.getParamTags = function()
{
    var paramTags = "";
   
    for (var p in this.getParams())
    {
            paramTags += '<param name="' + p + '" value="' + this.getParam(p) + '" />';
    }
    if (paramTags == "")
    {
        paramTags = null;
    }
    return paramTags;
}
VRMLObject.prototype.checkForFirefox = function()
{
var k = 0;   
var npvrml = new Array(10);   
var numPlugins = navigator.plugins.length;
//alert(numPlugins);
  for (i = 0; i < numPlugins; i++) {
    var plugin = navigator.plugins[i];
    var numTypes = plugin.length;
	//alert(plugin.name);
    for (j = 0; j < numTypes; j++)
    {
      mimetype = plugin[j];
	//alert(mimetype.type); 
      if (mimetype)
      { 
	if (mimetype.type == this.type)
        {
	//alert(mimetype.enabledPlugin.name);
            npvrml[k] = mimetype.enabledPlugin.name;
            k++;
        }
      }
    }
   }

   if (k == 0)
   {
       var vrmlHTML = "";
        vrmlHTML +="You don`t have VRML Browser " + this.namePlugin + " to display flie: " + this.vrml;
    return vrmlHTML;    
    }

   if(npvrml[0].indexOf(this.namePlugin) != -1 ){
        var vrmlHTML = "";
        vrmlHTML += '<embed type="' + this.type +'" src="' + this.vrml + '" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '"';
        for (var param in this.getParams())
        {
            vrmlHTML += ' ' + param + '="' + this.getParam(param) + '"';
        }
        vrmlHTML += '></embed>';
        return vrmlHTML;
    } else {
        var vrmlHTML = "";
        vrmlHTML +="Your Firefox use VRML Browser " + npvrml[0] + " to display " + this.type + " documents instead " + this.namePlugin + " Please uninstall " + npvrml[0] + " or reinstall "+ this.namePlugin;
        return vrmlHTML;
    }
         
}

VRMLObject.prototype.checkForIE = function()
{
    var vrmlHTML = "";
    if(this.namePlugin=="BS Contact")
    {
        if (IEDetectObject('bsContact.bsContact.1'))
        {
            vrmlHTML += '<object classid="clsid:4B6E3013-6E45-11D0-9309-0020AFE05CC8" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '">';
                this.addParam("src", this.vrml);
                    if (this.getParamTags() != null)
                    {
                        vrmlHTML += this.getParamTags();
                    }
                vrmlHTML += '</object>';
      }
      else
      {
                      vrmlHTML += "You should install VRML Browser BS Contact Player";
      }
    }
    if(this.namePlugin=="Octaga")
    {
        if (IEDetectObject('OCTAGAX.OctagaXCtrl.1'))
        {
                vrmlHTML += '<object classid="clsid:660D0125-4C92-4EDD-B7B4-B36857F1449E" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '">';
                this.addParam("src", this.vrml);
                    if (this.getParamTags() != null)
                    {
                        vrmlHTML += this.getParamTags();
                    }
                vrmlHTML += '</object>';
           
        }
           
    }
    if(this.namePlugin=="Flux")
    {
        if (IEDetectObject('ANIMA.AnimaCtrl.1'))
        {
                vrmlHTML += '<object classid="clsid:918B202D-8E8F-4649-A70B-E9B178FEDC58" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '">';
                      this.addParam("src", this.vrml);
                    if (this.getParamTags() != null)
                    {
                        vrmlHTML += this.getParamTags();
                    }
                vrmlHTML += '</object>';
        }
        else
        {
            vrmlHTML += "You should install VRML Browser Flux Player";
        }
    } 
    if(this.namePlugin=="Cortona")
    {
        if (IEDetectObject('Cortona.Control.1'))
        {
              vrmlHTML += '<object classid="clsid:86A88967-7A20-11d2-8EDA-00600818EDB1" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '">';
            this.addParam("src", this.vrml);
                    if (this.getParamTags() != null)
                    {
                        vrmlHTML += this.getParamTags();
                    }
                vrmlHTML += '</object>';
        }
        else
        {
                vrmlHTML += "You should install VRML Browser Cortona Player";
        }
   
    }
return vrmlHTML;
}

VRMLObject.prototype.getHTML = function()
{
    var vrmlHTML = "";
    if (navigator.plugins && navigator.plugins.length)
    {
    vrmlHTML = this.checkForFirefox();
    }
    else
    {
    vrmlHTML = this.checkForIE();
    }
    return vrmlHTML;
}

VRMLObject.prototype.write = function(elementId)
{
        if (elementId)
        {
            document.getElementById(elementId).innerHTML = this.getHTML();
        }
        else
        {
            document.write(this.getHTML());
        }
}
   
           
