

var fnif = {

    //root: "http://localhost:3132/",
    root: "",
    iniheight: 0,
    xtrheight: 0,
    doIframe: function() { e = document.getElementsByTagName('iframe'); for (i = 0; i < e.length; i++) { if (/\bautoHeight\b/.test(e[i].className)) { fnif.addEvent(e[i]); } } },
    undoThisIframe: function() { alert(this.id); },

    gotourl_e: function(id, e) { var u = $(e).attr('rel'); this.gotourl(id, this.root + u.slice(u.indexOf('BlogEngine'))); },
    gotourl: function(id, url) { $("#" + id).attr('src', url); },

    doThisIframe: function() {


        fnif.addEvent(this);

        try {


            var f = null;
            var u = "";

            if (fnjs.browser.name == "FF") { u = this.src; f = this.contentWindow; }
            else { f = window.frames[this.id]; if (f.location) { u = f.location.href; } }

        
            if (u.indexOf("BlogEngine") != -1) {
                if (this.id == "dv_blg" && fnme.index == 2) {
                    if (f.currentPost) {
                        fnme.sethtml("pg_hdr", f.currentPost[0], null, null, true, 'h');
                        fnme.sethtml("pg_det", f.currentPost[2], f.currentPost[3], null, true, 'link gap');
                        fnme.sethtml("pg_det", f.currentPost[4]);
                        var clr = true;
                        var css = "";
                        if (f.currentPost[8]) { fnme.sethtml("pg_opt", f.currentPost[8], f.currentPost[10], f.currentPost[9], clr, "link prv"); clr = false; css = " sep"; }
                        if (f.currentPost[5]) { fnme.sethtml("pg_opt", f.currentPost[5], f.currentPost[7], f.currentPost[6], clr, "link nxt" + css); }
                        fnme.pglink[fnme.index] = $('#hdr_cn').clone(true);
                        fnme.scrollTo();
                        fnme.saveurl(u);
                    }
                }

                else if (this.id == "dv_gbk" && fnme.index == 4) {
                    if (f.currentGsbk) {
                        if (f.currentGsbk[0] != "" && u.indexOf('guestsign') == -1) { fnme.sethtml("pg_opt", f.currentGsbk[0] + ' | ' + f.currentGsbk[1], null, null, true, 'right'); }
                        else { fnme.sethtml("pg_opt"); }
                        fnme.pglink[fnme.index] = $('#hdr_cn').clone(true);
                        fnme.scrollTo();
                        fnme.saveurl(u);
                    }

                }
            }
        }

        catch (ex) { alert(ex.message); }

    },

    setblog: function(idx) {
        var id = "dv_blg"; var h = window.frames[id].currentPost[idx]; h = this.root + h.slice(h.indexOf('BlogEngine')); document.getElementById(id).src = h;
    },

    addEvent: function(e) { fnif.setHeight(e); fnjs.addEvent(e, 'load', fnif.doThisIframe); },

    curele: function(e) {
        this.iniheight = 0;
        this.xtrheight = 0;

        if (e.contentDocument) {
            if (e.contentDocument.body) {
                this.iniheight = 500;
                if (fnjs.browser.name == "FF") { return e.contentDocument.documentElement; }
                else { return e.contentDocument.body; }
            }
        }
        else if (e.contentWindow.document.documentElement) { this.xtrheight = 50; return e.contentWindow.document.documentElement; }
        else if (e.contentWindow.document.body) { return e.contentWindow.document.body.scrollHeight; }
        else { return null; }
    },

    curdoc: function(e) {

        return;

        if (e.contentDocument) { alert(11); return e.contentDocument; }
        else if (e.contentWindow.document.documentElement) { alert(22); return e.contentWindow.document; }
        else if (e.contentWindow.document.body) { alert(33); return e.contentWindow.document; }
        else if (e.document) { alert(44); return e.document; }
    },






    setHeightx: function(e) {
        return;
        var h = null;
        var d = this.curele(e);
        if (!d) { return; }
        if (this.iniheight != 0) { e.style.height = this.iniheight + "px"; }
        h = d.scrollHeight + this.xtrheight + 50;
        alert(h);
        e.style.height = h + 'px';
    },


    setHeight: function(e) {
        var h = null; ;
        try {
            if (e.contentDocument) {
                if (e.contentDocument.body) {
                    e.style.height = "500px";
                    if (fnjs.browser.name == "FF") { h = e.contentDocument.documentElement.scrollHeight }
                    else { h = e.contentDocument.body.scrollHeight; }
                }
            }

            else if (e.contentWindow) {



                if (e.contentWindow.document) {

                    if (e.contentWindow.document.documentElement) {
                        h = e.contentWindow.document.documentElement.scrollHeight + 50;
                    }
                    else if (e.contentWindow.document.body) {
                        h = e.contentWindow.document.body.scrollHeight;
                    }
                }
            }

            else {

            }
        }

        catch (ex) { alert(ex.message); }

        if (h != null) {
            e.style.height = (h + 50) + 'px';
            if (h > 100) {
                fnme.iniscroll();
            }
        }

    }
}

