﻿
function converte_em_numero(valor) {
    if (valor.search(/px/i) >= 0) {
        return valor.replace('px', '') * 1;
    } else if (valor.search(/%/i) >= 0) {
        return valor.replace('%', '') / 100;
    } else {
        return valor
    }
}

function converte_em_numero_x(valor) {
    if (valor.search(/%/i) >= 0) {
        return converte_em_numero(valor) * tela_width;
    } else {
        return converte_em_numero(valor) * 1;
    }
}

function converte_em_numero_y(valor) {
    if (valor.search(/%/i) >= 0) {
        return converte_em_numero(valor) * tela_height;
    } else {
        return converte_em_numero(valor) * 1;
    }
}

function seta(elemento, v_left, v_top, v_width, v_height, v_opacity, v_tempo) {
    elemento.stop();
    var v_tempo2 = tempo;
    if (v_tempo != '' && v_tempo != undefined) { v_tempo2 = v_tempo; }
    if (sep == "?" && (v_tempo == '' || v_tempo == undefined)) { v_tempo2 = 0; }

    if (v_left != '' && v_left != undefined) {
        elemento.css("left", converte_em_numero_x(elemento.css("left")));
        v_left_array = v_left.split(";");
        v_left2 = converte_em_numero_x(v_left_array[0]);
        if (v_left_array.length > 1) { v_left2 += converte_em_numero_x(v_left_array[1]) }
        elemento.animate({ left: v_left2 }, { queue: false, duration: v_tempo2 });
    }

    if (v_top != '' && v_top != undefined) {
        elemento.css("top", converte_em_numero_y(elemento.css("top")));
        v_top_array = v_top.split(";");
        v_top2 = converte_em_numero_y(v_top_array[0]);
        if (v_top_array.length > 1) { v_top2 += converte_em_numero_y(v_top_array[1]) }
        elemento.animate({ top: v_top2 }, { queue: false, duration: v_tempo2 })
    }
    
    if (v_width != '' && v_width != undefined) {
        elemento.css("width", converte_em_numero_x(elemento.css("width")));
        v_width_array = v_width.split(";");
        v_width2 = converte_em_numero_x(v_width_array[0]);
        if (v_width_array.length > 1) { v_width2 += converte_em_numero_x(v_width_array[1]) }
        elemento.animate({ width: v_width2 }, { queue: false, duration: v_tempo2 })
    }

    if (v_height != '' && v_height != undefined) {
        elemento.css("height", converte_em_numero_y(elemento.css("height")));
        v_height_array = v_height.split(";");
        v_height2 = converte_em_numero_y(v_height_array[0]);
        if (v_height_array.length > 1) { v_height2 += converte_em_numero_y(v_height_array[1]) }
        elemento.animate({ height: v_height2 }, { queue: false, duration: v_tempo2 });
    }

    if (v_opacity != '' && v_opacity != undefined  && v_opacity != elemento.css('opacity')) {
        if (elemento.css('display') == 'none') { elemento.css("opacity", 0); }
        elemento.css('display', 'block');
        elemento.animate({ opacity: v_opacity },v_tempo2, function () {
            if (elemento.css('opacity') == 0) { elemento.css('display', 'none'); }
        });
    }
}

function seta_tamanho() {
    tela_width = converte_em_numero_y($('#geral').css('width'));
    tela_height = converte_em_numero_y($('#geral').css('height'));
}

function liga_verifica_posicao() {
    clearInterval(var_timeout);
    var_timeout = setInterval('verifica_posicao()', 100);
}

function verifica_posicao() {
    if (para == false) {
        //$('#barra_azul_acima').css('width', converte_em_numero($('#barra_azul_acima').css('width')) + 1);
        tela_width_ant = tela_width;
        tela_height_ant = tela_height;
        seta_tamanho();
        if (tela_width_ant != tela_width || tela_height_ant != tela_height) {
            posiciona(500);
        }
    }
}

$(window).resize(function () {
    posiciona(tempo_link);
});

jQuery(document).ready(function ($) {
    posiciona(tempo_link);
    liga_verifica_posicao();
});

function funcoes_extras() {
    posiciona(tempo_link);
    controla_imagens('');
}

function posiciona(v_tempo) {
    // elemento  - 1:v_left - 2:v_top - 3:v_width - 4:v_height - 5:v_opacity - 6:v_tempo
    secao = retorna_variaveis('secao', window.location.href.split(sep)[1]);
    if (secao != "") {
        para = true;
        tempo = v_tempo;
        seta_tamanho();

        if (secao != 'home') {
        } else {
        }
        seta($('#box_logo'), '50%;-440', '138', '', '', '');
        seta($('#sombra1'), '50%;-485', '', '', '', '');
        seta($('#sombra2'), '50%;-485', '100%;-106', '', '', '');
        seta($('#lateral1'), '50%;-500', '', '', '', '');
        seta($('#lateral2'), '50%;485', '', '', '', '');
        seta($('#lateral3'), '50%;-500', '100%;-125', '', '', '');
        seta($('#lateral4'), '50%;485', '100%;-125', '', '', '');
        seta($('#fotos'), '50%;-75', '', '', '', '');
        seta($('[id$=pagina_conteudo__box_linguas]'), '50%;-450', '', '', '', '');
        seta($('[id$=pagina_conteudo__box_menu]'), '50%;-435', '', '', '', '');
        seta($('[id$=pagina_conteudo__box_empresa]'), '50%;-65', '', '', '', '');
        seta($('[id$=pagina_conteudo__box_rodape]'), '50%;-445', '100%;-75', '', '', '');
        
        seta($('#box_conteudo_left'), '', '', '50%;-480', '', '');
        seta($('#box_gocce'), '50%;385', '100%;-104', '', '', '');

        setTimeout('para = false;', tempo + 500);
    }
//    alert("sh" + screen.height + " -dh " + document.documentElement.clientHeight + " -dsh " + document.documentElement.scrollHeight + " -bsh " + document.body.scrollHeight + " -oh " + document.documentElement.offsetHeight + " -gh " + converte_em_numero_y($('#geral').css('height')) + " -ih " + " -bh " + $('body').css('height'));
//    alert("sw" + screen.width + " -dw " + document.documentElement.clientWidth + " -sw " + document.documentElement.scrollWidth + " -ow " + document.documentElement.offsetWidth + " -gw " + converte_em_numero_y($('#geral').css('width')) );
} 

function controla_imagens(secao_mouse) {
    if (secao_mouse == '') { secao_mouse = secao; }
    if (secao_mouse2 != secao_mouse) {
        secao_mouse2 = secao_mouse;
        foto1 = $('#imagem1');
        foto2 = $('#imagem2');
        if (foto2.css('opacity') == 1) {
            foto1.css('opacity', 0);
            seta(foto1, '', '', '', '', '1','1000');
            seta(foto2, '', '', '', '', '0', '1000');
            foto1.attr('src', 'admin/clientes/lemos/images/foto_' + secao_mouse2 + '.jpg');
        } else {
            foto2.css('opacity', 0);
            seta(foto1, '', '', '', '', '0', '1000');
            seta(foto2, '', '', '', '', '1', '1000');
            foto2.attr('src', 'admin/clientes/lemos/images/foto_' + secao_mouse2 + '.jpg');
        }
    }
}

