  var Months = ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"];
	var Calend = [];
	for (i in Months)
		Calend[Months[i]] = 0;
	var shows = 0;
    Calend["Декабрь"] = [[0, "24 декабря", "Сливочный дENь", "Веселые покатушки)", "/GameDetails.aspx?gid=33786"], [2, "31 декабря", "Happy New Year, бл...!", "Фотоохота от Keith", "/GameDetails.aspx?gid=33840"]];
	var h = 174; // Высота шапки в пикселях
  $('#DivTopDesign').css('height', h + 'px');
  function AnonsShow(id, from) {
    $(id).innerHTML = '<br />' + $(from).innerHTML;
        $(id).style.display = '';
    return false;
  }
  
  function AnonsHide(id) {
    $(id).style.display = 'none';
    return false;
  }
  
  function brief(id, text) {
    if ($('#GameDetail_YourTimeArea').length)
      $('#GameDetail_YourTimeArea').prev().prev().after('<tr><td height="18">Брифинг: <span class="white">' + text + '</span></td></tr>');
    else
      $('a[href="/GameDetails.aspx?gid=' + id + '"][id="lnkGameTitle"]').parent().parent().parent().parent().parent().parent().next().next().next().after('<tr id="brief"><td height="18">Брифинг: <span class="white">' + text + '</span></td></tr>');
  }
  
  function fee(id, sum) {
    var expr = /^Времени/i;
    if ($('#GameDetail_YourTimeArea').length && expr.test($('#GameDetail_YourTimeArea').next().next().children().children(':first').html()))
      $('#GameDetail_YourTimeArea').next().next().next().children().children(':first').next().html(sum + ' рублей').next().clone(true).end().remove();
    else if ($('#GameDetail_YourTimeArea').length)
      $('#GameDetail_YourTimeArea').next().next().children().children(':first').next().html(sum + ' рублей').next().clone(true).end().remove();
    else
      $('a[href="/GameDetails.aspx?gid=' + id + '"][id="lnkGameTitle"]').parent().parent().parent().parent().parent().parent().next().next().next().next().next().next().next().next().next().next().next().children().children(':first').next().html(sum + ' рублей').next().clone(true).end().remove();
  }
  
  function priz(id, text) {
    var expr = /^Времени/i;
    //alert(expr.test($('#GameDetail_YourTimeArea').next().next().children().children(':first').html()));
    if ($('#GameDetail_YourTimeArea').length && expr.test($('#GameDetail_YourTimeArea').next().next().children().children(':first').html()))
      $('#GameDetail_YourTimeArea').next().next().next().next().children().children(':first').html('Приз:').next().html(text);
    else if ($('#GameDetail_YourTimeArea').length)
      $('#GameDetail_YourTimeArea').next().next().next().children().children(':first').html('Приз').next().html(text);
    else
      $('a[href="/GameDetails.aspx?gid=' + id + '"][id="lnkGameTitle"]').parent().parent().parent().parent().parent().parent().next().next().next().next().next().next().next().next().next().next().children().children(':last').html(text);
    //alert("ok");
  }
  
  function terr(id, text) {
    if ($('#GameDetail_YourTimeArea').length)
      $('#GameDetail_YourTimeArea').prev().prev().prev().after('<tr><td height="18">Территория: <span class="white">' + text + '</span></td></tr>');
    else
      $('a[href="/GameDetails.aspx?gid=' + id + '"][id="lnkGameTitle"]').parent().parent().parent().parent().parent().parent().next().next().after('<tr><td height="18">Территория: <span class="white">' + text + '</span></td></tr>');
  }
  
  function players(id, text) {
    if ($('#GameDetail_YourTimeArea').length)
      $('#GameDetail_YourTimeArea').prev().prev().prev().prev().prev().children().html('Играем: <span class="white">' + text + '</span>');
    else
      $('a[href="/GameDetails.aspx?gid=' + id + '"][id="lnkGameTitle"]').parent().parent().parent().parent().parent().parent().next().children().html('Играем: <span class="white"><b>' + text + '</b></span>');
  }
  
  function setInfo(game, brieftext, feetext, priztext, terrtext, playtext) {
    brief(game, brieftext);
    fee(game, feetext);
    priz(game, priztext);
    terr(game, terrtext);
    players(game, playtext);
  }  
  
  function divide ( numerator, denominator ) {
    // In JavaScript, dividing integer values yields a floating point result (unlike in Java, C++, C)
    // To find the integer quotient, reduce the numerator by the remainder first, then divide.
    var remainder = numerator % denominator;
    var quotient = ( numerator - remainder ) / denominator;
    
    // Another possible solution: Convert quotient to an integer by truncating toward 0.
    // Thanks to Frans Janssens for pointing out that the floor function is not correct for negative quotients.
    /****************************************************
    if ( quotient >= 0 )
    quotient = Math.floor( quotient );
    else  // negative
    quotient = Math.ceil( quotient );
    *****************************************************/
    return quotient + remainder;
  }
  
  function showCalend(month) {
    if (Calend[month] != 0) {
      $('#Calend').slideUp(100,function(){
        var q = divide(Calend[month].length, 2);
        code = '<table width="100%" border="0" cellpadding="0" cellspacing="20">';
        for (i = 0; i < q; i++) {
          game = Calend[month][i];
          code += '<tr><td valign="top" width="48%"><img src="http://cdn.endata.cx/images/icons/forum/type.' + game[0] + '.gif" hspace="3" width="20" height="20" alt="-" /><font style="font-size: 8pt; font-family: Arial Narrow; color: #ffffff;">' + game[1] + '</font><br />';
              code += (game[4] == "") ? '<strong>' + game[2] + '</strong>' : '<a href="' + game[4] + '"><strong>' + game[2] + '</strong></a>';
          code += '<br />' + game[3] + '</td>';
          if ((i+q) >= Calend[month].length) break;
          game = Calend[month][i+q];
          code += '<td align="right" valign="top" width="48%"><img src="http://cdn.endata.cx/images/icons/forum/type.' + game[0] + '.gif" hspace="3" width="20" height="20" alt="-" /><font style="font-size: 8pt; font-family: Arial Narrow; color: #ffffff;">' + game[1] + '</font><br />';
              code += (game[4] == "") ? '<strong>' + game[2] + '</strong>' : '<a href="' + game[4] + '"><strong>' + game[2] + '</strong></a>';
          code += '<br />' + game[3] + '</td></tr>';
        }
        if (Calend[month].length % 2) code += '<td>&#160;</td></tr>';
        code += '</table>';
        $('#Calend').html(code).slideDown();
      });
    }
    else if (shows = 0) {
      shows = 1;
      var m = jQuery.inArray(month, Months);
      if (m < 11)
        showCalend(Months[m + 1]);
      else
        showCalend(Months[0]);
    }
    return false;
  }
  
  function hideCalend() {
    $('#Calend').slideUp();
    return false;
  }
  
  function getCalend() {
		for (i in Calend)
    	if (Calend[i].length > 0)
				document.write('<a href="#" onclick="return showCalend(\'' + i + '\');">' + i + '</a> | ');
    document.write('<a href="#" onclick="return hideCalend();">Спрятать</a> <br />');
	  document.write('<div id="Calend" style="display: none;"></div>');
  
  	var preloadImg = new Image;
	  for (i = 0; i <= 8; i++)
    	preloadImg.src = 'http://cdn.endata.cx/images/icons/forum/type.' + i + '.gif';
  
	  var d = new Date;
  	showCalend(Months[d.getMonth()]);
	}

