/*

Teppefall Hybrid Teknologi 1.3
Kopirettigheter (c) 2010 Jan Erik Paulsen (Teppefall, http://teppefall.com)

Engelsk:
Based on jQuery 1.2.6 and keyboard_shortcuts.

URL syntax is like this:

installer
installer#action=start -> launches ${hybrid.loader}
installer#action=stop
installer#console      -> launches console.jxml
installer#effects      -> launches effects.jxml

Shortcuts:
    - Escape - Show navigation.
    - Enter  - Hide navigation.
    - F12    - Open assembly.

This is not really a framework. I just wrote it for the Teppefall website.
I use animation based callbacks to trigger the various DOM updates.

Debugging bookmarklets (verbose mode and stacktraces):
javascript:hybrid.debug=true;hybrid.changeAssembly("mediaplayer");return;
javascript:hybrid.debug=true;hybrid.changeAssembly("effects3d");return;
javascript:hybrid.joglMode();return

Fixes(dmy):
14.07.2010 - Loader. DownloadServiceListener class in attribute progress-class. JAR element with download="progress".
11.03.2010 - Stylesheet fix.
15.11.2009 - Widget mode with plugin1 absolute URL's.
20.08.2009 - Fixed the 1.6r15 certificate problem. Fingers crossed. Upgraded to Plugin2 logic.

*/
jQuery.noConflict(); // prototype and jquery both implement $('')

/*
Extension logic. This is a nightmare. Sun's own documentation and example code is comical.
The JNLP based Plugin2 launcher is much simpler. Just read the two JNLP files.
*/

var installJOGL = false
var installJMC = false
var server = "http://s24691.gridserver.com/ext/"
var jnlpLogic = "/assembly/20100714/hybrid.jnlp"

var EXT = ","+
    "http://download.java.net/media/applet-launcher/applet-launcher.jar,"+
    "http://download.java.net/media/jogl/builds/archive/jsr-231-webstart-current/jogl.jar,"+
    "http://download.java.net/media/gluegen/webstart/gluegen-rt.jar";

var EXT = ","+
"http://dl.javafx.com/applet-launcher__V1.1.0.jar,"+
"http://dl.javafx.com/jmc__V1.1.0.jar,"+
"http://dl.javafx.com/Decora-SSE__V1.1.0.jar,"+
"http://dl.javafx.com/jogl__V1.1.1a.jar,"+
"http://dl.javafx.com/gluegen-rt__V1.0b06a.jar"
//"http://dl.javafx.com/javafx-rt__V1.1.0.jar,"+
//"http://dl.javafx.com/fxdloader__V1.1.0.jar,"+
//"http://download.java.net/media/jogl/builds/archive/jsr-231-webstart-current/jogl.jar,"+
//"http://download.java.net/media/gluegen/webstart/gluegen-rt.jar"


/*EXT = ","+
    "http://download.java.net/media/applet-launcher/applet-launcher.jar,"+
    "http://dl.javafx.com/jmc__V1.1.0.jar,"+
    "http://dl.javafx.com/jogl__V1.1.1a.jar,"+
    "http://dl.javafx.com/gluegen-rt__V1.0b06a.jar";*/

/*EXT = ","+
    server + "applet-launcher.jar,"+
    server + "jogl.jar,"+
    server + "gluegen-rt.jar";*/

