﻿var listaTitulo = new Array();
var listaDesc = new Array();
var contador = 0;

$(document).ready(function () {

    // INIT
    noLabel.init();

    $('.descriProdutos').scrollPages({ elementSize: 614, elements: 1, direction: 'left' });

    if ($('.rolagemClientes').is('div')) rolagemClientes();

    // LINK ATIVO
    paginaAtiva = window.location + '';
    paginaAtiva = paginaAtiva.split('/').pop();
    paginaAtiva = paginaAtiva.split('?').shift();

    if (paginaAtiva != '') {

        $('#menu li a[href="' + paginaAtiva + '"]').addClass('ativo').parents('ul').show().prev('a').addClass('ativo');

    }

    //MENU
    $("#menu li.sub a").click(function () {
        if (!$(this).next().is(":visible")) {
            $(this).next().show();
        } else {
            $(this).next().hide();
        }

    });


    //TOOLTIP COMUNIDADE
    var contComunidade = $('.container-grafico-comunidade ul').width();
    $('.container-grafico-comunidade li').hover(function () {

        $(this).css('z-index', '999').siblings().css('z-index', '9');

        var widEl = $(this).find('.container-tooltip').width();
        var posTooltip = $(this).position();

        if (posTooltip.left + widEl >= contComunidade) {
            var valorEl = ($(this).width() / 2);
            $(this).find('.container-tooltip').css({ 'left': valorEl + -widEl }).addClass('right').show();

        } else {
            var valorEl = ($(this).find('a').width() / 2);
            $(this).find('.container-tooltip').css({ 'left': valorEl }).show();
        }

    }, function () {
        $(this).find('.container-tooltip').hide();
    });


    //LINHA DO TEMPO
    $('.container-linha-do-tempo li:last-child a').css("margin", "0");
    $('.container-linha-do-tempo li:odd a').css({ 'height': 38, 'padding-top': 42 });
    $('.container-linha-do-tempo li:last-child').addClass('last')

    $('.container-linha-do-tempo li a').click(function () {

        var tamEL = $('.container-linha-do-tempo li').width();
        var qtoEL = $(this).parent().prevAll().length;

        $('.linha-tempo-progresso').animate({ 'width': tamEL * qtoEL + 3 }, 'fast');
        $(this).addClass('ativo').parent().removeClass('progress').prevAll().addClass('progress').find('a').removeClass('ativo');
        $(this).parent().nextAll().removeClass('progress').find('a').removeClass('ativo', 'last');

        var larBtnAno = $('.container-linha-do-tempo li a').width();
        var altBtnAno = $('.container-linha-do-tempo li .container-tooltip').height();

        var larContLinhaTempo = $('.container-linha-do-tempo').width();
        var larTooltip = $('.container-linha-do-tempo li .container-tooltip').width();
        var posELAno = $(this).parent().position();

        $('.container-linha-do-tempo li .container-tooltip').hide();
        $(this).next().show().css({ 'bottom': -altBtnAno + -30 });

        if (posELAno.left + larTooltip >= larContLinhaTempo) {

            $('.container-linha-do-tempo li .container-tooltip').addClass('right').css({ 'left': -larTooltip + larBtnAno / 2 });

        } else {

            $('.container-linha-do-tempo li .container-tooltip').removeClass('right').css({ 'left': larBtnAno / 2 });

        }
    });

    setTimeout(function () {

        $('.container-linha-do-tempo li a:first').trigger('click').addClass('first');

    }, 500)

    // CUFON 
    Cufon.set('fontFamily', 'Fedra Sans Std Book');
    Cufon.replace('h1, h3, h4, #conteudoPrincipal dt a, .acordion, .linhaTempo h3');
    Cufon.replace('h2, .perfil h3', { textShadow: '0 2px #2c2d2e' });
    Cufon.replace('.boxSolucoes h3', { textShadow: '0 1px #2c2d2d' })
    Cufon.replace('.cufon');
    Cufon.replace('.cufon span, .solucoes ul.solucoes li h3', { textShadow: '0 1px #2c2d2d' });

    Cufon.set('fontFamily', 'Fedra Sans Std Medium');
    Cufon.replace('#menu > ul > li > a, #colunaApoio h3')
    Cufon.replace('.produto1 .btn a, .produtoB2B .boxSolucoes .btnVerMais, .produtoB2B .btn span', { textShadow: '0 2px #2a4c54' })
    Cufon.replace('.produto2 .btn a, .produtoLogistica .boxSolucoes .btnVerMais, .produtoLogistica .btn span', { textShadow: '0 2px #616a40' })
    Cufon.replace('.produto3 .btn a, .produtoGestao .boxSolucoes .btnVerMais, .produtoGestao .btn span', { textShadow: '0 2px #8b6434' })
    Cufon.replace('.box .btnVerMais', { textShadow: '0 2px #4d1012' })
    Cufon.replace('.btnEnviar', { textShadow: '0 2px #5f1013' })
    Cufon.replace('#conteudoPrincipal h3, .box-filtro .btnVerMais', { textShadow: '0 1px #2c2d2d' })

    // HOVER CASES E SOLUCOES
    /*$('.box .img').hover(
    function () { $(this).addClass('hover'); },
    function () { $(this).removeClass('hover'); }
    )*/

    // BOX PRODUTOS
    var timeProd
    $('.produtos li').hover(

        function () {
            clearTimeout(timeProd);
            var _this = $(this);
            timeProd = setTimeout(function () {

                $(_this).animate({ width: 330, opacity: 1 }).find('.btn a').addClass('hover').fadeIn();
                $(_this).siblings().animate({ width: 165, opacity: .3 }).find('.btn a').fadeOut();

                $(_this).children('#p_resumo').children('.texto-mais-resumido').hide();
                $(_this).children('#p_resumo').children('.texto-resumido').show();

                //alert($(_this).prev().children('texto-mais-resumido').attr('ID'));
            }, 200)

        },

        function () {
            clearTimeout(timeProd);

            timeProd = setTimeout(function () {

                $('.produtos li').children('#p_resumo').children('.texto-mais-resumido').show();
                $('.produtos li').children('#p_resumo').children('.texto-resumido').hide();

                $('.produtos li').animate({ width: 220, opacity: 1 }).find('.btn a').removeClass('hover').fadeIn();


            }, 200)
        }

    ).click(function () {
        var dest = $(this).find('.btn a').attr('href');
        location.href = dest;
    })


    // LAYOUT
    $('#menu > ul > li > ul').siblings('a').append('<span class="seta" />');

    $('.produtos .btn a').append('<span />');
    $(".boxSolucoes li:last").addClass("last");


    // ACCORDION
    var bugIE6 = function () {
        if ($.browser.msie && parseInt($.browser.version) == 6) {
            $('#rodape').hide().show();
        }
    }

    $('dl dt a').click(function () {
        var dl = $(this).parents('dl');
        var dt = $(this).parent();
        var dd = $(this).parent().next();

        if ($(dt).hasClass('aberto')) {
            $(dd).slideUp('slow', bugIE6);
            $(dt).removeClass('aberto');
        } else {
            $('dt.aberto', dl).removeClass('aberto').next().slideUp('slow');
            $(dt).addClass('aberto');
            $(dd).slideDown('fast', bugIE6);
        }

    })


    //ANCORA NA MESMA PÁGINA
    $("#conteudoPrincipal dd p a.ancora").click(function () {
        $('.linkAncora a').trigger('click');
    });


    // BOX SOLUÇÕES - HEIGHT
    var solHeight = $('.boxSolucoes li:eq(0)').height();
    $('.boxSolucoes li').each(function () {
        if (solHeight < $(this).height()) {
            solHeight = $(this).height();
        }

        $('.boxSolucoes li').css('height', solHeight + 10);
    });

    // SELECT
    var timeSelect;
    $('.select a.selected')
        .click(function () {
            var _this = $(this);
            var options = $(this).siblings('.options');

            if ($(options).is(':visible')) {
                $(options).slideUp(200);
                $(_this).removeClass('selectAtivo');
                return false;
            }

            $(_this).addClass('selectAtivo');
            $(options).unbind().show()
                .mouseover(function () {
                    clearTimeout(timeSelect);
                    $(options).show();
                    $(_this).addClass('selectAtivo');
                })
                .mouseout(function () {
                    timeSelect = setTimeout(function () {
                        $(options).hide();
                        $(_this).removeClass('selectAtivo');
                    }, 200)
                });
        })

        .mouseout(function () {
            var _this = $(this);
            var options = $(this).siblings('.options');
            timeSelect = setTimeout(function () {
                $(options).hide();
                $(_this).removeClass('selectAtivo');
            }, 200)
        })

        .mouseover(function () {
            clearTimeout(timeSelect)
        })

        .siblings('div.options').find('a').click(function () {
            var obj = $(this).parents('.select');
            var rel = $(this).attr("rel");
            var txt = $(this).text();
            var txtrel = rel + "|" + txt;

            $('.options a', obj).removeClass('ativo')
            $(this).addClass('ativo');
            $('.selected', obj).text(txt);
            $('input:hidden', obj).val(txtrel);
            $('#ctl00_ContentPlaceHolder1_txtSegmento', obj).val(txt);
            $('.options', obj).slideUp(200);
        })

    // VEJA MAIS LINK
    /*currentPage = window.location + '';
    currentPage = currentPage.split('/').pop();
    
    $('.boxVejaMais a[href="' + currentPage + '"]').hide();
    */

  
  
})