var fnwg = {


    itemclick: function(key, url, idx) {
        if (key == "new") { fnme.shownew(url, idx, true); }
    }
}



var fnme = {
    url: null,
    e: null,
    isloading: true,
    vdalert: false,
    iniaction: null,
    iniprm: null,
    pnlmode: 0,
    pos: { index: 0, height: 0, width: 0, top: 151, mgtop: 0 },
    timer: null,
    info: [],
    pgmode: [],
    pgsuburl: [],
    pglink: [],
    index: null,
    vdmode: null,
    vdpos: -1,
    fmmode: 0,
    lan: 'fr',
    isjscroll: false,
    loadstatus: 0,
    mumode: [],
    ismenu: false,
    iscsl: false,
    istotop: false,
    $pane: null,
    flashfix: false,

    ini: function(id, ln) {

        if (ln != this.lan && ln != undefined) { this.savelan(ln); return; }

        this.isloading = false;
        var a;

        if (this.iniaction == "new") { a = this.iniprm.split("&"); this.shownew(a[0], a[1]); }
        else if (this.iniaction == "alb") { this.showalb(this.iniprm); }
        else if (this.iniaction == "vid") { a = this.iniprm.split("&"); this.playclip(a[0], a[1], a[2], a[3], true, a[4]); }
        else if (this.iniaction == "ctl") { this.getcontrol(this.iniprm); }
        else if (this.iniaction == "blg") { this.showcurext(this.iniprm); }
        else if (this.iniaction == "gbk") { this.showcurext(this.iniprm); }
        this.iniaction = null;

        var fn = null;

        if (this.flashfix) { fn = function() { fnme.fixFlash(false); } }

        $('#' + id).fadeOut("1200", fn);

    },

    fixFlash: function(ishide) {
        if (ishide)
            $('.flashfix').addClass('outofsight');
        else
            $('.flashfix').removeClass('outofsight');


    },

    fadeenter: function(isini) { if (isini) { myFx.opacity('pn_load', 100, 0, 800, 'fnme.fadeenter()'); } else { myFx.opacity('dv_enter', 0, 100, 800); } },

    inijquery: function() {



        this.$pane = $("#dv_container");


        fnfp.iniplayer();

        if (fnjs.browser.name != "IE") { $("body").addClass("body-gk"); }


        $('a.overlink').overlay({ expose: { color: '#000', opacity: 0.5 }, absolute: true, effect: 'apple', top: 75, onBeforeLoad: function() {
            var $a = this.getTrigger();

            var c = $a.attr('rev');
            var d = $a.attr('rel');


            if (c != '') {
                c = c + '.ascx';
                var i = 0;
                if (d == '#overlay_if') { i = 9; } else if (d == '#overlay_cp') { i = 10; }
                var p = fnmst_getPuByIndex(i);
                p.get_Parameters()['url'] = $a.attr('href');
                if (p.get_UserControlPath() != c) { p.set_UserControlPath(c); }
                if (!fnme.pgmode[i]) { fnme.pgmode[i] = true; p.refresh(); }
            }

            //fnme.scrollTo(0, true);

            if (fnme.flashfix) { fnme.fixFlash(true); }

        },

            onClose: function() { if (fnme.flashfix) { fnme.fixFlash(false); } }

        }).show();

        $(".linkcp").click(function() { $("#an_cp").click(); });

        $("#an_sp").hide();





        fnif.doIframe();

        if (this.loadstatus != 1) { this.fadeenter(true); }


    },

    iniload: function() { if (this.loadstatus == 1) { this.loadstatus = 0; this.ini('dv_in'); } },
    tglvideo: function(show) {
    
        this.vdalert = false;
    
        if (this.vdmode != show) {
            if (show) { $('#dv_vd').removeClass('hidden'); } else { $('#dv_vd').addClass('hidden'); }
            if (this.vdmode) { $f().stop(); } else { this.vdalert = true; } this.vdmode = show;
        }
    },


    playclip: function(e, h, fs, idx, isini, pos) {
        this.pgsuburl[this.index] = e + "&" + h + "&" + fs + "&" + idx + "&" + pos;
        if (this.isloading) { this.setaction("vid", this.pgsuburl[this.index]); return; }
        pos = Number(pos);
        if (this.vdpos != pos) {
            this.vdpos = pos;
            if (pos == 0) { $('#dv_vd').removeClass('tvi'); } else { $('#dv_vd').addClass('tvi'); } 
        }
        this.tglvideo(true);

        if (fnjs.browser.name == "FF" && this.vdalert) { fnfp.iniplayer(); }
        fnfp.play(e, h, fs);
        this.pgmode[this.index] = idx;
        if (isini) { if (pos == 0) { fnme.showvid(); } else { this.setframe("int") } }
        this.saveurl(this.pgsuburl[this.index]);
    },

    iniscroll: function() { this.$pane.jScrollPane({ animateTo: true, showArrows: true, width: this.pos.width, height: this.pos.height, scrollbarWidth: 21, scrollbarMargin: 0, reinitialiseOnImageLoad: true }); },
    createmenu: function(idx, htm) {
        document.getElementById("fm_mu").style.display = "block";
        if (htm != undefined && htm != '') { document.getElementById("dv_mu_cn").innerHTML = htm; fnMn.buildmenu("dv_mu", 0); }
        this.mumode[idx] = true;
        this.ismenu = true;
    },

    menuclick: function(i) { var id = "#h" + this.lan + "_" + i; this.scrollTo(id); },
    find: function(id) { return document.getElementById(id); },
    cleartimer: function() { clearTimeout(this.timer); },
    settimer: function(fn, t) { this.timer = setTimeout(fn, t); },
    showbackToTop: function(show) { if (show != this.istotop) { $('#bt_top').css('display', show ? 'block' : 'none'); this.istotop = show; } },
    fademe: function(id, s) { if (id != undefined || s) { this.$pane.hide(); if (id != undefined) { $('#' + id).css('display', 'block'); } fnme.iniscroll(); } this.showpage(true); },
    setaction: function(e, p) { this.iniaction = e; this.iniprm = p },
    gotourl: function(idx, url) { if (idx == 0) { javascript: window.open(url); } else if (idx == 1) { document.location.href = url; } else if (idx == 2) { fn_seturl(url); } },
    setheader: function(e) { $("#pg_tit").html(e); },
    scrollTo: function(e, iswin) { if (iswin) { $.scrollTo(0); } else if (e) { this.$pane[0].scrollTo(e); } else { try { this.$pane[0].scrollTo(0); } catch (ex) { alert(ex.message); } } },
    status: function() { this.closeframe(); },
    savelan: function(e) { if (this.lan != e) { this.lan = e; cmservice.fnsrv_setlan(e, fnme.serverresult, fnme.error, fnme.timeout); } },
    showhomepanel: function(qidx, idx) { fnqm.hilite(qidx, idx); },
    showhomeChangeStart: function(fidx, tidx) { var e = $('#dv_qm input'); e.removeClass('lnkqsel'); var ei = $(e[tidx - 1]); ei.addClass('lnkqsel'); $("#dv_pn_hd").html(ei.attr('title')); },
    serverresult: function(e, ctx) { if (e == 'LNG') { location.href = "index.aspx"; } },
    timeout: function(e) { },
    error: function(e) { },
    showpage: function(e) { var p = $("#dv_container"); if (e) { p.fadeIn(800, function() { if (fnjs.browser.name == "IE") { $(this).removeAttr('filter'); } }); } else { p.hide(); $(".hdrs").hide(); this.showbackToTop(false); if (this.ismenu) { $("#fm_mu").hide(); this.ismenu = false; } } },
    sethtml: function(id, htm, url, tip, clr, css) {
        var e;
        var f = $("#" + id);
        if (!tip) { tip = ""; }
        if (!css) { css = ""; }
        if (url) { e = $("<a/>").html(htm).attr('rel', url).attr('title', tip).addClass(css).click(function() { fnif.gotourl_e('dv_blg', this); }); }
        else if (htm) { e = $("<span/>").html(htm).attr('title', tip).addClass(css); }
        else { f.hide(); return false; }
        if (clr) f.empty();
        f.append(e).show();
    },


    loadpage: function(setonly, url, index, pos_index, txt, subtxt, reset) {

        if (this.pnlmode != 0) { return; }

        if (this.index != index) {

            this.showpage(false);
            this.index = index;

            var e = document.getElementById("bt_" + index);
            if (this.e != null) { this.e.className = "bt"; } e.className = "bt-sl"; this.e = e;

            if (this.pos.index != pos_index) {

                $("#dv_pg").removeClass().addClass('fm-pg' + pos_index);
                this.setpos(pos_index);
                var $p = $('#dv_jScroll');
                if ($p) {
                    $p.width(this.pos.width);
                    $('>.jScrollPaneTrack, >.jScrollArrowUp, >.jScrollArrowDown, >.jScrollCap', $p).remove();

                }

            }

            if (reset) {
                this.pgsuburl[this.index] = null;
                if (this.index == 2) { this.pgmode[this.index] = undefined; }
            }
            if (!setonly) { this.loadurl(url, e.id); os.MoveToPanel(this.index + 1); }
            else { this.url = url; }
            this.setheader(txt);
        }

        else if (!reset) { return; }
        else {
            this.pgsuburl[index] = null;
            if (index == 2) { this.url = url; this.pgmode[index] = undefined; this.showcurext('blg'); }
            else if (index == 6) {
                this.url = url; this.showcur('vid', 0, false, false);
                //    this.framehilite("ifcs", this.pgmode[this.index]); 

            }
            else if (index == 5) { this.url = url; this.showcur('new', 0, false, false); }
        }

    },

    setpos: function(i) {
        var $c = $('#dv_pg_wrap');
        this.pos.mtop = fnjs.parseInt($c.css('margin-top'), 0);
        this.pos.width = fnjs.parseInt($c.css('width'));
        this.pos.height = fnjs.parseInt($c.css('height'), 400) - this.pos.mtop;
        this.pos.index = i;
    },

    loadurl: function(url) { if (this.url != url) { fn_seturl(url); this.status(); this.saveurl(); } },
    loadsuburl: function(url, surl) { fn_seturl(url); this.saveurl(url + "&" + surl); },
    saveurl: function(surl) { if (surl == undefined || surl == "") { surl = ""; } else { this.pgsuburl[this.index] = surl; surl = "?" + surl; } cmservice.fnsrv_seturl(this.index + surl, fnme.wsresult, fnme.error, fnme.timeout); },
    setpanelmode: function(mode) { if (mode == 0) { this.cleartimer(); } this.pnlmode = mode; },
    cache: function(id, htm, h) { var e = document.getElementById(id); if (!e) { e = document.createElement("input"); e.setAttribute("type", "hidden"); e.setAttribute('id', id); e.setAttribute("name", id); e.setAttribute("value", htm); e.setAttribute("header", h); document.getElementById("dv_hidden").appendChild(e); } else if (!!htm) { e.value = htm; } },
    framechange: function(id, e, txt) { window.frames[id].changeGallery(e, txt, this.pgmode[this.index]); },
    framehilite: function(id, idx) { window.frames[id].hilite(idx); },
    framecloseview: function(id) { window.frames[id].closeView() },
    framecaption: function(id, e) { window.frames[id].setCaption(e); },
    showcsl: function(url) { if (this.isloading) { this.setaction("csl"); } else { this.csmode = 1; this.showframe(this.csmode, "ifcs", this.info[3]); } },
    showgal: function(idx, url, h) { var e = this.find("hd_gal_" + idx); if (!e) { if (url == undefined) { url = ''; } cmservice.fnsrv_gethtml("GAL|" + url + "|" + idx + "|" + h, fnme.galresult, fnme.error, fnme.timeout); } else { this.showframe("gal", "ifgl", null, e); } },
    galresult: function(a) { fnme.framechange("ifgl", a[0], a[2]); fnme.cache('hd_gal_' + a[1], a[0], a[2]); fnme.setframe("gal"); },
    showalb: function(url) { if (this.isloading) { this.setaction("alb", url); return; } var e = this.find("hd_alb"); if (!e) { if (url == undefined) { url = ''; } cmservice.fnsrv_gethtml("ALB|" + url, fnme.albresult, fnme.error, fnme.timeout); } else { this.showframe("gal", "ifcs", null, e); } },
    albresult: function(a) { var h = a[1].substring(0, a[1].indexOf('[')); fnme.pgmode[fnme.index] = Number(a[2]); fnme.framechange("ifcs", a[0], a[1]); fnme.framechange("ifgl", a[3], h); fnme.cache('hd_alb', a[0], a[1]); fnme.cache('hd_gal_' + a[2], a[3], h); fnme.setframe("gal"); },
    showlnk: function() { var e = this.find("hd_lnk_" + this.lan); if (!e) { cmservice.fnsrv_gethtml("LNK", fnme.lnkresult, fnme.error, fnme.timeout); } else { fn_displaylink(e.value); } },
    lnkresult: function(a) { fn_displaylink(a[0]); fnme.cache("hd_lnk_" + fnme.lan, a[0], ''); },
    showvid: function(url) { if (this.isloading) { return; } var e = this.find("hd_vid"); if (!e) { if (url == undefined) { url = ''; } cmservice.fnsrv_gethtml("VID|" + url, fnme.vidresult, fnme.error, fnme.timeout); } else { this.showframe("vid", "ifcs", null, e); } },
    vidresult: function(a) { fnme.framechange("ifcs", a[0], a[1]); fnme.cache('hd_vid', a[0], a[1]); fnme.setframe("vid", a[1]); },
    shownew: function(url, i, ismenu) {
        this.pgsuburl[this.index] = url + "&" + i;
        if (this.isloading) { this.setaction("new", this.pgsuburl[this.index]); return; }
        if (this.pgmode[this.index] != 2) { if (url == undefined) { url = ''; } cmservice.fnsrv_gethtml("NEW|" + url + "|" + i, fnme.newresult, fnme.error, fnme.timeout); }
        else if (!ismenu) { fnme.setframe("new"); this.loadsuburl(url, i); api_new0.click(i).seekTo(i, 1000, function() { this.getConf().easing = 'linear'; }); }
        else { this.loadsuburl(url, i); }
    },

    newresult: function(a) { fnme.pgmode[fnme.index] = 2; $("#dv_new").html(a[1]); setTimeout(a[0] + "fnme.shownew('" + a[2] + "'," + a[3] + ");", 0); },


    showcurext: function(key) {
        if (this.isloading) { this.setaction(key, key); return; }

        if (this.pgmode[this.index] == undefined) {
            var r = fnif.root;
            var u = fnjs.urlquery(this.url, true);
            var ur;
            var nm;

            if (key == "blg") { nm = "dv_blg"; ur = r + "BlogEngine.Web/default.aspx" }
            else if (key == "gbk") { nm = "dv_gbk"; ur = r + "BlogEngine.Web/gb/guestbook.aspx" }

            if (u != null) { u = "&url=" + u; } else { u = ""; }

            ur = ur + "?" + (this.lan == 'fr' ? "Index=fr&lan=fr-FR" : "Index=en&lan=en-US") + u;

            document.getElementById(nm).src = ur; this.pgmode[this.index] = 1;
        }
        else {

            this.resetpageheaders();
        }

        this.setframe(key)
    },

    resetpageheaders: function() { var e = $('#hdr_cn'); e.empty(); $(fnme.pglink[fnme.index]).clone(true).appendTo(e); },
    showframe: function(key, id, h, e) { if (e != undefined) { h = e.attributes.getNamedItem("header").value; this.framechange(id, e.value, h); this.setframe(key); } else { alert(90000); } },
    setframe: function(key, h) {

        if (this.fmkey == key) { return; }
        this.closeframe();
        if (key == null) { return }

        var e = $('#dv_' + key);
        var s = false;

        if (key == "gal" || key == "gbk" || key == "blg") { e.removeClass('hidden'); }
        else if (key == "vid") { }
        else if (key == "int") { $(".homeview").show(); if (this.isjscroll) { $jScroller.start(); } }
        else { e.show(); }

        if (key == "gal") { this.showcsl('fm-csl-gl'); }
        else if (key == "vid") { this.showcsl('fm-csl-vd'); $("#dv_bar").show(); }
        this.fmkey = key;


        if (key == "gbk" || key == "blg") {
            if (this.pgsuburl[this.index] != undefined) { s = true; }
        }

        if (key == "vid" || key == "gal") { s = true; }


        this.fademe(undefined, s);

    },

    closeframe: function() {
        if (this.fmkey == null) { return }
        var e = $('#dv_' + this.fmkey);
        if (this.fmkey == "gal" || this.fmkey == "gbk" || this.fmkey == "blg") { e.addClass('hidden'); }
        else if (this.fmkey == "vid") { this.tglvideo(false); }
        else if (this.fmkey == "int") {
            this.tglvideo(false);
            $(".homeview").hide();
            if (this.isjscroll) { $jScroller.stop(); }
        }
        else { e.hide(); }

        if (this.fmkey == "gal") { this.framecloseview("ifgl"); this.showcsl(); }
        else if (this.fmkey == "vid") { this.showcsl(); $("#dv_bar").hide(); }
        this.fmkey = null;
    },


    showcsl: function(css) { var e = $('#dv_csl'); if (css != undefined) { e.removeClass().addClass(css); this.iscsl = true; } else { e.addClass('hidden'); this.iscsl = false; } },
    tglcsl: function(show) { if (this.iscsl != show) { var e = $("#dv_csl"); if (show) { e.removeClass('hidden').fadeIn("slow"); } else { e.addClass('hidden'); } this.iscsl = show; } },
    framedv: function(key) { var e = document.getElementById("dv_" + key); if (e) { return e; } else { return null; } },
    frameclick: function(idx, url, fn, cp, ds) { if (fn == 'vid') { this.playclip(url, cp, ds, idx, false, 0); } else if (fn == 'gal') { this.showgal(idx, url, cp); this.framecaption("ifcs", cp); } },
    framemouseover: function(idx, url, fn) { },

    getcontrol: function(key) {
        var p = fn_getpu(key);
        if (p == null) { return; }
        var px = p.get_Parameters()['ctl'];
        var h = p.get_Parameters()['hdr'];
        if (p.get_UserControlPath() != px) { p.set_UserControlPath(px); p.refresh(); }
        this.pgmode[this.index] = 1;
        this.setframe(key, h);
    },


    showcur: function(key, pos, iscur, isini) {
        var p;
        if (iscur && !!this.pgsuburl[this.index]) { p = this.pgsuburl[this.index].split("&"); }
        else { p = fnjs.urlquery(this.url); }
        if (p != null) {
            var e = null;
            var h = '';
            var fs = ''
            var i = 0;
            if (p.length > 0) { if (p[0] != '') { e = p[0]; } }
            if (p.length > 1) { h = p[1]; }
            if (p.length > 2) { fs = p[2]; }
            if (p.length > 3) { i = Number(p[3]); }
            if (e == null) { return; }
            if (key == 'vid') { this.playclip(e, h, fs, i, isini, pos); }
            else if (key == 'new') { this.shownew(e, i); }
        }
    },

    setpage: function(id, ispfx) { if (ispfx) { id = id + '_' + this.lan; } this.fademe(id); }




}


