var jslt = {}
jslt.JSLT = function(){
   
}
jslt.JSLT.prototype={
		 /**
	     *
	     * @param {String} module nazwa modułu, bez .js
	     * Nie jest określony czas załadowania
	     */
	    include : function(fName /*String*/, inHead){
	        var fName = fName.indexOf("/") > -1 ? fName : '/modules/jslt/' + fName
	        if(fName.indexOf(".") == -1){
				fName += '.js'
			}
	        if (inHead) {
	            var script = document.createElement("script");
	            script.src = fName;
	            script.type = "text/javascript";
	            document.getElementsByTagName("head")[0].appendChild(script);
	        }
	        else {
	            var s = '<script type="text/javascript" language="JavaScript" src="' + fName + '">//</script>'
	            document.write(s)
	        }
	        
	    }
}
var JSLT = new jslt.JSLT()
if (typeof(console) == "undefined") {
    jslt.consoleClass = function(){
        this.log = function(){
            
        }
    }
    console = new jslt.consoleClass()
}

function PluginEmbeder(){
    this.hmgrp = 'PluginEmbeder'
    this.trackHistory = false
    this.showQuestionLink = false
    this.detectVersion = []
	this.offerAlternative=false
    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' />"
                      str+='</a>'
					  	if(this.offerAlternative){
							str += "<a href='/adm/vsw/light'><img style='position:absolute;top:400px'  src='/modules/PluginEmbeder/light_v.gif' />"
						str+='</a>'
						}

					    var wasShow = false;
                        try {
                            var cl = new jslt.CokiesLib()
                            wasShow = cl.readCookie("PluginEmbederShowedGet") == "true"
                            cl.setCookie("PluginEmbederShowedGet", "true")
                        }
                        catch (e) {
						globalLog(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) {
            this.attributes.id = 'swfGeneric' + Math.round(Math.random() * 100000)
        }
        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) {
                    globalLog(e)
                }
            }
        }
        if (this.trackHistory) {
            $.HistoryManager.register(this)
        }
    }
    /**
     *
     * @param {PageRequestVO} pageRequest Call from swf
     */
    this.syncPage = function(pageRequest){
        this.curPageRequest = pageRequest
        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)
        }
    }
    /**
     * Zwraca parametry strony html wygenerowanej po żadaniu
     * Uzywana przez strone swf do konfiguracji i synchronizacji stanu
     */
    this.getConfig = function(){
        var ret = {}
        ret.id_site = id_site
        ret.lang = lang
        ret.translations = translations//Array
        ret.languages = languages//Array
        ret.useTracking=typeof(google_tracking_id)=="string"
		ret.is_default_page=is_default_page
        return ret
    }
}

function PluginEmbeder(){
    this.hmgrp = 'PluginEmbeder'
    this.trackHistory = false
    this.showQuestionLink = false
    this.detectVersion = []
	this.offerAlternative=false
    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' />"
                      str+='</a>'
					  	if(this.offerAlternative){
							str += "<a href='/adm/vsw/light'><img style='position:absolute;top:400px'  src='/modules/PluginEmbeder/light_v.gif' />"
						str+='</a>'
						}

					    var wasShow = false;
                        try {
                            var cl = new jslt.CokiesLib()
                            wasShow = cl.readCookie("PluginEmbederShowedGet") == "true"
                            cl.setCookie("PluginEmbederShowedGet", "true")
                        }
                        catch (e) {
						globalLog(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) {
            this.attributes.id = 'swfGeneric' + Math.round(Math.random() * 100000)
        }
        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) {
                    globalLog(e)
                }
            }
        }
        if (this.trackHistory) {
            $.HistoryManager.register(this)
        }
    }
    /**
     *
     * @param {PageRequestVO} pageRequest Call from swf
     */
    this.syncPage = function(pageRequest){
        this.curPageRequest = pageRequest
        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)
        }
    }
    /**
     * Zwraca parametry strony html wygenerowanej po żadaniu
     * Uzywana przez strone swf do konfiguracji i synchronizacji stanu
     */
    this.getConfig = function(){
        var ret = {}
        ret.id_site = id_site
        ret.lang = lang
        ret.translations = translations//Array
        ret.languages = languages//Array
        ret.useTracking=typeof(google_tracking_id)=="string"
		ret.is_default_page=is_default_page
        return ret
    }
}