//////////////
// No Label //
//////////////
noLabel = {
  init: function () {
    $(".noLabel").each(function () {

      if (Get_Cookie($(this).attr('id')) != null) {
        if (Get_Cookie($(this).attr('id')) == $(this).val()) {
          $(this).addClass('vazio');
          noLabel.buffer[$(this).attr('id')] = $(this).val();
        }
        else {
          noLabel.buffer[$(this).attr('id')] = Get_Cookie($(this).attr('id'));
        }
      }
      else {
        $(this).addClass('vazio');
        noLabel.buffer[$(this).attr('id')] = $(this).val();
        Set_Cookie($(this).attr('id'), $(this).val(), 360, '/', '', '');
      }
      $(this).unbind('focus', noLabel.foco).unbind('blur', noLabel.desfoco).bind('focus', noLabel.foco).bind('blur', noLabel.desfoco);
    }).parents("form:eq(0)").unbind('submit', noLabel.formulario).bind('submit', noLabel.formulario);
  },

  buffer: {},

  foco: function (obj) {

    obj = this;
    if ($(obj).hasClass("vazio")) {
      if ($(obj).is("textarea")) {
        $(obj).html("");
      } else {
        $(obj).val("");
      }
      $(obj).removeClass("vazio");
    }
  },

  desfoco: function () {
    if ($.trim($(this).val()) == "") {
      if ($(this).is("textarea")) {
        $(this).html(noLabel.buffer[$(this).attr("id")]);
      } else {
        $(this).val(noLabel.buffer[$(this).attr("id")]);
      }
      $(this).addClass("vazio");
    }
  },

  formulario: function () {
    $(".vazio", this).each(function () {
      noLabel.foco(this);
    });
    return true;
  }
}


