function PluginEmbeder(){
	this.hmgrp='PluginEmbeder'
	this.trackHistory = false
    this.showQuestionLink = false
    this.detectVersion = []
    this.pluginComMethod = "none"//auto - javascript/fscommand zależnie od browsera|javascript
    this.type = "application/x-shockwave-flash"
    this.attributes = {}
    this.addAttribute = function(n, v){
        this.attributes[n] = v
    }
    this.variables = {}
    this.addVariable = function(n, v){
        this.variables[n] = v
    }
	this.addAttribute('onerror','onFlashPlayerError')
		//this.addAttribute('onfocus','this.blur()') //TODO http://trac.test.amu.pl/cms2/ticket/241#comment:2
		this.addAttribute('allowScriptAccess','always')
		this.addAttribute('menu','false')
		onFlashPlayerError=function(p){
			}
    this.getHTML = function(){
        var ua = {}
        ua.ie = /msie/.test(navigator.userAgent.toLowerCase())
        ua.win = ua.ie && /windows/.test(navigator.userAgent.toLowerCase())
        if (this.detectVersion.length == 3) {
            var detector = new adobe.FlashVerDetector()
            var isRequired = detector.compare(this.detectVersion[0], this.detectVersion[1], this.detectVersion[2])
            var isAutoInstall = detector.isAutoInstall()
            if (!isRequired && window.pluginEmbederDetectNoValidVersion) {
                return ""
            }
            if (!isRequired && !window.pluginEmbederDetectNoValidVersion) {
                var myLang = (typeof(lang) == "string" ? lang : "pl")
                if (myLang != "pl" && myLang != "en") {
                    myLang = "pl"
                }
                window.pluginEmbederDetectNoValidVersion = true
                if (!isRequired && isAutoInstall && false) {//TODO niesprawdzone && ua.ie
                    this.addVariable("MMdoctitle", document.title)
                    document.title = "Flash Player Install - " + document.title;
                    this.addVariable("MMredirectURL", window.location)
                    this.addVariable("MMplayerType", ua.ie ? "ActiveX" : "PlugIn")
                    this.addAttribute("file", "/modules/PluginEmbeder/playerProductInstall.swf")
                }
                else 
                    if (!isRequired) {
                        var str = "<div style='position:relative' id='getFlashRelativeDiv'>"
                        str += "<a href='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash'><img  style='position:absolute' src='/modules/PluginEmbeder/flash_brak_" + myLang + ".jpg' border='0' /></a>"
                        var wasShow = false;
                        try {
                            var cl = new jslt.CokiesLib()
                            wasShow = cl.readCookie("PluginEmbederShowedGet") == "true"
                            cl.setCookie("PluginEmbederShowedGet", "true")
                        } 
                        catch (e) {
                        }
                        if (this.showQuestionLink && wasShow) {
                            str += "<a style='position:absolute;top:109px' href='/modules/PluginEmbeder/problem.php?lang=" + myLang + "' target='_blank'>"
                            str += "<img src='/modules/PluginEmbeder/problem_question_" + myLang + ".gif' border='0' alt=''/>"
                            str += "</a>"
                            str += "</div>"
                        }
                        return str
                    }
            }
        }
        var str = '<object type="' + this.type + '" width="' + this.attributes.width + '" height="' + this.attributes.height + '"'
        
        if (!ua.ie) {
            str += ' data="' + this.attributes.file + '"'
        }
        if (this.attributes.id) {
            str += ' id="' + this.attributes.id + '" name="' + this.attributes.id + '"'
            if (this.pluginComMethod == "auto") {
                if (ua.win) {
                    this.addVariable("canUseFscommand", "true")
                }
                else {
                    this.addVariable("fscommandFunctionName", this.attributes.id + "_DoFSCommand")
                }
            }
            else 
                if (this.pluginComMethod == "javascript") {
                    this.addVariable("fscommandFunctionName", this.attributes.id + "_DoFSCommand")
                }
        }
        if (this.attributes.style) {
            str += ' style="' + this.attributes.style + '"'
        }
        if (this.attributes.className) {
            str += ' class="' + this.attributes.className + '"'
        }
		if (this.attributes.onerror) {
            str += ' onerror="' + this.attributes.onerror + '"'
        }
		if (this.attributes.onfocus) {
            str += ' onfocus="' + this.attributes.onfocus + '"'
        }
		if (this.attributes.allowScriptAccess) {
            str += ' allowScriptAccess="' + this.attributes.allowScriptAccess + '"'
        }
        str += '>'
        str += '<param name="movie" value="' + this.attributes.file + '" />'
            var re = /file|width|height|id|style|class|onerror/
            for (var el in this.attributes) {
                if (re.test(el)) {
                    continue;
                }
                str += '<param name="' + el + '" value="' + this.attributes[el] + '" />'
            }
            
            var fva = new Array()
            for (var el in this.variables) {
                fva.push(el + "=" + this.variables[el])
            }
            if (fva.length > 0) {
                str += '<param name="flashvars" value="' + fva.join("&") + '" />'
            }
        str += '</object>'
        return str
    }
    this.assignToElement = function(elId){
        document.getElementById(elId).innerHTML = this.getHTML()
    }
    this.getRef = function(){
        if (navigator.appName.indexOf("Microsoft") != -1) {
            return window[this.attributes.id]
        }
        else {
            return document[this.attributes.id]
        }
    }
    /**
     * Using: emb.startProxy()
     * addExternalInterfaceListener(ref)//ref=function f(object)
     *
     */
    this.startProxy = function(){
        window.externalInterfaceListeners = []
        window.addExternalInterfaceListener = function(ref){
            window.externalInterfaceListeners.push(ref)
        }
        window.externalInterfaceProxy = function(params){
            for (var i = 0; i < window.externalInterfaceListeners.length; i++) {
                try {
                    window.externalInterfaceListeners[i].call(this, params)
                } 
                catch (e) {
                    if (console) {
                        console.log(e)
                    }
                }
            }
        }
		if(this.trackHistory){
			$.HistoryManager.register(this)	
		}
    }
	/**
	 * 
	 * @param {PageRequestVO} pageRequest Call from swf
	 */
    this.syncPage = function(pageRequest){
		this.curPageRequest=pageRequest
        document.getElementById('cms_integration_page_id').innerHTML = pageRequest.id_page
        if(pageRequest.title != ''){
			document.title = pageRequest.title +' - '+universal_title
		}else{
			document.title = universal_title
		}
		if(this.trackHistory){
			$.HistoryManager.save(this)
		}
    }
	this.saveState=function(){
		var p={}
		 p.cms_id=this.curPageRequest.id_page
		for(var pName in this.curPageRequest.getParams){
			p[pName]=this.curPageRequest.getParams[pName]
		}
		return {hmgrp:this.hmgrp,params:p}
	}
	this.loadState=function(par){
		if(par.hmgrp==this.hmgrp){
			if(par.cms_id!=undefined){
				//TODO _get
				
			}
			$('#'+this.attributes.id)[0].evHistoryItem(par)
		}
	}
}
