$(document).ready(function(){
  
  // last menu item
  //$('li').last().css('background-color', 'red');

  $('#menu li').last().css("background", "none");
  $("#products-slider").productSlider();
  
  intensityDown = function(){
    $(".points").stop(true, true).animate({opacity: 0.5}, 'fast');
  };
  
  intensityUp = function(){
    $(".points").stop(true, true).animate({opacity: 1.0}, 'fast');
  };
  
  showDetail = function(id){
    $("#map_" + id).stop(true, true).fadeIn();
    $("#cbox_" + id).stop(true, true).fadeIn();
  };
  
  hideDetail = function(id){
    $("#map_" + id).stop(true, true).fadeOut();
    $("#cbox_" + id).stop(true, true).fadeOut(); 
  };
  
  $(".map a").bind({
    mouseenter: function(){
      intensityDown();
      showDetail(this.id);
    },
    mouseleave: function(){
      intensityUp();
      hideDetail(this.id);
    }
  });
  
  showDetailFromMenu = function(id){
    intensityDown();
    $("#map" + id).stop(true, true).fadeIn('slow');
    $("#cbox" + id).stop(true, true).fadeIn();
  };
  
  hideDetailFromMenu = function(id){
    $("#map" + id).stop(true, true).fadeOut('slow');
    $("#cbox" + id).stop(true, true).fadeOut(); 
    intensityUp(); 
  };
  
  $("#select-country a").hover(function(){
    showDetailFromMenu(this.id);
  },
    function(){
      hideDetailFromMenu(this.id);
    }
  );
  
  // contact places selection
  
  //$("#place-show").css({'height':'160px', 'overflow':'hidden'});
  
  $(".place").css("display", "none");
  $(".place:first-child").slideDown();
  $(".place:first-child").addClass('active');
  
  // maps under coutries list
  $("#countries-maps img").css("display", "none");
  $("#countries-maps img:first-child").slideDown();
  $("#countries-maps img:first-child").addClass('active');
  
  $("#select-country-contact a").click(function(){

    if($("#place" + this.id).css("display") == "none"){
      $(".place.active").stop(true, true).slideUp();
      $(".place.active").removeClass('active');
      
      $("#place" + this.id).addClass('active');
      $("#place" + this.id).stop(true, true).slideDown();
    }
    
    // maps under coutries list
    if($("#map" + this.id).css("display") == "none"){
      $(".leftmap.active").stop(true, true).slideUp();
      $(".leftmap.active").removeClass('active');
      
      $("#map" + this.id).addClass('active');
      $("#map" + this.id).stop(true, true).slideDown();
    }
    
    return false;   
  });
                     
  //////////////////////////////////////////////////////////////////////////////
  // peoples selection
  
  /*list = $(".people-group");
  listCount = list.length;
  
  if(listCount){  
    ps = "#people-selector";
    $(list).not(list[0]).css("display", "none");
    
    $(ps).append("<select></select>");
    
    $(ps + " select").change(function(){
      $(list).fadeOut();
      $("#" + this.value).fadeIn();
    });
    
    for(i = 0; i < listCount; i++){
      $(ps + ' select').append("<option value='" + list[i].id +"'>" + $("#" + list[i].id + " h3").text() + "</option>");  
    }    
  }*/  
  
  // peoples biggest photos
  $(".photo").hover(function(){
    
    $(this).children(".big-photo").css({top: '150px'});
    
    x = $(this).position();
    
    //alert(x.left);
    
    $(this).children(".big-photo").css('left', (x.left - 30) + 'px');
    $(this).children(".big-photo").css('top', (x.top - 30) + 'px');
    
    $(this).children(".big-photo").stop(true, true).fadeIn('fast'); 
    
  }, function(){
    $(this).children(".big-photo").stop(true, true).fadeOut('fast');
  });
  
  //////////////////////////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////
  
  
  //////////////////////////////////////////////////////////////////////////////
  // awards
             
  /*$(".award .cat-name").hover(function(){
  
    $(this).find('img.award-product').stop(true, true).fadeIn('fast');

  },function(){
  
    $(this).find('img.award-product').stop(true, true).fadeOut('fast');  
  
  });*/
  
  $(".award .position").hover(function(){
  
      var id = this.id;
      var prefix = "#img_";
      
      $( prefix + id ).stop(true, true).fadeIn('fast');
  
    }, function(){
    
      var id = this.id;
      var prefix = "#img_";
    
      $( prefix + id ).stop(true, true).fadeOut('fast');
    }
  );
  
  $(".award .cat-name").click( function(){
  
    return false;
  
  } );
  
  //////////////////////////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////
  
  // animation references
  $("#references-list").dynamicbillboard();
   
  
});
