/**
 * Cult3D API Abstraction.
 * To ease the use to call the same method both for Netscape and Internet Explorer.
 */

/*
 * Original author: J-Peter, Cycore
 * Current maintainer: Jonatan Andersson, Cycore Systems
 *
 * Last edited 2006-04-25
 * version 1.2
 */



// Cult3D support file for Netscape Navigator and Internet Explorer

// AntiAliasing
var AA_AUTOMATIC = 0;   // Automatic antialiasing when using software
var AA_DISABLED  = 1;   // Disable antialiasing when using software
var AA_ENABLED   = 2;   // Enable antialiasing when using software

// Action status
var AS_NOTFOUND = -1;   // Action status not found
var AS_CLEAR    =  0;   // Action status is clear
var AS_SET      =  1;   // Action status is set

// Identify the browser, wait for a small period of time to make sure
// that Netscape is able to start the Java engine. Provide the
// same interface for both Internet Explorer and Netscape Communicator.
function Cult3D_Object(refObject)
{
	if (typeof(this.Type)!="undefined")
		return;

	if (isActiveX() && typeof(refObject)=="object" && typeof(refObject.Version)=="string")
    {
		this.Type            = "IE";
		this.Cult3D          = eval(refObject);
        this.getFrame        = IE_getFrame;
        this.setFocus        = IE_setFocus;
		this.triggerEvent    = IE_triggerEvent;
        this.triggerAction   = IE_triggerAction;
		this.getVersion      = IE_getVersion;
		this.getLastMessage  = IE_getLastMessage;
        this.getActionStatus = IE_getActionStatus;
		this.getAntiAliasing = IE_getAntiAliasing;
        this.setAntiAliasing = IE_setAntiAliasing;
		this.getStereoMode   = IE_getStereoMode;
		this.setStereoMode   = IE_setStereoMode;
		this.getDisparity    = IE_getDisparity;
		this.setDisparity    = IE_setDisparity;
        this.getAntiAliasingDelay = IE_getAntiAliasingDelay;
        this.setAntiAliasingDelay = IE_setAntiAliasingDelay;

		return;
	}
	if (!isActiveX())
    {
		if(document.getElementById)
        {
			refObject = document.getElementById(refObject);
		}
		else
        {
			refObject = findObj(refObject);
		}

		if (typeof(refObject) == "object")
        {
			this.Type            = "NS";
			this.Cult3D          = refObject;
            this.getFrame        = NS_getFrame;
            this.setFocus        = NS_setFocus;
            this.getVersion      = NS_getVersion;
			this.triggerEvent    = NS_triggerEvent;
            this.triggerAction   = NS_triggerAction;
			this.getLastMessage  = NS_getLastMessage;
            this.getActionStatus = NS_getActionStatus;
            this.getAntiAliasing = NS_getAntiAliasing;
			this.setAntiAliasing = NS_setAntiAliasing;
			this.getStereoMode   = NS_getStereoMode;
			this.setStereoMode   = NS_setStereoMode;
			this.getDisparity    = NS_getDisparity;
			this.setDisparity    = NS_setDisparity;
            this.getAntiAliasingDelay = NS_getAntiAliasingDelay;
            this.setAntiAliasingDelay = NS_setAntiAliasingDelay;

			return;
		}
	}

    this.Type            = "";
    this.Cult3D          = null;
    this.getFrame        = None_Dummy;
    this.setFocus        = None_Dummy;
    this.getVersion      = None_Dummy;
    this.triggerEvent    = None_Dummy;
    this.triggerAction   = None_Dummy;
    this.getLastMessage  = None_Dummy;
    this.getActionStatus = None_Dummy;
    this.getAntiAliasing = None_Dummy;
    this.setAntiAliasing = None_Dummy;
    this.getStereoMode   = None_Dummy;
    this.setStereoMode   = None_Dummy;
    this.getDisparity    = None_Dummy;
    this.setDisparity    = None_Dummy;
    this.getAntiAliasingDelay = None_Dummy;
    this.setAntiAliasingDelay = None_Dummy;
}

///////////////////////////
// Misc utililities
//////////////////////////

