var ClientInfo = {
    getScreenSize:
        function() {
            return screen.width + "x" + screen.height;
        },
    getColorDepth:
        function() {
            return screen.colorDepth;
        },
    viewport: 
        {
            width: null,
            height: null,
            check:
                function() {
                    if (typeof(window.innerWidth) == 'number') {
                        // Non-IE
                        this.width = window.innerWidth;
                        this.height = window.innerHeight;
                    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                        // IE 6+ in 'standards compliant mode'
                        this.width = document.documentElement.clientWidth;
                        this.height = document.documentElement.clientHeight;
                    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
                        // IE 4 compatible
                        this.width = document.body.clientWidth;
                        this.height = document.body.clientHeight;
                    }
                },
            getSize:
                function() {
                    return this.width + "x" + this.height;
                }
        },
    flash:
        {
            supported: false,
            version: null,
            check:
                // Extracted from Adobe's Flash Player Detection Kit
                // JavaScript helper required to detect Flash Player PlugIn version information
                function(util) {
                    // NS/Opera version >= 3 check for Flash plugin in plugin array
                    var flashVer = -1;
                    if (navigator.plugins != null && navigator.plugins.length > 0) {
                        if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
                            var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
                            var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
                            var descArray = flashDescription.split(" ");
                            var tempArrayMajor = descArray[2].split(".");                   
                            var versionMajor = tempArrayMajor[0];
                            var versionMinor = tempArrayMajor[1];
                            var versionRevision = descArray[3];
                            if (versionRevision == "") {
                                versionRevision = descArray[4];
                            }
                            if (versionRevision[0] == "d") {
                                versionRevision = versionRevision.substring(1);
                            } else if (versionRevision[0] == "r") {
                                versionRevision = versionRevision.substring(1);
                                if (versionRevision.indexOf("d") > 0) {
                                    versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
                                }
                            }
                            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
                        }
                    }
                    // MSN/WebTV 2.6 supports Flash 4
                    else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
                    // WebTV 2.5 supports Flash 3
                    else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
                    // older WebTV supports Flash 2
                    else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
                    else {
                        if (util.isIE()) {
                            flashVer = this.checkVersionIE();
                        }
                    }       
                    if (flashVer != -1) {
                        this.version = flashVer;
                        this.supported = true;
                    }
                },
            checkVersionIE:
                function() {
                    var version;
                    var axo;
                    var e;

                    // NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

                    try {
                        // version will be set for 7.X or greater players
                        axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
                        version = axo.GetVariable("$version");
                    } catch (e) {}

                    if (!version) {
                        try {
                            // version will be set for 6.X players only
                            axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
                        
                            // installed player is some revision of 6.0
                            // GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
                            // so we have to be careful. 
                        
                            // default to the first public version
                            version = "WIN 6,0,21,0";

                            // throws if AllowScripAccess does not exist (introduced in 6.0r47)             
                            axo.AllowScriptAccess = "always";
    
                            // safe to call for 6.0r47 or greater
                            version = axo.GetVariable("$version");
                        } catch (e) {}
                    }

                    if (!version) {
                        try {
                            // version will be set for 4.X or 5.X player
                            axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
                            version = axo.GetVariable("$version");
                        } catch (e) {}
                    }

                    if (!version) {
                        try {
                            // version will be set for 3.X player
                            axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
                            version = "WIN 3,0,18,0";
                        } catch (e) {}
                    }

                    if (!version) {
                        try {
                            // version will be set for 2.X player
                            axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
                            version = "WIN 2,0,0,11";
                        } catch (e) {
                            version = -1;
                        }
                    }
        
                    if (version != -1) {
                        return version.replace(/^WIN /,"").replace(/,/g,".");
                    }
                    return -1;
                }
        },
    java:
        {
            supported: false,
            version: null,
            check:
                function(util) {
                    // There seems to be no way to check simply whether Java is supported
                    // (at least without actually launching an applet) - we need to look
                    // for the actual Java plugin.
                    this.version = this.checkVersion(util);
                    if (this.version) {
                        this.supported = true;
                    }
                },
            checkVersion:
                function(util) {
                    var version = null;
                    // For non-IE (at least Firefox, Opera, Chrome) we check for Java plugin
                    // in plugin array - but the supported Java version must be extracted
                    // from mime type.
                    if (navigator.plugins != null) {
                        var versionArray = [];
                        var regex = /^(application\/x-java-applet;jpi-version=)([0-9].*)/i;
                        for (var i = 0; i < navigator.plugins.length; ++i) {
                            var plugin = navigator.plugins[i];
                            for (var j = 0; j < plugin.length; ++j) {
                                var mimeType = plugin[j];
                                if (regex.test(mimeType.type)) {
                                    // There might be several plugins supporting different Java
                                    // versions; only the highest will be returned.
                                    var newArray = RegExp.$2.split(/[._]/);
                                    if (util.compareArray(newArray, versionArray) > 0) {
                                        versionArray = newArray;
                                    }
                                }
                            }
                        }
                        if (versionArray.length > 0) {
                            version = versionArray.join(".");
                        }
                    }

                    if (version == null && util.isIE) {
                        version = this.checkVersionIE();
                    }

                    return version;
                },
            checkVersionIE:
                function() {
                    // For IE we need to try creating an ActiveXObject appropriate for the Java
                    // plugin - but it's not as nice as with Flash above. There seems to be
                    // exactly one valid ActiveXObject per Java plugin version - so trial and 
                    // error it is...
                    for (var i = 0; i < this.maxJavaVersions.length; ++i) {
                        var version = this.maxJavaVersions[i];
                        var major = version[0];
                        var minor = version[1];
                        for (var rev = version[2]; rev >= 0; --rev) {
                            for (var b = version[3]; b >= 0; --b) {
                                var build = b > 0 ? ("_" + (b < 10 ? "0" : "") + b) : "";
                                var axoName = "JavaPlugin." + major + minor + rev + build;
                                try {
                                    var axo = new ActiveXObject(axoName);
                                    // ActiveXObject created successfully, so Java plugin with
                                    // given version is present.
                                    return major + "." + minor + "." + rev + "." + b;
                                } catch (e) {}
                            }
                        }
                    }
                    return null;
                },
            maxJavaVersions:
                [
                    [1, 9, 2, 30],
                    [1, 8, 2, 30],
                    [1, 7, 2, 30],
                    [1, 6, 1, 30],
                    [1, 5, 1, 30],
                    [1, 4, 2, 30],
                    [1, 3, 1, 30]
                ]
        },
    util:
        {
            isIE:
                function() {
                    var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
                    var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
                    var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
                    return isIE && isWin && !isOpera;
                },
            compareArray:
                function(a, b) {
                    for (var i = 0; i < a.length && i < b.length; i++) {
                        if (a[i] > b[i]) return 1;
                        if (a[i] < b[i]) return -1;
                    }
                    if (a.length > b.length) return 1;
                    if (a.length < b.length) return -1;
                    return 0;
                }
        },
    init:
        function() {
            this.viewport.check(this.util);
            this.flash.check(this.util);
            this.java.check(this.util);
        }
}