//EXT = ""
//jmc-natives-macosx__V1.0.0.jar
//Decora-SSE-natives-macosx__V1.0.0.jar
//Decora-SSE-natives-macosx__V1.0.0.jar
if(navigator.platform.indexOf("Mac") != -1) {
    // The Java Web Start JOGL extension nukes pretty much all browsers on the Mac platform.
    // And then I tried JMC and nuke-tastic was suddenly happyness and fluffy bunnies.
    /*EXT += ",http://dl.javafx.com/jmc__V1.1.0.jar,"+
    "http://dl.javafx.com/Decora-SSE__V1.0.1.jar,"+
    "http://dl.javafx.com/Decora-HW__V1.0.1.jar,"+
    "http://dl.javafx.com/Decora-OGL__V1.0.1.jar"*/
    installJOGL = true
    installJMC = true;
}
else if(navigator.platform.indexOf("Win") != -1){
    /*EXT += ",http://dl.javafx.com/jmc__V1.1.0.jar,"+
    "http://dl.javafx.com/Decora-SSE__V1.0.1.jar,"+
    "http://dl.javafx.com/Decora-HW__V1.0.1.jar,"+
    "http://dl.javafx.com/Decora-D3D__V1.0.1.jar"*/

    /*EXT += ",/beta2/ext/jmc.jar,"+
    "/beta2/ext/Decora-SSE.jar,"+
    "/beta2/ext/Decora-HW.jar,"+
    "/beta2/ext/Decora-D3D.jar"

    EXT += ","+server+"jmc.jar,"+
    server + "Decora-SSE.jar,"+
    server + "Decora-HW.jar,"+
    server + "Decora-D3D.jar"*/

    installJOGL = true;
    installJMC = true;
}
else {
    EXT = ""
}

//alert(EXT)

/*
Loader logic.
*/