/**
 * Using:
 * JSLT.include("CookiesLib")
 * var cookiesLib=new jslt.CokiesLib()
 * cookiesLib.readCookie(name)
 * cookiesLib.setCookie(cookieName,cookieValue,seconds)
 * cookiesLib.setCookie(cookieName,cookieValue)//session
 */
jslt.CokiesLib=function (){
	/**
	 * 
	 * @param {Object} name
	 * @return {String} or null
	 */
	this.readCookie=function(name){
	    var search = name + "=";
	    var ret=null;
	    if (document.cookie && document.cookie.length > 0) {
		    var offset = document.cookie.indexOf(search);
		    if (offset != -1) {
			    offset += search.length;
			    var end = document.cookie.indexOf(";", offset);
			    if (end == -1)
				    end = document.cookie.length;
			    ret= unescape(document.cookie.substring(offset, end))   ;
			    };
		    };
	    return ret;
	 };
	 /**
	  * 
	  * @param {Object} cookieName
	  * @param {Object} cookieValue
	  * @param {Object} seconds
	  */
	this.setCookie=function (cookieName,cookieValue,seconds) {
		 var expireStr=""
		 if(seconds!=undefined && seconds>0){
		 	expireStr+=";expires="
			 var today = new Date();
			 var expire = new Date();
			expire.setTime(today.getTime() + seconds*1000);
			expireStr+=expire.toGMTString()
		 }
		 document.cookie = cookieName+"="+escape(cookieValue)+ expireStr+" ;path=/";              
	}
	this.checkCookie=function(isSession){
		var cName="jsltTestCookie"
		if(isSession){
			seconds=null
		}else{
			seconds=3600
		}
		this.setCookie(cName,"ok",seconds)
		if(this.readCookie(cName)=="ok"){
			ret= true;
		}else{
			ret= false;
		}
		this.setCookie(cName,null,seconds)
		return ret;
	}
}
jslt.CookiesLib=jslt.CokiesLib //mistake fix
//JSLT.include("FullSize")
jslt.OverPage=function (){
	this.outenerLayerId="outenerOverPageDiv"
	this.innerBackgroundLayerId="OverPageDiv"
	this.layerId="contentOverPageDiv"
	this.getLayer=function(opacity,params){
		if(!params){
			params={}
		}
		if(jslt.overPageInstance){//console.log(jslt.overPageInstance)
			document.getElementById(this.outenerLayerId).style.display="block"
			document.getElementById(this.innerBackgroundLayerId).style.display="block"
			var div=document.getElementById(this.layerId)
			div.style.display="block"
			return div
		}else{
			jslt.overPageInstance=this
		}
		var outener=document.createElement("div")
		outener.style.position="absolute"
		outener.style.top="0px"
		outener.style.left="0px"
		outener.style.zIndex=1001
		outener.id=this.outenerLayerId
		document.body.appendChild(outener)
		var background=document.createElement("div")
		background.style.position="absolute"
		background.style.top="0px"
		background.style.left="0px"
		background.id=this.innerBackgroundLayerId
		outener.appendChild(background)
		if(typeof(opacity)!="undefined"){
			background.style.filter = "alpha(opacity:"+Math.round(opacity*100)+")";
     		 background.style.opacity =opacity;
			 if(params.backgroundColor){
			 	background.style.backgroundColor=params.backgroundColor
			 }else{
			 	background.style.backgroundColor="#cccccc"
			 }
		}
		var div=document.createElement("div")
		div.style.position="absolute"
		div.style.top="0px"
		div.style.left="0px"
		div.id=this.layerId
		outener.appendChild(div)
		return div
	}
	this.setCenter=function(){
		var setCenterActions=function(){
			var cen=new jslt.FullSize()
			cen.setSize2(jslt.overPageInstance.outenerLayerId,true)
			cen.setSize(jslt.overPageInstance.innerBackgroundLayerId,true)
			cen.setSize(jslt.overPageInstance.layerId,true)
			}
		setCenterActions()
		window.onresize=setCenterActions;
	}
	this.hide=function(){
		document.getElementById(this.outenerLayerId).style.display="none"
		document.getElementById(this.innerBackgroundLayerId).style.display="none"
		document.getElementById(this.layerId).style.display="none"
		document.getElementById(this.layerId).innerHTML=""
	}
	this.show=function(){
		document.getElementById(this.outenerLayerId).style.display="block"
		document.getElementById(this.innerBackgroundLayerId).style.display="block"
		document.getElementById(this.layerId).style.display="block"
	}
	this.centerContent=function(objRef,objSizeA){
			var bodyEl=new jslt.Element(document.body)
			var viewSize=bodyEl.getRequiredSize()
			var divEl=new jslt.Element(jslt.overPageInstance.outenerLayerId)
			viewSize[1]=divEl.getViewHeight()
			var thisPosition=[parseInt((viewSize[0]-objSizeA[0])/2),Math.max(0,parseInt((viewSize[1]-objSizeA[1])/2))]
			objRef.style.left=thisPosition[0]+"px"
			objRef.style.top=thisPosition[1]+"px"
	}
}

