﻿nie = (navigator.appName.indexOf("Microsoft") == -1);

function getel(doc, id) {
    return doc.getElementById(id);
}

function el(id) {
    return getel(document, id);
}

function getElementsById(sId) {
    var outArray = new Array();

    if (typeof (sId) != 'string' || !sId) {
        return outArray;
    };

    if (document.evaluate) {
        var xpathString = "//*[@id='" + sId.toString() + "']"
        var xpathResult = document.evaluate(xpathString, document, null, 0, null);
        while ((outArray[outArray.length] = xpathResult.iterateNext())) { }
        outArray.pop();
    }
    else if (document.all) {

        if (document.all[sId])
            for (var i = 0, j = document.all[sId].length; i < j; i += 1) {
                outArray[i] = document.all[sId][i];
            }

    } else if (document.getElementsByTagName) {

        var aEl = document.getElementsByTagName('*');
        for (var i = 0, j = aEl.length; i < j; i += 1) {

            if (aEl[i].id == sId) {
                outArray.push(aEl[i]);
            };
        };

    };

    if ((outArray.length == 0) && (el(sId)))
        outArray[0] = el(sId);

    return outArray;
}

function escreve(s) {
    document.write(s);
}

function arr(n) {
    this.length = n
    for (var i = 0; i < n; i = i + 1) {
        this[i] = ''
    }
}

function element_top(el) {
    var et = 0
    while (el) {
        et += el.offsetTop
        el = el.offsetParent
    }
    return et
}


function element_left(el) {
    var et = 0
    while (el) {
        et += el.offsetLeft
        el = el.offsetParent
    }
    return et
}

/* 19/05/2008 */
function escreveFlash(id, src, width, height, align, salign, transparent, mozila, versao, onmouseover, onmouseout) {
    s = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + (versao) + ',0,0,0" width="' +
        (width) + '" height="' + (height) + '" id="' +
        id + '" ' + (align != '' ? 'align="' + align + '"' : '') +
        (onmouseover != '' ? ' onmouseover="' + onmouseover + '"' : '') +
        (onmouseout != '' ? ' onmouseout="' + onmouseout + '"' : '') +
        '><param name="quality" value="high" />' +
        (src != '' ? '<param name="movie" value="' + src + '" />' : '') +
        (salign != '' ? '<param name="salign" value="' + salign + '" />' : '') +
        (transparent ? '<param name="wmode" value="transparent" />' : '') +
        '<param name="menu" value="false" /><param name="scale" value="noscale" />';
    if (mozila)
        s += '<embed ' +
            (src != '' ? 'src="' + src + '" ' : '') +
            'loop="false" menu="false" quality="high" scale="noscale" width="' +
            (width) + '" height="' + (height) + '" name="' + id + '" ' +
            (align != '' ? 'align="' + align + '" ' : '') +
            (salign != '' ? 'salign="' + salign + '" ' : '') +
            (onmouseover != '' ? 'onmouseover="' + onmouseover + '" ' : '') +
            (onmouseout != '' ? 'onmouseout="' + onmouseout + '" ' : '') +
            (transparent ? 'wmode="transparent" ' : '') +
            'allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" swliveconnect="true" />';
    s += '</object>';
    escreve(s);
}

function loadFlashWithPreload(id, src, preloadId, paramsStr) {
    preloaded = movieIsLoaded(mv(preloadId));
    loaded = movieIsLoaded(mv(id));

    if ((!loaded) && (preloaded)) {
        cmd = 'loadMovie(\'' + id + '\', \'' + src + '\', [' + paramsStr + '])';
        setTimeout(cmd, 1);
        setTimeout(cmd, 500);
    }

    paramsStr = paramsStr.replace(/\'/g, '\\\'');
    cmd = 'loadFlashWithPreload(\'' + id + '\', \'' + src + '\', \'' + preloadId + '\', \'' + paramsStr + '\')';

    if ((loaded) && (nie))
        setTimeout(cmd, 1000);
    else if (!loaded)
        setTimeout(cmd, 100);

}

