/*
** The Crusher Applet
*/
function CrusherApplet(applet_url)
{
    this.applet_url = applet_url;
    this.return_value = "";
    this.imghost = "";
    this.ahost = "";
    this.sg = "";
    this.loadType = "";
    this.finalize_func = null;
}
CrusherApplet.prototype.create = function(params)
{
    document.getElementsByTagName("body").item(0).style.cursor = "wait";
    param_string = "";
    for (var name in params) {
        var value = params[name];
        param_string += this._create_param(name, value);
        if (name == "this") {
            // this one is special/skipped
        } else if (name == "imghost") {
            this.imghost = value;
        } else if (name == "host") {
            this.ahost = value;
        } else if (name == "sg") {
            this.sg = value;
        }
    }
    param_string += this._create_param("js_callback", this._create_callback(this, params["this"]));
    param_string += this._create_param("debug", "true");
    applet_tag = '<applet name="Creative Toolbox" code="com.ag.applets.photoupload.Crusher.class" ';
    applet_tag += 'archive="' + this.applet_url + '" width="0" height="0" mayscript="true">';
    applet_tag += param_string;
    applet_tag += "</applet>";
    var div = document.createElement("div");
    document.body.appendChild(div);
    div.innerHTML = applet_tag;
}
CrusherApplet.prototype._create_callback = function(this_, eval_this) {
    var function_name = "";
    var alphabet = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
    for (var i=0; i < 15; i++) {
        function_name += alphabet.charAt(Math.floor(Math.random() * alphabet.length));
    }
    window[function_name] = function(s) {
        document.getElementsByTagName("body").item(0).style.cursor = "";
        this_.return_value = s;
        if (eval_this) {
            func = eval_this["getAppletCallback"](eval_this);
        } else {
            func = this_["getCallback"](this_);
        }
        setTimeout(func, 1500);
    }
    return function_name;
}
CrusherApplet.prototype.getCallback = function(this_)
{
    return function() {
        this_.finalize_func(this_.ahost, this_.imghost, this_.return_value, this_.sg, this_.loadType);
    }
}
CrusherApplet.prototype._create_param = function(name, value)
{
    return '<param name="' + name + '" value="' + value + '"/>';
}

/* <crusherapplet> */