var hybrid = window.hybrid = {
    container : "com.teppefall.hybrid.browser.JJHPlugin",
    containerBackup : "com.teppefall.hybrid.browser.JJHPlugin",
    loader : "console.jxml",
    extras : "",
	version : "20100714",
    jars: "/assembly/"+this.version+"/hybrid.jar,/assembly/miglayout-swing.jar" + EXT,
    look : "",
    basepath : "/assembly/",
    idCopy : "",
    changeLogo : false,
    javaAlreadyStarted : false, // applet already running
    offset : 310,
    fadeTime : 500,
    appletLoaderRunning : false,
    debug : false,
    delayed : false,
    automatedFocus : true,
    weAreInFocus : true,
    animated : true,
    globalAssembly : "",
    currentAssembly : this.loader,
    assemblyVersion : "", // does not work - console.xml?1.0
    start : -1,
    inExtremeMode : false,
    syncLAF : false,
    blueLAF : false,
    legacyDispatchThread : false,
    absoluteUrl : false,
    adjustViewport : function(e) {
        if(document.getElementById("copyright") == null) return
        var copyrightHeight = document.getElementById("copyright").offsetHeight
        var logoHeight = document.getElementById("logoBg").offsetHeight
        var navigationHeight = 20
        try {
        navigationHeight = document.getElementById("thicktabs").offsetHeight
        }
        catch(e) {
        }
        //alert(copyrightHeight +" - "+ navigationHeight)
        this.offset = copyrightHeight + logoHeight + navigationHeight + 148
        if(document.getElementById("launcherApp")   /*typeof window.innerWidth != 'undefined'*/) {
            var soLame = "launcherApp"
            //if(navigator.userAgent.indexOf('Opera') != -1) soLame = "launcherApp1"
            //if(navigator.userAgent.indexOf('Safari') != -1) soLame = "launcherApp1"
            //soLame = "launcherApp"
            if(window.innerHeight)
            document.getElementById(soLame).style.height = window.innerHeight - this.offset + "px"
            else
            document.getElementById(soLame).style.height = document.documentElement.clientHeight - this.offset + "px"
            //document.getElementById(soLame).style.background = "gray"
        }
        else {
            //if(document.getElementById("launcherApp1"))
            //document.getElementById("launcherApp1").style.height = document.documentElement.clientHeight  - offset + "px"
            //document.getElementById("launcherApp1").style.background = "gray"
        }
    },
    // this might be wrong because of location.href calls ? confused
    // race condition in chrome? works fine in safari
    setTitle : function(title) {
        if(title == null || title == "") document.title = "Teppefall"
        else document.title = title + " - Teppefall"
    },
    //javascript:hybrid.changeAssembly("pad")
    changeAssembly : function(component) {
        this.currentAssembly = component
        this.setTitle(component + ".jxml")
        this.globalAssembly = this.basepath + component + ".jxml"//+"?v=" + this.assemblyVersion
        this.urlSync(component)
        this.checkJogl(component)
        this.createComponent("hybrid", "launcherApp", "hybrid")
    },
    startAnimation : function(component) {
        if(component != null) this.setTitle(component)
        else this.setTitle("")
        this.start = (new Date).getTime();
        this.globalAssembly = this.basepath + component //+ "?v=" + this.assemblyVersion // Broken
        this.urlSync("action=start")
        this.checkJogl(component)

        jQuery("#copyright").hide();
        jQuery("#thicktabs").slideUp(function() {
            hybrid.adjustViewport()
            jQuery("launcherApp").css("cursor","default");
            jQuery("div.navTest h1").fadeOut(this.fadeTime, function() {
                jQuery("div.navTest h1").html("<a title=Navigation-ON href=#action=stop onclick=window.hybrid.stopAnimation()>Click or press Escape to access navigation</a>")
                jQuery("div.navTest h1").fadeIn(this.fadeTime);
            });
            jQuery("#groupFixedViewportHidden").animate({
                marginRight: "300px"
                }, 0,function() {
                    jQuery("#groupFixedRightHidden").fadeIn(this.fadeTime);
                    jQuery("#removeMe").fadeOut(this.fadeTime, function() {
                        if(!this.appletLoaderRunning) {
                                hybrid.appletLoaderRunning = true
                                if(hybrid.debug)
                                jQuery("#launcherApp").css("background","green");
                                if(!hybrid.javaAlreadyStarted) {
                                    if(hybrid.debug)
                                    jQuery("#launcherApp").css("border","4px solid magenta");
                                    document.getElementById("launcherApp").removeAttribute("onclick");
                                    jQuery("#launcherApp").css("cursor","default");
                                    hybrid.createComponent("hybrid", "launcherApp", "removeMe")
                                }
                                hybrid.javaAlreadyStarted = true;
                        }
                    });
                    if(hybrid.changeLogo)
                    jQuery("#topp").attr("src","/media/topp07.png");
                }
            );
            if(component) {
                //alert(component)
            }
        });
        jQuery("#newfeature").fadeOut(this.fadeTime);
        jQuery("#store").fadeOut(this.fadeTime);
        jQuery("#idcode").fadeOut(this.fadeTime);
    },
    stopAnimation : function() {
        this.urlSync("action=stop")
        jQuery("#copyright").show();
        jQuery("#thicktabs").slideDown(function() {
            hybrid.adjustViewport()
            jQuery("launcherApp").css("cursor","default");
            jQuery("div.navTest h1").fadeOut(this.fadeTime, function() {
                jQuery("div.navTest h1").html("<a title=Navigation-OFF href=#action=start onclick=window.hybrid.startAnimation()>Click or press Enter to hide navigation</a>")
                jQuery("div.navTest h1").fadeIn(this.fadeTime);
            });
            jQuery("#groupFixedViewportHidden").animate({
                marginRight: "0px"
                }, 0
            );
            jQuery("#groupFixedRightHidden").fadeOut(this.fadeTime, function() {
                if(hybrid.appletLoaderRunning) {
                    hybrid.appletLoaderRunning = false
                    if(hybrid.debug)
                    jQuery("#launcherApp").css("background","red");
                }
                if(hybrid.changeLogo)
                jQuery("#topp").attr("src","/media/topp05.png");
            })
        });
        jQuery("#newfeature").fadeIn(this.fadeTime);
        jQuery("#store").fadeIn(this.fadeTime);
        jQuery("#idcode").fadeIn(this.fadeTime);
    },
    urlSync : function(current) {
        if(location.hash.length != 0 && location.hash.indexOf("=") == -1) return // Not an action
        if(location.hash != current) {
            location.href = "#" + current
            //this.setTitle(current + ".jxml") //race condition in chrome? does not work
        }
    },
    createComponent : function(objectID, parentID, placeholderID, offscreen) {
        this.idCopy = objectID
        var attributes = {
            image   : "loader.gif",
            code    : this.container,
            archive : this.jars,
            lookandfeel: this.look,
            id      : objectID,
            width   : "100%",
            height  : "100%",
            type    : "application/x-java-applet", //application/x-java-applet;version=1.6
            pluginspage: "http://java.sun.com/javase/downloads/ea.jsp",
            boxmessage : "JJHPlugin - " + this.globalAssembly,
            boxborder  : "false",
            jnlpNumExtensions : "4",
            //jnlpExtension1 : "http://download.java.net/media/jogl/builds/archive/jsr-231-webstart-current/jogl.jnlp",
            jnlpExtension1 : "http://dl.javafx.com/jmc__V1.1.0.jnlp",
            jnlpExtension2 : "http://dl.javafx.com/Decora__V1.1.0.jnlp",
            jnlpExtension3 : "http://dl.javafx.com/jogl__V1.1.1a.jnlp",
            jnlpExtension4 : "http://dl.javafx.com/gluegen-rt__V1.0b06a.jnlp",
            //jnlpExtension2 : "http://dl.javafx.com/jmc__V1.1.0.jnlp",
            //jnlpExtension2 : "http://dl.javafx.com/1.1/javafx-rt.jnlp",
            //jnlpExtension1 : "http://dl.javafx.com/jogl__V1.1.1a.jnlp",
            //jnlpExtension2 : "http://dl.javafx.com/gluegen-rt__V1.0b06a.jnlp",
            //jnlpExtension5 : "http://dl.javafx.com/Decora__V1.1.0.jnlp",
            subappletXXXclassname : this.containerBackup, //"com.teppefall.hybrid.browser.EmbeddedApplet",
            //noddrawXXXcheck : "true",
            //boxbgcolor : "#000000",
            //background : "#000000",
            //boxfgcolor : "#000000",
            //classloader_cache : "false",
            //codebase_lookup : "true",
            //centerimage: "true",
            boxborder  : "false",
            boxbgcolor : (this.inExtremeMode)?"#111111":"#eeeeee",
            boxfgcolor : (this.inExtremeMode)?"#cccccc":"#000000",
            draggable  : "true",
            mayscript  : "true",
            scriptable : "true",
            dka        : "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
            dkb        : "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
            jnlp_href  : jnlpLogic, //"installer.jnlp"
            //jnlp_href : "/install/" + this.globalAssembly + ".jnlp",
            assembly   : this.globalAssembly, // teit "/beta2/pownce.xml"
            verbose    : this.debug, // turns on debug info
            delayed    : this.delayed // two second delay
        };

        var parameters = {
            id      : objectID,
            width   : "100%",
            height  : "100%",
            classid : "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
        };

        var jnlpCount = 3
        if(!installJOGL) {
            jnlpCount--
            attributes.jnlpExtension1 = ""
            attributes.subappletXXXclassname = ""
        }

//http://app.teppefall.com/t.flv
        /*if(!installJMC) {
            jnlpCount-=2
            attributes.jnlpExtension2 = ""
            attributes.jnlpExtension3 = ""
        }*/
        //attributes.jnlpNumExtensions = jnlpCount


        /* This is technically correct, but still breaks IE.
           Simply write this tree to a static file and it will work fine. Java Plugin bug ?

           I guess I have to try the applet tag.
         */
        /*
        var objectElement = document.createElement("object");
        for (var attribute in parameters) {
            objectElement.setAttribute(attribute, parameters[attribute]);
        }
        for (var parameter in attributes) {
            if(parameter == "id" || parameter == "width" || parameter == "height") continue
            if(attributes[parameter] == "") continue
            var param = document.createElement("param");
            param.setAttribute("value", attributes[parameter]);
            param.setAttribute("name",  parameter);
            if(parameter == "subappletXXXclassname") {
                param.setAttribute("name",  "subapplet.classname");
                //alert("yay" + attributes[parameter])
            }
            objectElement.appendChild(param);
        }
        */

        document.getElementById(parentID).removeChild(document.getElementById(placeholderID));

        if(!jQuery.browser.msie) {
            var embedElement = this.createElement("embed", attributes, null)
            document.getElementById(parentID).appendChild(embedElement);
        }
        else {
            var embedElement = this.createElement("applet", attributes, parameters)
            document.getElementById(parentID).appendChild(embedElement);
            //document.getElementById(parentID).appendChild(objectElement);
        }
        if(this.automatedFocus) {
            document.getElementById(parentID).onmouseover = function() {
                if(hybrid.debug)
                jQuery("body").css("border","4px solid red");
                if(hybrid.automatedFocus && hybrid.weAreInFocus) {
                    document.getElementById("hybrid").focus() // ??
                }
            }
            document.getElementById(parentID).onmouseout = function() {
                if(hybrid.debug)
                jQuery("body").css("border","4px solid blue");
                if(hybrid.automatedFocus && hybrid.weAreInFocus) {
                    window.focus() // angst
                }
            }
        }
        // Check success
        var diff
        if(this.start != -1) diff = (new Date).getTime() - this.start;
        else diff = -1;
        //alert(diff)
        //alert(typeof test.getAppletInfo)

        if(!this.javaAlreadyStarted) {
            setTimeout(function () {
                var test = document.getElementById("hybrid")
                if(typeof test.getAppletInfo == "undefined" /*|| test.getAppletInfo() != "EmbeddedApplet"*/) {
                    jQuery("#newfeature").css("top", "60px")
                    jQuery("#newfeature").show()
                    jQuery("#newfeature").html("<h1 class=notify>LiveConnect offline or slow ?</h1>")
                }
                else {
                    if(hybrid.debug) {
                        jQuery("#newfeature").css("top", "60px")
                        jQuery("#newfeature").show()
                        jQuery("#newfeature").html("<h1 class=notify>LiveConnect works</h1>")
                    }
                }
            }, 10000);
        }
        else {
            //alert("post applet")
        }

    },
    createElement : function(elementName, attributes, parameters, parameterName) {
        if(elementName == "applet") {
            parameters.classid = ""
            var copyA = attributes
            var copyB = parameters
            attributes = copyB
            parameters = copyA
        }

        if(!parameterName) parameterName = "param";
        var element = document.createElement(elementName);
        for (var attribute in attributes) {
            if(attributes[attribute] == "") continue
            if(attribute == "subappletXXXclassname") {
                element.setAttribute("subapplet.classname", attributes[attribute]);
                //alert("dd")
            }
            else {
                element.setAttribute(attribute, attributes[attribute]);
            }
        }
        for (var parameter in parameters) {
            if(parameters[parameter] == "") continue
            var param = document.createElement(parameterName);
            if(parameter == "subappletXXXclassname") {
                param.setAttribute("name", "subapplet.classname");
            }
            else {
                param.setAttribute("name",  parameter);
            }
            param.setAttribute("value", parameters[parameter]);
            element.appendChild(param);
        }

        /*if(elementName == "applet") {
            element.setAttribute("id", this.idCopy);
            element.setAttribute("width", "100%");
            element.setAttribute("height", "100%");
            element.setAttribute("width", "100%");
        }*/


        return element;
    },
    hybridComponent : function(secondaryMode) {
        if(!secondaryMode) {
            setActiveStyleSheet('Wide')
            wideMode = true
        }
        var assembly = hybrid.loader //"loader.jxml"

        // TODO
        ///landing?next=effects3d - Click to laucnh Effects3D
        // http://app.teppefall.com/landing?next=effects3d#editor

        //this.currentAssembly = "loader"
        if(location.hash.length != 0) {
            var smartUrl = location.hash.substring(1)
            if(smartUrl.indexOf("=") != -1) {
                // action=?
                var values = smartUrl.split("=")
                if(this.debug)
                alert(values)
                if(values[0] == "action" && values[1] == "start") {
                    jQuery(window).load(function () {
                        hybrid.startAnimation(assembly)
                    });
                }
            }
            else {
                // view
                assembly = smartUrl + ".jxml"
                this.currentAssembly = smartUrl
                if(this.debug)
                alert(assembly)
                jQuery(window).load(function () {
                    hybrid.startAnimation(assembly)
                });
            }
        }
        else {
            //if(this.debug)
            //alert("default settings")
        }
        var info = "<br/><h3><span>Click or press Enter to continue</span></h3>"
        if(jQuery.browser.msie)
        info += "You might get a better experience with a different browser. Also, this can crash IE. Really. 1,2MB."
        else if(jQuery.browser.safari || jQuery.browser.mozilla || jQuery.browser.opera)
        info += "This code (1,2MB) can crash your browser. Save your links. Really."
        else
        info += "Your browser has not been tested. It might crash. 1,2MB."
        if(location.hash.length != 0) info = ""

        document.write("<div id=\"launcherApp\" onclick=\"hybrid.startAnimation('"+assembly+"')\"><div id=\"removeMe\"><img id=\"logo\" width=\"260\" height=\"200\" alt=\"Hybrid\" src=\"/Teppefall-HybridLogo.png\"/>"+info+"</div></div>")
        shortcut.add("Enter", function() {
            hybrid.startAnimation(assembly) // Bug, assembly value
        });
        shortcut.add("Escape", function() {
            hybrid.stopAnimation()
        });
        shortcut.add("F12", function() {
            var run = prompt("Change assembly. JXML suffix is not required.", "")
            if(run)
            hybrid.changeAssembly(run)
            //alert("open")
        });
        // Video mode ?
        if(hybrid.debug) {
            this.debugLook()
        }
    },
    saveState : function() {
        var current = this.inExtremeMode + "," + this.syncLAF + "," + this.delayed + "," + this.debug
        //alert(cookie +"\n\n" + current)
        createCookie("state", current, 365)

    },
    classpath : function(jars) {
        var cp = ""
        for(var i=0;i<jars.length;i++) {
            cp += jars[i] + ","
        }
        if(this.inExtremeMode) {
            cp += "test.jar"
        }
        else {
            cp = cp.substring(0, cp.length - 1)
        }
        return cp
    },
    cacheImage : function(path) {
        var image = new Image()
        image.src = path
    },
    debugLook : function() {
        document.getElementById("logoBg").style.background  = "#1e1e1e";
        document.getElementById("thicktabs").style.background  = "#1e1e1e";
        jQuery(".air").css("background","#000000");
        jQuery(".navTest").css("background","#222222");
        jQuery(".main").css("background","#111111");
        jQuery(".main").css("color","#cccccc");
    },
    createWidget : function(info, assembly) { //component, width, height, runNow, screenshot randomID + nextNumber
        //this.debug = true
        if(!assembly) {
            this.globalAssembly = "/hybrid_widget/effects3d.jxml" // bug in url logic
            this.globalAssembly = "/assembly/effects3d.jxml" // bug in url logic
            this.globalAssembly = "/assembly/editor.jxml" // bug in url logic
        }
        else {
            this.globalAssembly = assembly
        }
        //this.checkJogl()
        if(this.globalAssembly.indexOf("3d") != -1) { // stupid
            this.container = "org.jdesktop.applet.util.JNLPAppletLauncher"
            this.extras = EXT
        }
        shortcut.add("Enter", function() {
            hybrid.launchWidget()
        });
        document.write("<div id=\"launcherApp\" onclick=\"hybrid.launchWidget()\"><div id=\"removeMe\" class=\"widget\"><img id=\"logo\" width=\"260\" height=\"200\" alt=\"Hybrid\" src=\"http://app.teppefall.com/Teppefall-HybridLogo.png\"/>"+info+"</div></div>")
    },
    launchWidget : function() {
        //this.urlSync("action=start")
        //this.checkJogl(component)
        //hybrid.inExtremeMode = true
        //jnlpLogic = "/installerBlack.jnlp"
        jnlpLogic = "/assembly/"+this.version+"/hybrid-dark.jnlp"
        if(hybrid.absoluteUrl)
        jnlpLogic = "http://app.teppefall.com/" + this.jnlpLogic
        hybrid.appletLoaderRunning = true
        hybrid.javaAlreadyStarted = true;
        //hybrid.look = "org.jvnet.substance.skin.SubstanceRavenGraphiteLookAndFeel"
        hybrid.jars = "/assembly/"+this.version+"/hybrid.jar,/assembly/miglayout-swing.jar,"+/*server+"substance.jar" +*/ EXT
        if(hybrid.absoluteUrl)
        hybrid.jars = "http://app.teppefall.com/assembly/"+this.version+"/hybrid.jar,http://app.teppefall.com/assembly/miglayout-swing.jar,"+/*server+"substance.jar" +*/ EXT
        document.getElementById("launcherApp").removeAttribute("onclick");
        jQuery("#launcherApp").css("cursor","default");
        //jQuery("#launcherApp").css("background","#000000");
        hybrid.createComponent("hybrid", "launcherApp", "removeMe")
    },
    setLookAndFeel : function(laf) {
        setActiveStyleSheet(laf)
    },
    extremeMode : function() {
        if(this.inExtremeMode) {
            if(!this.syncLAF)
            setActiveStyleSheet('Wide')
            this.inExtremeMode = false
        }
        else {
            var ok = confirm("This is highly experimental. Continue ?")
            if(!ok) {
                document.getElementById("idextrememode1").checked = false
                return
            }
            if(!this.syncLAF)
            setActiveStyleSheet('Dark')
            jnlpLogic = "/assembly/"+this.version+"/hybrid-dark.jnlp"
            this.inExtremeMode = true
            this.jars = "/assembly/"+this.version+"/hybrid.jar,/assembly/miglayout-swing.jar,"+server+"substance.jar" + EXT

            // deadlocks
            //if(this.legacyDispatchThread)
            //this.container = "com.teppefall.hybrid.browser.LAFPlugin"
            //else
            this.container = "com.teppefall.hybrid.browser.JJHPluginLAFDT"
            this.containerBackup = "com.teppefall.hybrid.browser.JJHPluginLAFDT"
            // causes visual problems
            //if(/*!this.syncLAF &&*/ !this.blueLAF)
            this.look = "org.jvnet.substance.skin.SubstanceRavenGraphiteLookAndFeel" //SubstanceRavenGraphiteGlassLookAndFeel
            //else
            //this.look = "com.teppefall.titanium.BlueLAF"
            //this.look = "org.jvnet.substance.skin.SubstanceRavenGraphiteLookAndFeel"
            //hybrid.changeAssembly(this.currentAssembly);
            hybrid.createComponent("hybrid", "launcherApp", "hybrid")

        }
        this.saveState();
    },
    checkJogl : function(component) {
        if(typeof component == 'undefined') return

        if(/*true ||*/ installJOGL && component.indexOf("3d") != -1) { // TODO angst, dette er helt feil
            this.container = "org.jdesktop.applet.util.JNLPAppletLauncher"
            //if(this.jars.indexOf("jogl.jar") == -1)
            //this.jars = this.jar + EXT
            this.extras = EXT
        }
        else if(installJOGL && component.indexOf("mediaplayer") != -1) {
            this.container = "org.jdesktop.applet.util.JNLPAppletLauncher"
            this.extras = EXT
        }
        else if(installJOGL && component.indexOf("audioplayer") != -1) {
            this.container = "org.jdesktop.applet.util.JNLPAppletLauncher"
            this.extras = EXT
        }
        else {
            this.container = this.containerBackup
            this.extras = ""
        }
    },
    joglMode : function() {
        this.container = "org.jdesktop.applet.util.JNLPAppletLauncher"
        this.extras = EXT
        hybrid.createComponent("hybrid", "launcherApp", "hybrid")
    },
    match : function(os) {
        return navigator.platform.indexOf(os) != -1
    },
    installExtensions : function() {
        if(this.match("Win32") || this.match("Win64")) {
            alert("Windows")
        }
        else if(this.match("MacPPC") || this.match("MacIntel")) {
            alert("Mac")
        }
        else if(this.match("Linux i686") || this.match("Linux x64")) {
            alert("Linux")
        }
        else {
            alert("Unknown")
            // run Linux ? choice
        }
    },
    setJavaVersion : function(version) {
        //
    },
    exportHTML : function() {
        //
    },
    syncLAFMode : function() {
        if(this.syncLAF) {
            document.getElementById("idsync1").checked = false
            this.syncLAF = false
            //alert("You must reload to turn this off")
        }
        else {
            document.getElementById("idsync1").checked = true
            this.syncLAF = true
        }
        this.saveState();
    },
    delayedMode : function() {
        if(this.delayed) {
            document.getElementById("iddelayed1").checked = false
            this.delayed = false
        }
        else {
            document.getElementById("iddelayed1").checked = true
            this.delayed = true
        }
        this.saveState();
    },
    debugMode : function() {
        if(this.debug) {
            document.getElementById("iddebug1").checked = false
            this.debug = false
            alert("You must reload to turn this off")
        }
        else {
            document.getElementById("iddebug1").checked = true
            this.debug = true
            this.debugLook();
        }
        this.saveState();
    }
}

