
$(function(){

$('img#popup').hide();
$('div.popup').show('slow', function(){
    $('img#fechar').fadeIn('slow');
    $('div img#popup').fadeIn('slow');
});

$('img#fechar').click(function(){
    $('img#popup').fadeOut('slow');
    $('img#fechar').fadeOut('slow');
    $('div.popup').hide('slow');
});

    setTimeout(function() {
       $('img#popup').fadeOut('slow');
    $('img#fechar').fadeOut('slow');
    $('div.popup').hide('slow');
    }, 18000);
});



$(document).ready(function(){
  /*
  $div = $('#holder');
  _width = $div .width();
  $div .css('left', ($(document).width() - _width) / 2 + 'px');
  $(window).resize(function(){ $div .css('left', ($(document).width() - _width) / 2 + 'px') });
  */
  $("#tab-filosofia").click(function(){
    hideTabs();
    changeImage(this);
    $("#filosofia").css("display", "block");
    return false;
  });
  
  $("#tab-performance").click(function(){
    $('p.textoHistorico').show();
    hideTabs();
    changeImage(this);
    $("#performance").css("display", "block");
    $("#tabela-rentabilidade").css("display","block");
    return false;
  });
  
  $("#tab-como").click(function(){
    $('p.textoHistorico').hide();
    hideTabs();
    changeImage(this);
    $("#como").css("display", "block");
    return false;
  });
  
  $('#menu a img[src*=_on]').addClass('active');

  $('#menu a img:not(.active)').hover(function(){
	  _img = $(this).attr('src').replace('_off', '_on');
	  $(this).attr('src', _img);
	  $('#menu a img.active').attr('src', $('#menu a img.active').attr('src').replace('_on', '_off'));
  },function(){
	  _img = $(this).attr('src').replace('_on', '_off');
	  $(this).attr('src', _img);
	  $('#menu a img.active').attr('src', $('#menu a img.active').attr('src').replace('_off', '_on'));
  });

  $('#menu .miolo').hover(function(){
	  $('#menu a img.active').attr('src', $('#menu a img.active').attr('src').replace('_on', '_off'));
  },function(){
	  $('#menu a img.active').attr('src', $('#menu a img.active').attr('src').replace('_off', '_on'));
  });

  $('.zebra tbody tr:odd').addClass('cinzinha');
});

function culture() { 
  var c = /\/(pt|en|es)/.exec(window.location.pathname);
  return c? c[1] : 'pt';
}

function menu(url){
  if(url == '/index') { 
    window.location = '/' + culture();
  }
  else{
    window.location = '/' + culture() + '/' + url;
  }
}

function changeImage(object){
  imagem = $("img", object);
  newSource = imagem.attr("src").replace(/_[a-z]+\./,"_on.");
  imagem.attr("src", newSource);
}

function hideTabs(){
  //Esconde o Conteúdo
  $(".conteudo-tab").hide();
  $("#tabela-rentabilidade").hide();
  //Muda as imagem para off
  newSource = $("#tab-filosofia img").attr("src").replace(/_[a-z]+\./,"_off.");
  $("#tab-filosofia img").attr("src", newSource);
  
  newSource = $("#tab-performance img").attr("src").replace(/_[a-z]+\./,"_off.");
  $("#tab-performance img").attr("src", newSource);
  
  newSource = $("#tab-como img").attr("src").replace(/_[a-z]+\./,"_off.");
  $("#tab-como img").attr("src", newSource);
  
}

// popup
function janela(url, nome, param) {
  window.open(url, nome, param);
}
