$('document').ready(function(){
  var browser = $.browser;
  if((browser.msie && browser.version.slice(0,3) == "6.0") || (browser.msie && browser.version.slice(0,3) == "7.0")){
    $.fx.off = true;
  }

  var bodyClass = $('body').attr("class");
  $('body').append('<div class="background '+bodyClass+'"></div>');

  $('.logo .hover').css({
    "opacity":0
  });

  $('.morph').each(function(){
    var $this = $(this);
    var color = $this.css('color');
    $this.mouseover(function(){
      if($this.is(".morph")){
        $this.stop().animate({
          color:"#000"
        },500);
      }
    });
    $this.mouseout(function(){
      if($this.is(".morph")){
        $this.stop().animate({
          color:"#"+color
        },500);
      }
    });
  });

  $('.linkAbsoluto').each(function(linkIndice){
    var $this = $(this);

    var color = new Array();
    $this.parent().find(".morph").each(function(itemIndice){
      color[itemIndice] = $(this).css('color');
    });

    $this.mouseover(function(){
      $this.parent().find(".morph").each(function(itemIndice){

        $(this).stop().animate({
          color:"#000"
        },500);

      });
    });

    $this.mouseout(function(){
      $this.parent().find(".morph").each(function(itemIndice){

        $(this).stop().animate({
          color:"#"+color[itemIndice]
        },500);

      });
    });
  });

  $('.hover').each(function(){
    var $this = $(this);
    $this.mouseover(function(){
      $this.stop().animate({
        opacity:0.5
      });
    });
    $this.mouseout(function(){
      $this.stop().animate({
        opacity:0
      });
    });
  });

  $('#news_itens img').live('mouseover',function(){
    $(this).stop().animate({
      opacity:0.3
    });
  });
  $('#news_itens img').live('mouseout',function(){
    $(this).stop().animate({
      opacity:1
    });
  });

  var indiceTotal = $('#img_slider > figure').length;
  var imgSize = indiceTotal*960;
  $('#img_slider').width(imgSize);

  var swimexIndice = 0;
  var imagesLength = $("#img_slider figure").length;
  $('.seta').click(function(){
    var $this = $(this);

    if($this.hasClass('esq')){
      swimexIndice--;
    } else {
      swimexIndice++;
    }

    if(swimexIndice < 0){
      swimexIndice = 0;
      return false;
    }
    if(swimexIndice == imagesLength){
      swimexIndice = imagesLength-1;
      return false;
    }

    var leftValor = swimexIndice * -960;
    $('#img_slider').animate({
      left:leftValor
    },250);
  });

  $('#lista_modalidades > li').each(function(){
    var $this = $(this);
    var link = $('> a', this);
    var color = $(link).css('color');
    var tamanho = $this.height();
    $this.height(45);
    $(link).click(function(){
      var newsMenu = $this;
      if($(newsMenu).height() == 45){
        $(newsMenu).stop().animate({
          height:tamanho
        },200,function(){
          $(link).removeClass("morph").stop().animate({
            "color":"#000"
          },250);
        });
      }else if($(newsMenu).height() > 45){
        $(newsMenu).stop().animate({
          height:45
        },200,function(){
          $(link).addClass("morph").stop().animate({
            "color":color
          },250);
        });
      }
    });
  });

  $('#swimex_info .esquerda .seta .hover').css({
    "opacity":0
  });

/*
  $('#calendario .horario ul').each(function(){
    var $this = $(this);
    $this.parent().height($this.height());
    if(!$this.parent().is(".mesmo")){
      $this.parent().css({
        "padding-bottom":"15px"
      });
    }else{
      $this.parent().css({
        "padding-bottom":"15px"
      });
      $this.parent().prev().css({
        "padding-bottom":"0"
      });
    }
  });
*/

//  var horariosHeight = $('#calendario .lista_horarios').height();
//  $('#calendario .dia').each(function(){
//    $(this).height(horariosHeight);
//  });

  // abre e fecha o menu principal
  $("#topo .submenu").height(0);
  $("#topo").each(function(){

    var $this = $(this);
    var submenu = $("> .submenu", $this);

    $($this).mouseenter(function(){
      if($(submenu).height() < 320){
        $(submenu).stop().animate({
          height:320
        },200);
      }
    });

    $($this).mouseleave(function(){
      if($(submenu).height() > 0){
        $(submenu).stop().animate({
          height:0
        },200);
      }
    });
  }); // *** fim

  // abre e fecha o menu de news
  $("#news_menu").each(function(){
    var $this = $(this);

    $($this).mouseenter(function(){
      if($this.height() < 320){
        $this.stop().animate({
          height:320
        },500);
      }
    });

    $($this).mouseleave(function(){
      if($this.height() > 0){
        $this.stop().animate({
          height:80
        },500);
      }
    });
  }); // *** fim

  // intercala a opacidade dos ítens do menu principal
  $('#topo .menu menu li, #topo .submenu section').each(function(){
    var $this = $(this);
    var classe = $this.attr('class');
    var correspondente;
    var todos;
    var todos_correspondentes;

    if($this.is('li')){
      correspondente = "#topo .submenu ."+classe;
      todos = "#topo .menu menu li";
      todos_correspondentes = "#topo .submenu section";
    }else if($this.is('section')){
      correspondente = "#topo .menu menu ."+classe;
      todos = "#topo .submenu section";
      todos_correspondentes = "#topo .menu menu li";
    }

    $this.mouseenter(function(){
      $(todos).stop().animate({"opacity":0.8},500);
      $(todos_correspondentes).stop().animate({"opacity":0.8},500);

      $this.stop().animate({"opacity":1},500);
      $(correspondente).stop().animate({"opacity":1},500);
    });

    $this.mouseleave(function(){
      $(todos).stop().animate({"opacity":1},500);
      $(todos_correspondentes).stop().animate({"opacity":1},500);
    });
  }); // *** fim
});
function novidades(){
  $('div.item').animate({"opacity":0.8},500);

  $("div.item").hover(
    function () {
      $(this).stop().animate({"opacity":1},500);
    },
    function () {
      $(this).stop().animate({"opacity":0.8},500);
    }
  );
};
