offer.StaticContentView = function(){
    this.StaticContentView()
}
offer.StaticContentView.prototype = {
    StaticContentView: function(){
        var sitemap = []
        var links = $('#allSiteLinks > a[data-type="additive"]');
        for (var i = 0; i < links.length; i++) {
            var el = links[i]
            if (el.className.indexOf('langLink') == -1) {
                sitemap.push({
                    label: el.innerHTML,
                    id: String(el.id).substr(3)
                })
            }
        }
        var ul = document.createElement("ul")
        document.getElementById('mlContainer').appendChild(ul)
        ul.className = "jslt-tv-list jslt-tv-list-l1"
        this.createMenu(sitemap, ul);
        $.HistoryManager.register(this);
        $(document).bind('siteMenuClick', this.evMenuClick)
    },
    createMenu: function(items, container){
        for (var i = 0; i < items.length; i++) {
            var li = document.createElement("li")
            container.appendChild(li)
            li.className = "jslt-tv-el jslt-tv-el-l1"
            li.id = 'staticContent' + items[i].id
            var item = document.createElement("a")
            li.appendChild(item)
            item.onclick = new Function("offerInstance.staticContentView.evItemClick('" + items[i].id + "','" + items[i].label + "')")
            item.innerHTML = items[i].label
        }
        var mainJQ = $('#staticContentTrigger')
        if (mainJQ) {
            mainJQ[0].onclick = new Function("offerInstance.staticContentView.evItemClick('" + items[0].id + "','" + items[0].label + "')")
        }
    },
    evItemClick: function(id, title){
    	this.serviceLoad(id, title);
    		this.sign('staticContent' + id);
    },
    serviceLoad: function(id, title){
        this.pr = new cms2.site.vo.PageRequestVO();
        this.pr.id_page = id
        this.pr.title = title
        this.pr.lang = lang
        this.pr.transform_content = true
        this.pr.daoClassName = "fromPage"
        offerInstance.serviceDelegate.getStaticContent(this.pr)
        //offer.ViewHelper.setViewTitle(title)
        $(document).trigger('siteMenuClick', ['staticContent'])
        $(document).trigger('EVENT_NAVIGATION_PATH_CHANGE', [[decodeURI(title)]])
       // $.HistoryManager.save(this)
    },
    sign: function(id){
        $('#mlContainer li').each(function(i){
            if (this.id == id) {
                this.className = "jslt-tv-el jslt-tv-el-l1 jslt-tv-el-act-l1"
            }
            else {
                this.className = "jslt-tv-el jslt-tv-el-l1"
            }
        })
    },
    evContentAvailable: function(pageRequest){
        offerInstance.tabView.selectById("staticContentView", true)
        offerInstance.tabView.clearCurrent();
        offerInstance.tabView.getCurrent().innerHTML = pageRequest.content.content
        //przetwarzamy scripts TODO Zrobić rozróżnienei na jedno/wielo krotnie ładowane
        $("script",$('#staticContentView')).each(function(i){
            $.getScript(this.src);
        })
    },
    saveState: function(){
        var p = {
            id_page: this.pr.id_page,
            title: this.pr.title
        }
        return {
            hmgrp: 'StaticContentView',
            params: p
        }
    },
    loadState: function(par){
        if (par.hmgrp == 'StaticContentView') {
            this.evItemClick(par.id_page, par.title)
        }
    },
    evMenuClick: function(e, txt){
        if (txt != 'staticContent') {
            offerInstance.staticContentView.sign(null)
        }
    }
}