//////////////////
// ScrollPages  //
//////////////////
$.extend({
  scrollPages: {
    defaults: {
      elementSize: 50,
      elements: 3,
      speed: "slow",
      direction: "up"
    }
  }
});
$.fn.extend({
  scrollPages: function (options) {
    options = $.extend({}, $.scrollPages.defaults, options);
    return this.each(function () {

      // Definições de variáveis
      var total = $(".scrollMask li", this).length;
      var mask = options.elementSize * options.elements;
      var area = options.elementSize * total;
      var animation = false;
      var obj = this;
      var dimension = options.direction == "left" ? "width" : "height";
      var side = new Array();
      side[0] = options.direction;
      side[1] = options.direction == "up" ? "down" : "right";

      var linhaCont = 1;

      $(".scrollButtom", this).css("opacity", "1");
      if (options.elements >= total) {
        $(".scrollButtom", this).css("opacity", "1");
        mask = area;
      } else {
        $(".scrollButtom[rel*='" + options.direction + "']", obj).css("opacity", ".3");
      }

      // Aplicação de estilos
      $(".scrollMask", this).css({ "width": mask + "px", overflow: "hidden" }); // Máscara
      $(".scrollMask ul", this).css({ "width": area + "px", marginTop: 0 }); // UL
      $(".scrollMask li", this).css({ "width": options.elementSize + "px" }); // LI
      //$(".scrollMask li", this).css({ "width": options.elementSize + "px", display: "block" }); // LI

      // Função que executa a rolagem
      var rolagem = function (direction) {

        // Variáveis
        var margem = -parseInt($(".scrollMask ul", obj).css("margin-" + (options.direction == "up" ? "top" : "left")));

        var intervalo = direction == side[1]
					? (margem + (mask * 2)) < area
						? mask
						: area - (margem + mask)
					: (margem - mask) < 0
						? margem
						: mask
				;
        direction = direction == side[1]
					? -margem - intervalo
					: -margem + intervalo
				;

        $(".scrollButtom", obj).css("opacity", "1");
        var rel = -direction == 0 ? side[0] : (-direction + mask) == area ? side[1] : null;
        if (rel != null) $(".scrollButtom[rel*='" + rel + "']", obj).css("opacity", ".3");

        // Animação
        animation = true;
        if (options.direction == "up") {
          $(".scrollMask ul", obj).animate({ marginTop: direction + "px" }, options.speed, function () { animation = false; });
        } else {
          $(".scrollMask ul", obj).animate({ marginLeft: direction + "px" }, options.speed, function () { animation = false; }); ;
        }
      }

      // Aplicação de eventos
      $(".scrollButtom", this).unbind("click").click(function () {
        if (!animation) {
          var direction = $(this).attr("rel");
          rolagem(direction);
        }
      });
    });
  }
});