function OverPageInfo(){
this.overPage=null
this.cookiesLib=new jslt.CokiesLib()
this.emb=new PluginEmbeder()
this.targeturls;
this.targeturl='';
this.target;
this.cookieName="overWasShowedSess"
this.persistent=false
this.setMovie=function(url,target,type,params){
	this.emb.addAttribute("wmode","transparent")
	for(var el in params){
		this.emb.addAttribute(el,params[el])
	}
	this.emb.addVariable("isHTML","true")
	if(url.indexOf("ref=")==-1){
		url+=(url.indexOf("?")>-1?"&":"?")
		url+="ref=OverPageInfo"
	}
	this.targeturl=url
	this.target=target
}
this.assign=function(divNameOrOver,left,top){

	if(this.cookiesLib.readCookie(this.cookieName)=="true" && !this.persistent){
		return;
	}
	if(typeof divNameOrOver =="string"){
		var targetDiv=document.getElementById(divNameOrOver)
		targetDiv.innerHTML="<div id='overPageContentAbsolute' style='position:absolute;top:"+top+"px;left:"+left+"px' >"+this.emb.getHTML()+"</div>"
	}else{
		this.overPage=divNameOrOver
		this.overPage.getLayer().innerHTML=this.emb.getHTML()

	}
}
this.closeMe=function(){
	this.setWasShowed()
	this.hideBN()
}
this.hideBN=function(){
	if(this.overPage!=null){
		this.overPage.hide()

	}else{
		document.getElementById("overPageContentAbsolute").style.clip="rect(0px 0px 0px 0px)"
	}
}
this.clickMe=function(nr){
	this.setWasShowed()
	if (this.target == "_blank" || this.targeturl.indexOf('#')>-1) {
		this.hideBN()
	}
	if(nr!=undefined){
		location=this.targeturls[nr]
		return
	}
	if(this.target=="_blank"){
		var nw=window.open(this.targeturl)
	}else if(this.target=="_top"){
		location=this.targeturl
	}
}
this.setVisited=function(){
	this.setWasShowed()
}
this.setWasShowed=function(){
	this.cookiesLib.setCookie(this.cookieName,"true")
}
}