function mv(movieName) {
    tM = null;
    if (navigator.appName.indexOf("Microsoft") != -1) {
        tM = document.all[movieName];
        if (typeof (tM) != "undefined") {
            if (tM.length && (tM.length > 0))
                tM = tM[0];
            else if (tM.length && (tM.length == 0))
                tM = null;
        }
    }
    else if (document[movieName])
        tM = document[movieName];
    else
        tM = el(movieName);

    return tM;
}

function loadMovie(id, movie, params) {
    mv(id).LoadMovie(0, movie);
    for (p = 0; p < params.length; p += 2)
        mv(id).SetVariable(params[p], params[p + 1]);
}

function loadMovieWithDelay(id, movie, paramsStr) {
    cmd = 'loadMovie(\'' + id + '\', \'' + movie + '\', ' + paramsStr + ')';
    setTimeout(cmd, 500);
}

function movieIsLoaded(theMovie) {
    if (typeof (theMovie) != "undefined") {
        return ((typeof (theMovie.PercentLoaded) != "undefined") && (theMovie.PercentLoaded() == 100));
    } else {
        return false;
    }
}

function movieIsReady(theMovie) {
    return (typeof (theMovie.PercentLoaded) != "undefined");
}

function newImage(arg) {
    if (document.images) {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
}

function imprime() {
    window.focus();
    setTimeout("window.print()", 500);
}

var ie5 = document.all && !window.opera
var lastHeight = 0;
var autoHeight = 1;
var autoHSet = 0;
function adjustIFrameSize() {

    window.parent.adjust1(0);
    
    if (!el('content'))
        return;

    iframeElement = getel(window.parent.document, 'ifcontent');

    ih = iframeElement.offsetHeight;
    h = document.documentElement.scrollHeight;

    if (h > ih) {
        document.documentElement.style.overflow = '';
        document.documentElement.style.overflowx = 'scroll';
    }
    else {
        document.documentElement.style.overflow = 'hidden';
        document.documentElement.style.overflowx = 'hidden';
    }

    lastHeight = h;

    if ((autoHeight) && (!autoHSet)) {
        autoHSet = 1;
        setTimeout('autoH()', 500);
    }
}

function autoH() {
    h = document.documentElement.scrollHeight;
    if (h != lastHeight)
        adjustIFrameSize();
    setTimeout('autoH()', 500);
}

var elementosFonte = '';
function fonte(aumenta) {
    // default
    dif = Number(readCookie('fontSize'));

    els = elementosFonte.split(',');

    for (i = 0; i < els.length; i++) {

        if (els[i].substr(0, 1) == '_') {
            dfs = getElementsById(els[i].substr(1, els[i].length - 1));
        }
        else
            dfs = [el(els[i])];

        for (xx = 0; xx < dfs.length; xx++) {
            df = dfs[xx];
            if (!df)
                continue;
            def = Number(df.getAttribute('default-font', 0));
            if (aumenta > -1) {
                size = Number(df.style.fontSize.substr(0, df.style.fontSize.length - 2));
                dif = size - def;
            }
            else {
                dif = Number(readCookie('fontSize'));
                size = def + dif;
            }
            //alert(els[i] + ' default: ' + (def) + ' atual: ' + (size));

            if (aumenta > -1) {
                if ((dif <= 0) && !aumenta) {
                    alert(fonteMinTxt);
                    return;
                }
                if ((dif >= 4) && aumenta) {
                    alert(fonteMaxTxt);
                    return;
                }
                if (aumenta)
                    size++;
                else
                    size--;
            }

            dif = size - def;

            df.style.fontSize = (size) + "px";
        }
    }

    var expire = new Date();
    expire.setTime(new Date().getTime() + 3600000 * 24 * 5000);
    document.cookie = 'fontSize' + "=" + escape((dif) + '') + ";expires=" + expire.toGMTString();

    adjustIFrameSize();
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function indica() {
    ifc = window.parent.frames['ifcontent'];
    iurl = 'indique.aspx?1=1';
    if (ifc) {
        if (ifc.idcontent != 0)
            iurl += '&idContent=' + (ifc.idcontent);
        if (ifc.idcontentsection != 0)
            iurl += '&idContentSection=' + (ifc.idcontentsection);
        ifc.location = htmlbase + iurl;
    }
    else
        window.location = iurl;
}

function amplia2(id, pw, ph, text) {
    wp = window.parent;
    wpd = wp.document;
    ov = getel(wpd, 'overlay');
    amp = getel(wpd, 'ampliacao');
    ampi = getel(wpd, 'ampliInner');
    img = getel(wpd, 'imgAmpliar2');
    txt = getel(wpd, 'ampliText');

    ampi.style.width = (pw + 12) + 'px';
    ov.style.height = (wpd.documentElement.scrollHeight) + 'px';
    img.src = wp.htmlbase + 'images/blank.gif';
    txt.style.display = (text != '' ? 'block' : 'none');
    txt.innerHTML = text;

    th = wpd.documentElement.clientHeight;
    th = ((th - ph - 12 - 18 - 3) / 2) - 20;
    if (th < 0)
        th = 0;
    th = th + window.parent.document.documentElement.scrollTop;
    ampi.style.marginTop = (th) + 'px';

    ov.style.display = 'block';
    amp.style.display = 'block';

    img.src = wp.htmlbase + 'ModuleHandlers/Content/picture.aspx?idContentPicture=' +
        (id) + '&w=' + (pw) + '&h=' + (ph);
}

function fechaAmpliar2() {
    wp = window.parent;
    wpd = wp.document;
    img = getel(wpd, 'imgAmpliar2');
    txt = getel(wpd, 'ampliText');
    ov = getel(wpd, 'overlay');
    amp = getel(wpd, 'ampliacao');

    ov.style.display = 'none';
    amp.style.display = 'none';
    img.src = '';
    txt.innerHTML = '';
}



/* ----------------------------------------------- */

var menuItens = new arr(0);
var menuComplete = 0;
var menuLoaded = 0;
var menuShowed = 0;

function addMenuItem(id, src, preloadId, paramsStr) {
    menuItens.length++;
    i = menuItens.length - 1;
    menuItens[i] = new arr(4);
    menuItens[i][0] = id;
    menuItens[i][1] = src;
    menuItens[i][2] = preloadId;
    menuItens[i][3] = paramsStr;
}

function menuDone() {
    menuComplete = 1;
}

function mostraMenu() {
    preloaded = movieIsLoaded(mv('menuPreload'));
    loaded = movieIsLoaded(mv('menuPreload'));

    if ((!menuComplete) || (!preloaded) || (!loaded))
        setTimeout('mostraMenu()', 100);
    else if (!menuLoaded) {
        menuLoaded = 1;
        lastX = 0;
        for (i = menuItens.length - 1;  i >= 0; i--) {
            x = ((menuItens.length - i - 1) * 200);
            lastX = x;
            cmd = 'loadMovie(\'' + menuItens[i][0] + '\', \'' + menuItens[i][1] + '\', [' + menuItens[i][3] + '])';
            setTimeout(cmd, x);

            // para manter visivel no mozila
            menuItens[i][3] = menuItens[i][3].replace(/\'/g, '\\\'');
            cmd = 'loadFlashWithPreload(\'' + menuItens[i][0] + '\', \'' + menuItens[i][1] + '\', \'' + menuItens[i][2] + '\', \'' + menuItens[i][3] + '\')';
            setTimeout(cmd, x+1000);
        }
        setTimeout('menuShowed = 1', lastX);
    }
}

function umclique(base, sel) {
    val = sel.options[sel.selectedIndex].value;
    if (val != '')
        window.location = base + val;
}

// *********************************************************************************************************************

activeMenu = 0;

function getel(doc, id) {
    if (doc.all)
        return doc.all[id];
    else
        return doc.getElementById(id);
}

var timeid = 0;

function debugMenu(s) {
    el('txtteste').value = s + '\n' + el('txtteste').value;
}

function abreMenu(e, id) {
    
    // debugMenu('abreMenu1');
    
    window.isOverButton = id;
    window.isOverMenu = 0;

    showmenu_src = ie5 ? e.srcElement : e.target;
    showmenu_which = eval('ms' + id);
    showmenu_id = id;
    
    // debugMenu('hidemenu pela abremenu');

    hidemenu();
    clearhidemenu()

    clearTimeout(timeid);
    timeid = setTimeout('showmenu()', 200);

    // debugMenu('abreMenu2');
}
function fechaMenu(id, subitens) {
    // debugMenu('fechaMenu');
    
    if (id == window.isOverButton) {
        window.isOverButton = 0;
        delayhidemenu();
    }
}

var defaultMenuWidth = 120;

var ie5 = document.all && !window.opera
var ns6 = document.getElementById

// já escrito. problema de posicionamento
dsm = ie5 ? document.all.divSubMenu : document.getElementById("divSubMenu")

function iecompattest() {
    return (document.compatMode && document.compatMode.indexOf("CSS") != -1) ? document.documentElement : document.body
}

function element_top(el) {
    var et = 0
    while (el) {
        et += el.offsetTop
        el = el.offsetParent
    }
    return et
}

function element_left(el) {
    var et = 0
    while (el) {
        et += el.offsetLeft
        el = el.offsetParent
    }
    return et
}

var showmenu_src = 0;
var showmenu_which = 0;
var showmenu_id = 0;

function showmenu(src, which, id) {

    // debugMenu('showmenu');

    src = showmenu_src;
    which = showmenu_which;
    id = showmenu_id;

    mv('m' + id).SetVariable('hideOver', 'no');
    mv('m' + id).SetVariable('isOverSub', 'yes');
    activeMenu = id;
    if (!document.all && !document.getElementById)
        return
    menuobj = el('divSubMenu')
    menuobj.innerHTML = '<table id=tbMenu border=0 cellpadding=0 cellspacing=0>' + which + '</table>';
    menuobj.style.width = (getel(document, 'tbMenu').offsetWidth > defaultMenuWidth ? getel(document, 'tbMenu').offsetWidth : defaultMenuWidth) + "px";
    getel(document, 'tbMenu').style.width = menuobj.style.width;

    //menuobj.style.width=defaultMenuWidth;
    menuobj.contentwidth = menuobj.offsetWidth
    menuobj.contentheight = menuobj.offsetHeight
    if (!ie5)
        menuobj.style.top = element_top(src) + 0 + "px";
    else
        menuobj.style.top = element_top(src) + 0 + "px";

    menuobj.style.left = element_left(src) + 138 + "px";

    menuobj.style.visibility = "visible"
    
    // debugMenu('showmenu2');
    
    return false
}

function contains_ns6(a, b) {
    while (b.parentNode)
        if ((b = b.parentNode) == a)
        return true;
    return false;
}

function hidemenu(porDelay) {
    
    // debugMenu('hidemenu ' + (porDelay) + ' ');
    
    if (window.menuobj) {
        menuobj.style.visibility = "hidden"
        mv('m' + activeMenu).SetVariable('isOverSub', 'no');
        mv('m' + activeMenu).SetVariable('hideOver', 'yes');
    }
}

function dynamichide(e) {
    if (!window.isOverButton) {
        
        // debugMenu('dynamichide');
        
        if (ie5 && !menuobj.contains(e.toElement)) {
            // debugMenu('hidemenu pela dynamichide');
            hidemenu()
        }
        else if (ns6 && e.currentTarget != e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget)) {
            // debugMenu('hidemenu pela dynamichide');
            hidemenu()
        }
    }
}

function delayhidemenu() {
    if (!window.isOverMenu)
        window.delayhide = setTimeout("hidemenu(1)", 500)
}

function clearhidemenu() {
    if (window.delayhide)
        clearTimeout(delayhide)
}

if (ie5 || ns6)
    document.onclick = hidemenu

/* ----------------------------------------------- */

function slideShow(varId, elementId, outerElementId, linkId, picturesCount, auto, slide_time, slide_change_speed, startDelay, legendElementId) {

    this.varid = varId;
    this.elementId = elementId;
    this.outerElementId = outerElementId;
    this.linkId = linkId;
    this.automatic = auto;
    this.slideTime = slide_time;
    this.speed = slide_change_speed;
    this.startDelay = startDelay;
    this.legendElementId = legendElementId;

    this.outItens = new matriz(0);

    this.changingImage = 0;
    this.outItemIndex = -1;
    this.newIndex = -1;
    this.changeStep = 0;
    this.changeDirection = 1;
    this.isFirstChange = 1;
    this.timeId = 0;

    this.addOutItem = function(foto, texto, link, title, legend) {
        this.outItens.length++;
        this.outItens[this.outItens.length - 1] = new matriz(5);
        this.outItens[this.outItens.length - 1].src = foto;
        this.outItens[this.outItens.length - 1].texto = texto;
        this.outItens[this.outItens.length - 1].link = link;
        this.outItens[this.outItens.length - 1].title = title;
        this.outItens[this.outItens.length - 1].legend = legend;
    }

    this.init = function() {
        setTimeout(varId + '.loadPictures()', 100);
        setTimeout(varId + '.changePicture(1, false)', 100);
    }

    this.loadPictures = function() {
        for (i = 0; i < this.outItens.length; i++) {
            if (!(this.outItens[i].ok)) {
                // verifica se a imagem anterior já foi carregada
                if ((i > 0) && !(this.outItens[i - 1].img.complete)) {
                    setTimeout(varId + '.loadPictures()', 100);
                    break;
                }
                else {
                    this.outItens[i].img = newImage(this.outItens[i].src);
                    this.outItens[i].ok = 1;
                }
            }
        }
    }

    this.changePicture = function(forward, byUser, destindex) {

        if ((this.changingImage) && (byUser))
            return;

        // if (byUser)
        //    this.automatic = 0;

        if (byUser)
            clearTimeout(this.timeId);

        img = el(elementId);

        if (this.newIndex == this.outItemIndex) {
            this.newIndex = this.outItemIndex;
            if (forward) {
                this.newIndex++;
                if (this.newIndex >= this.outItens.length)
                    this.newIndex = 0;
            }
            else if (typeof (destindex) != "undefined") {
                this.newIndex = destindex;
            }
            else {
                this.newIndex--;
                if (this.newIndex < 0)
                    this.newIndex = this.outItens.length - 1;
            }
        }

        if ((this.outItens[this.newIndex].ok) && (this.outItens[this.newIndex].img.complete)) {
            this.changingImage = 0;

            slow = 0;
            if ((!byUser) && (this.outItemIndex > -1)) {
                slow = 1;
                this.slowChange(1);
            }
            else
                this.show(this.newIndex);

            this.outItemIndex = this.newIndex;

            if (this.automatic)
                this.scheduleNext(slow);
        }
        else {
            img.src = "images/blank.gif";
            this.changingImage = 1;
            setTimeout(varId + '.changePicture(' + (forward) + ', 0)', 100);
        }
    }

    this.scheduleNext = function(slow) {
        clearTimeout(this.timeId);
        x = this.slideTime + (slow ? (this.speed * 1000) : 0) + (this.isFirstChange ? this.startDelay : 0);
        this.timeId = setTimeout(varId + '.changeSlide()', x);
        this.isFirstChange = 0;
    }

    this.slowChange = function(start) {
        try {
            oDiv = el(outerElementId);
            oDiv.style.filter = "blendTrans(duration=" + (this.speed) + ")";
            oDiv.filters.blendTrans.apply();
            oDiv.filters.blendTrans.play();
            this.show(this.newIndex);
        }
        catch (e) {
            this.show(this.newIndex);
        }
    }

    this.changeSlide = function() {
        if (this.automatic)
            this.changePicture(1, 0);
    }

    this.show = function(index) {
        el(elementId).src = this.outItens[index].src;
        if (el(this.linkId)) {
            el(this.linkId).href = this.outItens[index].link;
            el(this.linkId).title = this.outItens[index].title;
        }
        // custom sj
        setTimeout(this.varid + '.showText()', 10)
    }

    this.showText = function() {
        if (!el(elementId).complete)
            setTimeout(this.varid + '.showText()', 50)
        else {

            if (el('foto')) {
                w = el(this.elementId).offsetWidth;
                el('foto').style.width = (w) + 'px';
            }

            index = this.newIndex;
            if (el(this.legendElementId)) {
                el(this.legendElementId).innerHTML = this.outItens[index].legend;
                el(this.legendElementId).style.display = this.outItens[index].legend != '' ? 'block' : 'none';

                // custom sj
                el(this.legendElementId).style.width = (w - 44) + 'px';
                if (el('bg-p')) {
                    el('bg-p').style.display = el(this.legendElementId).style.display;
                    el('bg-p').style.width = el(this.legendElementId).style.width
                }
            }
        }
    }

}

function matriz(n) {
    this.length = n
    for (var i = 0; i < n; i = i + 1) {
        this[i] = ''
    }
}

/* ----------------------------------------------- */

function contentBeforePrint() {
    getel(window.parent.document, 'ifcontent').style.height = (getel(window.parent.document, 'ifcontent').offsetHeight + 150) + 'px';
}

function contentAfterPrint() {
    getel(window.parent.document, 'ifcontent').style.height = (getel(window.parent.document, 'ifcontent').offsetHeight - 150) + 'px';
}

function onclickz(name) {
    var opcoes = document.getElementsByName(name)
    for (var i = 0; i < opcoes.length; i++) {
        var op = opcoes[i];
        op.style.display = 'block';
    }
}

function adjust1(isHome) {

    cw = el('content-wrapper');
    iw = el('iframe-wrapper');
    ic = el('ifcontent');
    pr = el('prog');

    cw.style.width = isHome ? '1052px' : '1002px';
    iw.style.width = isHome ? '864px' : '814px';
    ic.style.width = isHome ? '864px' : '814px';
    pr.style.left = isHome ? '135px' : '54px';
}

function sincronizaSlides() {

    ok = ((outdor_diversao.outItens[0].ok) && (outdor_diversao.outItens[0].img) && (outdor_diversao.outItens[0].img.complete) &&
        (outdor_cozinha.outItens[0].ok) && (outdor_cozinha.outItens[0].img) && (outdor_cozinha.outItens[0].img.complete) &&
        (outdor_equipe.outItens[0].ok) && (outdor_equipe.outItens[0].img) && (outdor_equipe.outItens[0].img.complete) &&
        (window.parent.menuShowed));

    if (!ok)
        setTimeout('sincronizaSlides()', 250);
    else {
        outdor_diversao.automatic = 1;
        outdor_cozinha.automatic = 1;
        outdor_equipe.automatic = 1;
        outdor_diversao.scheduleNext(0);
        outdor_cozinha.scheduleNext(0);
        outdor_equipe.scheduleNext(0);
    }
}

function changeGaleriaAuto() {
    clearTimeout(galeria.timeId);
    galeria.automatic = !galeria.automatic;
    if (galeria.automatic)
        galeria.changeSlide();
    b = 'url(images/but_slide_' + estilo + '_' + (galeria.automatic ? 'pause' : 'play') + '.gif)';
    el('slideshow').style.backgroundImage = b;
}

var galeriaRolagemAtiva = 0;
var galeriaRolagemDirecao = 0;
var galeriaRolagemTempo = 50;
var galeriaRolagemStep = 10;
function rolaGaleria(ativa, direcao) {
    galeriaRolagemAtiva = ativa;
    galeriaRolagemDirecao = direcao;
    if (ativa)
        setTimeout('rolaGaleria2()', galeriaRolagemTempo);
}

function rolaGaleria2() {
    step = galeriaRolagemStep;
    if (!galeriaRolagemDirecao)
        step = step * -1;
    s = window.frames['ifgaleria'].document.documentElement.scrollLeft;
    s += step;
    window.frames['ifgaleria'].document.documentElement.scrollLeft = s;
    if (galeriaRolagemAtiva)
        setTimeout('rolaGaleria2()', galeriaRolagemTempo);
}

function adjust2() {

    h1 = document.documentElement.clientHeight;
    h2 = document.documentElement.scrollHeight;
    w1 = document.documentElement.clientWidth;
    w2 = document.documentElement.scrollWidth;

    if ((h1 - h2 >= -10) && (w1 - w2 >= -50)) {
        document.documentElement.style.overflow = 'hidden';
    }
    else {
        document.documentElement.style.overflow = '';
    }
}