if(typeof noVerticalAdjustments == "undefined") {
    onload   = hybrid.adjustViewport
    onresize = hybrid.adjustViewport
}
onfocus  = function() { /*hybrid.weAreInFocus=true; hybrid.adjustViewport();*/ }
onblur   = function() { /*hybrid.weAreInFocus=false;*/ }

jQuery(window).load(function () {
    //hybrid.adjustViewport();
    jQuery("#consoleId").click(function() { hybrid.changeAssembly("console"); })
    jQuery("#mediaplayerId").click(function() { hybrid.changeAssembly("mediaplayer"); })
    jQuery("#editorId").click(function() { hybrid.changeAssembly("editor"); })
    jQuery("#publisherId").click(function() { hybrid.changeAssembly("publisher"); })
    jQuery("#effects3dId").click(function() { hybrid.changeAssembly("effects3d"); })
    jQuery("#idextrememode1").click(function() { hybrid.extremeMode(); })
    jQuery("#iddelayed1").click(function() { hybrid.delayedMode(); })
    jQuery("#iddebug1").click(function() { hybrid.debugMode(); })
    jQuery("#idsync1").click(function() { hybrid.syncLAFMode(); })
    jQuery("#closeicon").click(function() {
        jQuery("#groupFixedRightHidden").fadeOut(hybrid.fadeTime);
        jQuery("#groupFixedViewportHidden").animate({marginRight: "0px"}, 0)
    })
    hybrid.cacheImage("/media/topp07.png")
    /*var cookie = readCookie("state");
    if(cookie != null) {
        var changes = cookie.split(",")
        if(changes.length == 4) {
            document.getElementById("idextrememode1").checked = (changes[0] == "true")
            document.getElementById("idsync1").checked        = (changes[1] == "true")
            document.getElementById("iddelayed1").checked     = (changes[2] == "true")
            document.getElementById("iddebug1").checked       = (changes[3] == "true")

        }
    }*/
});