function isActiveX()
{
    if(navigator.userAgent.toLowerCase().indexOf('windows') != -1 && navigator.userAgent.toLowerCase().indexOf('msie') != -1)
    {
        return true;
    }

    return false;
}

function isIE()
{
    return isActivex();
}



//////////////////////////////////////
// Private help functions.
// Not to be used outside this file
/////////////////////////////////////


////////////////////////////////
// Netscape support functions
///////////////////////////////
function NS_getVersion()
{
    return this.Cult3D.getVersion();
}

function NS_triggerEvent(name)
{
    return this.Cult3D.triggerEvent(name);
}

function NS_getLastMessage()
{
    return this.Cult3D.getLastMessage();
}

function NS_setAntiAliasing(aa_mode)
{
    this.Cult3D.setAntiAliasing(aa_mode);
}

function NS_getAntiAliasing()
{
    return this.Cult3D.getAntiAliasing();
}


function NS_setAntiAliasingDelay(aa_delay)
{
    this.Cult3D.setAntiAliasingDelay(aa_delay);
}

function NS_getAntiAliasingDelay()
{
    return this.Cult3D.getAntiAliasingDelay();
}

function NS_getFrame()
{
    return this.Cult3D.getFrame();
}

function NS_setFocus()
{
    this.Cult3D.setFocus();
}

function NS_getActionStatus(name)
{
    return this.Cult3D.getActionStatus(name);
}

function NS_triggerAction(name,action)
{
    return this.Cult3D.triggerAction(name,action);
}

// Supported from version 5.2.x.x and later 5.x serie
function NS_setStereoMode(mode)
{
    this.Cult3D.setStereroMode(mode);
}

function NS_getStereoMode()
{
    return this.Cult3D.getStereoMode();
}

function NS_setDisparity(disparity)
{
    this.Cult3D.setDisparity(disparity);
}

function NS_getDisparity()
{
    return this.Cult3D.getDisparity();
}



/////////////////////////////////////////
// Internet Explorer support functions
/////////////////////////////////////////

function IE_getVersion()
{
    return this.Cult3D.Version;
}

function IE_triggerEvent(name)
{
    return this.Cult3D.TriggerEvent(name);
}

function IE_getLastMessage()
{
    return this.Cult3D.LastMessage;
}

function IE_setAntiAliasing(aa_mode)
{
    this.Cult3D.AntiAliasing=aa_mode;
}

function IE_getAntiAliasing()
{
    return this.Cult3D.AntiAliasing;
}


function IE_setAntiAliasingDelay(aa_delay)
{
    this.Cult3D.AntiAliasingDelay=aa_delay;
}

function IE_getAntiAliasingDelay()
{
    return this.Cult3D.AntiAliasingDelay;
}

function IE_getFrame()
{
    return this.Cult3D.Frame;
}

function IE_setFocus()
{
    this.Cult3D.focus();
}

function IE_getActionStatus(name)
{
    return this.Cult3D.GetActionStatus(name);
}

function IE_triggerAction(name,action)
{
    return this.Cult3D.TriggerAction(name,action);
}

// Supported from version 5.2.x.x and later 5.x serie
function IE_setStereoMode(mode)
{
    this.Cult3D.StereroMode=mode;
}

function IE_getStereoMode()
{
    return this.Cult3D.StereoMode;
}

function IE_setDisparity(disparity)
{
    this.Cult3D.Disparity=disparity;
}

function IE_getDisparity()
{
    return this.Cult3D.Disparity;
}

function hasObj(name, doc)
{
    if (typeof(doc.document.embeds[name])=="object")
    {
        return true;
    }

    return false;
}

function findObj(name, doc)
{
    if (!doc)
    {
        doc = window;
    }

    var o = hasObj(name, doc);
    if (o)
    {
        return doc.document.embeds[name];
    }
    else
    {
        for(i=0;i<doc.document.layers.length;i++)
        {
            obj = findObj(name, doc.document.layers[i]);
            if (typeof(obj) == "object")
            {
                return obj;
            }
        }
    }
}

// Dummy function to bind unused object properties
function None_Dummy()
{
}