// Rolagem Clientes
function rolagemClientes() {

  var timeLogo, timeRolagem
  var total = $('.rolagemClientes li').length;
  var largura = 132;
  var margem = 0;

  $('.rolagemClientes ul').width(total * largura)

  // Logos
  $('.rolagemClientes li')
  // Ordem aleatoria
    .each(function () {
      eq = Math.random() * total;
      $('.rolagemClientes li:eq(' + parseInt(eq) + ')').appendTo('.rolagemClientes ul');
    })
  // Hover
    .hover(
        function () {
          var _img = $('img', this);
          timeClientes = setTimeout(function () {
            _img.stop().animate({ opacity: 1, width: largura, marginTop: 0 }, 200);
          }, 100);
        },
        function () {
          clearTimeout(timeClientes);
          $('img', this).stop().animate({ opacity: .3, width: 116, marginTop: 4 }, 200);
        }
    ).find('img').css('opacity', '.3').parents('ul').show();


  // Rolagem
  $('.rolagemClientes .scrollButtom').each(function () {

    margem = -1;

    timeRolagem = setInterval(function () {
      $('.rolagemClientes ul').css({
        marginLeft:
                    function (i, val) {
                      valor = parseInt(val) + margem;
                      if (valor == 0) {
                        $('.rolagemClientes ul li:last-child').prependTo('.rolagemClientes ul');
                        valor = -132;
                      } else if (valor <= -132) {
                        $('.rolagemClientes ul li:first-child').appendTo('.rolagemClientes ul');
                        valor = 0;
                      }
                      return valor;
                    }
      })
    }, 40);

  })
    .click(function () {
      margem = $(this).attr('rel') == 'right' ? -1 : 1;
    });


}

//Aceita apenas números
function SoNumeros(event) {
  var tecla;

  tecla = (event.keyCode) ? event.keyCode : event.which;

  var teclaAux = String.fromCharCode(tecla);

  if (!((teclaAux >= 0) && (teclaAux <= 9)) || teclaAux == ' ') {
    if (tecla == 13 || tecla == 8) {
      return true;
    } else {

      if (window.event) {
        window.event.keyCode = 0;

      }
      event.returnValue = false;
      return false;
    }
  }
}


// ------------------------------------- Bloquear TextArea ---------------------- //

function bloquear_textarea(field, maxlength, txtcontador) {

  if (field.value.length > maxlength) {
    field.value = field.value.substring(0, maxlength);

    alert("Quantidade de caracteres acima do permitido!")

  }
  countfieldvalue = maxlength - field.value.length;
  // document.aspnetForm.txtcontador.value = countfieldvalue;

  if (document.getElementById(txtcontador) != null) {
    document.getElementById(txtcontador).value = countfieldvalue;
  }

}

function ValidaContato(oSrc, args) {

  if (args.Value == "Mensagem") {
    args.IsValid = false;
  }

  if (args.Value == "Nome") {
    args.IsValid = false;
  }
}

var posicao = 0;

function setMediaBox() {
  $('#banner').html('<p><span class="tit">' + listaTitulo[posicao] + '</span><br /><span class="desc">' + listaDesc[posicao] + '</span></p>');
  //$('#banner p').css({ 'opacity': '0.65', '-moz-opacity': '0.65', 'filter': 'alpha(opacity=65)' });
  $('#banner p').hide();

  Cufon.replace('#banner p', { fontFamily: 'Fedra Sans Std Book' });

  $('#banner p').css('top', (200 - $('#banner p').height()) / 2);

  $('#banner p').fadeIn('slow');


  if (posicao >= contador - 1) {
    posicao = 0;
  } else {
    posicao++;
  }
}

// supersLeight
jQuery.fn.supersleight = function (settings) {
  settings = jQuery.extend({
    imgs: true,
    backgrounds: true,
    shim: '../_img/blank.gif',
    apply_positioning: true
  }, settings);

  return this.each(function () {
    if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) {
      jQuery(this).find('*').andSelf().each(function (i, obj) {
        var self = jQuery(obj);
        // background pngs
        if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
          var bg = self.css('background-image');
          var src = bg.substring(5, bg.length - 2);
          var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
          var styles = {
            'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
            'background-image': 'url(' + settings.shim + ')'
          };
          self.css(styles);
        };
        // image elements
        if (settings.imgs && (self.is('img[src$=png]') || self.is('input[src$=png][type=image]'))) {
          var styles = {
            'width': self.width() + 'px',
            'height': self.height() + 'px',
            'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
          };
          self.css(styles).attr('src', settings.shim);
        };
        // apply position to 'active' elements
        if (settings.apply_positioning && self.is('a, input') && (self.css('position') === '' || self.css('position') == 'static')) {
          self.css('position', 'relative');
        };
      });
    };
  });
};

