$(function(){
  
  //map open/close
  $('div.single-event a.map-link','#content').click(function(){
    $(this).toggleClass('opened');
    $('div.map').toggle();
    $(this).find('var').toggle();

    map.checkResize();
    map.disableScrollWheelZoom();
    map.setCenter(new GLatLng($('div.gmap').attr('latitude'), $('div.gmap').attr('longitude')), 16);
    
    return false;
  });

  //over events expand/collapse
  $('div.over-events p > a','#content').click(function(){
    $(this).parent().siblings('div.over-wrap').toggleClass('opened');
    return false;
  });

  $('div.authors h4 > a','#content').click(authorsToggle);

  //пойду / не пойду на мероприятие
  $('.wrapper_header a.go','#content').live('click',function(){
    $.getJSON(this.href, {}, function(data){
      var go = data.go;
      var id = data.id;
      var willgo = data.willgo;

      if (go) {
        if (typeof(willgo_list[id]) != 'undefined') {
          var item = '<a id="togo' + id + '" href="' + data.link + '"><img src="' + willgo_list[id] + '" alt="" /><span></span></a>';
          $('div.to-go h4','#fixed-nav').after(item);
        }
      }
      else {
        $('#togo' + id).remove();
      }

      $('div.to-go h4 span','#fixed-nav').text(makeCounterText(willgo.length));
    });

    if ($(this).hasClass('no')) {
      if (SF_CULTURE == 'ru') $(this).html('<span>пойду</span>');
      else $(this).html('<span>i\'m going</span>');
      $(this).attr('href', this.href.replace(/\?.+/, '?no=1'));
    }
    else {
      if (SF_CULTURE == 'ru') $(this).html('<span>пойти</span>');
      else $(this).html("<span>go</span>");
      $(this).attr('href', this.href.replace(/\?.+/, '?go=1'));
    }
    $(this).toggleClass('no');

    return false;
  });

  //initialize map for event (maps.js)
  initEMap();

});
