

    function DetectFlash_Engine(){
    	this.ua         = navigator.userAgent;
    	this.isMSIE     = ( (navigator.appName=='Microsoft Internet Explorer') || (this.ua.indexOf('MSIE')!=-1 ) )?true:false;
        this.isOpera    = (this.ua.indexOf('Opera')!=-1)?true:false;
        this.isWin      = (navigator.appVersion.toLowerCase().indexOf("win")!=-1) ? true : false;

        this.defaultMode        = 'standard';
        this.rightPluginVersion = false;
        this.isLoaded           = false;
    };

    DetectFlash_Engine.prototype = {
	    init : function(settings){
		    this.settings = settings;

		    // set defaults
            this._define("mode",                    this.defaultMode);
		    this._define("req_major_version",       8);
		    this._define("req_minor_version",       0);
		    this._define("req_revision",            0);

            this.rightPluginVersion = DetectFlash.getPluginVersion();



            switch( DetectFlash.getParam('mode', this.defaultMode) ){
                case 'redirect':
                    window.location.href = (this.rightPluginVersion) ? DetectFlash.getParam('url_correct_plugin', '') : DetectFlash.getParam('url_incorrect_plugin', '');
                    break;

                default:
                    break;
            }
        },

        getSwfVersion : function(i){
            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;
                    descArray               = flashDescription.split(" ");
                    tempArrayMajor          = descArray[2].split(".");
                    versionMajor            = tempArrayMajor[0];
                    versionMinor            = tempArrayMajor[1];

                    if( descArray[3]!="" ){
                        tempArrayMinor = descArray[3].split("r");
                    }else{
                        tempArrayMinor = descArray[4].split("r");
                    }

                    versionRevision = tempArrayMinor[1]>0 ? tempArrayMinor[1] : 0;
                    flashVer        = versionMajor+"."+versionMinor+"."+versionRevision;

                }else{
                    flashVer = -1;
                }
            }else if( this.ua.toLowerCase().indexOf("webtv/2.6")!=-1 ){
                flashVer = 4;
            }else if( this.ua.toLowerCase().indexOf("webtv/2.5")!=-1 ){
                flashVer = 3;
            }else if( this.ua.toLowerCase().indexOf("webtv")!=-1 ){
                flashVer = 2;
            }else{
                flashVer = -1;
            }

            return flashVer;
        },

        getPluginVersion : function(settings){
            reqVer = parseFloat(this.settings['req_major_version'] + "." + this.settings['req_revision']);

            for( i=25; i>0; i-- ){
                if( this.isMSIE && this.isWin && !this.isOpera ){
                    versionStr = VBGetSwfVer(i);
                }else{
                    versionStr = DetectFlash.getSwfVersion(i);		
                }

                if( versionStr==-1 ){ 
        			return false;
        		}else if( versionStr!=0 ){
                    if( this.isMSIE && this.isWin && !this.isOpera ){
                        tempArray       = versionStr.split(" ");
                        tempString      = tempArray[1];
                        versionArray    = tempString .split(",");				
                    }else{
                        versionArray = versionStr.split(".");
                    }
                    versionMajor    = versionArray[0];
                    versionMinor    = versionArray[1];
                    versionRevision = versionArray[2];
        			versionString   = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
        			versionNum      = parseFloat(versionString);

                    if( (versionMajor>this.settings['req_major_version']) && (versionNum>=reqVer) ){
                        return true;
        			}else{
                        return ( (versionNum>=reqVer && versionMinor>=this.settings['req_minor_version'])?true:false);	
                    }
                }
            }
        },

        getContent : function(n){
            var elm_flash       = 'output_'+n+'_flash';
            var elm_no_flash    = 'output_'+n+'_no_flash';

            return ( DetectFlash.rightPluginVersion ) ? this.settings[elm_flash] : this.settings[elm_no_flash];
        },

	    getParam : function(name, default_value, strip_whitespace){
		    var value = (typeof(this.settings[name])=="undefined") ? default_value : this.settings[name];

            if( value=="true" || value=="false") return (value=="true");

            if( strip_whitespace ) value = DetectFlash.regexpReplace(value, "[ \t\r\n]", "");

            return value;
        },

        regexpReplace : function(in_str, reg_exp, replace_str, opts) {
            if( in_str==null ) return in_str;

            if( typeof(opts)=="undefined" ) opts = 'g';

            var re = new RegExp(reg_exp, opts);
            return in_str.replace(re, replace_str);
        },

        hasCorrectPlugin : function(){
            return DetectFlash.rightPluginVersion;
        },

	    _define : function(key, val_default, bool){
		    var res = DetectFlash.getParam(key, val_default);

		    res = bool ? res.replace(/\s+/g,"") : res;

    		this.settings[key] = res;
    	}
    };

    // global instance
    var DetectFlash = new DetectFlash_Engine();

