document.ready = function() {
  // events for all pages
  $('#search_submit').live('mouseenter', function() { $('#search_form').show('slow'); } );
  $('.header').live('mouseleave', function() { $('#search_form').hide('slow'); } );
  $('input[type="text"]').one('click', function() { $(this).val(''); } );
  // feels constructive always
  $('img[alt="wReune.Ru"]').live('mouseenter', function() { $('.header .hfright').fadeOut('slow'); });
  $('img[alt="wReune.Ru"]').live('mouseleave', function() { $('.header .hfright').fadeIn('slow'); });
  
  if($('#tags').length > 0) {
    var correction = ($('#tags').parent().height() - $('#tags').height()) / 2;
    $('#tags').css({top: correction + 'px'});
  }
  if($('#forum_top_posts').length > 0) {
    var updateNewPosts = function(html) {
        $('#forum_top_posts_content').html(html);
    }
    var updateForumTop = function() {
      $.get('ajax.html?do=update_forum_top', updateNewPosts);
    }
    $('#update').bind('click', updateForumTop);
  }
  if($('#forum_top_users').length > 0) {
    $('#forum_top_users img').bind('mouseenter', function() { $('#forum_top_users .w_block .w_title').html($(this).attr('alt')); })
    $('#forum_top_users').bind('mouseleave', function() { $('#forum_top_users .w_block .w_title').html('Пользователи') })
  }
};
var is_hide = true;
function MenuSelector(id)
{
  if(is_hide)
  {
	$('#' + id).slideDown('slow');
    is_hide = false
  }
  else
  {
	$('#' + id).slideUp('slow');
    is_hide = true;
  }    
}
function centralizeWindow() {
  if($('#w1').length > 0) {
    $('#w1').css({margin: '-' + $('#w1').height() / 2 + 'px 0 0 -' + $('#w1').width() / 2 + 'px'});
  }
}
function viewmessage(title, content)
{
  $('#ws').html("<div class=\"window\" id=\"w1\" style=\"display: none;\"><div class=\"w_title\">" + title + "<img style=\"float: right; border: 4px solid transparent; cursor: pointer;\" src=\"templates/images/close.gif\" id=\"close\" title=\"Закрыть окно\"/></div><div class=\"w_content\">" + content + "</div></div>");
  $('#w1').fadeIn('slow');
  $('#close').bind('click', function() { $('#w1').fadeOut('slow', function() { $('#ws').html(''); }); });
  centralizeWindow();
}
function viewmessagebuttons(title, content, buttons)
{
  $('#ws').html("<div class=\"window\" id=\"w1\" style=\"display: none;\"><div class=\"w_title\">" + title + "</div><div class=\"w_content\">" + content + "</div><div class=\"w_buttons\">" + buttons + '<input type="submit" class="button" value="Скрыть" id="close"></div></div>');
  $('#w1').fadeIn('slow');
  $('#close').bind('click', function() { $('#w1').fadeOut('slow', function() { $('#ws').html(''); }); });
  centralizeWindow();  
}
document.documentElement.onkeydown = function(e)
{
  if(!e)
  {
    e = window.event;
  }
  if(e.ctrlKey)
  {
    switch(e.keyCode)
    {
      case 0x25: document.location = document.getElementById('back').href; break;
      case 0x27: document.location = document.getElementById('next').href; break;
    }
  }
}
