var opened = -1;

function show_form(cid, ahr)
{
 var f = document.getElementById('reply_'+cid);
 var f0 = document.getElementById('reply');
 if (!f || !f0)
  return;

 if (opened > -1)
  document.getElementById('reply_'+opened).innerHTML = '';
 opened = cid;

 f.innerHTML = f0.innerHTML;
 //f.getElementsByTag
 f.getElementsByTagName('form')[0].elements['parent'].value = cid;

 f.getElementsByTagName('form')[0].action = f.getElementsByTagName('form')[0].action + '#rt' + cid;
}

function show_replies(cid, ahr)
{
 var f = document.getElementById('replies_'+cid);
 if (!f)
  return;

 var state = f.style.display == 'block';
 f.style.display = state ? 'none' : 'block';
 ahr.getElementsByTagName('span')[0].innerHTML = state ? 'прочитать' : 'скрыть';
}

jQuery.noConflict();

 var fading;
 var loading = 0;

/* jQuery(function(){
  jQuery('.rating').mouseover(function(){
   if (loading) 
    return;
   var ratediv = jQuery(this);//.parent().parent().parent().parent();
   //ratediv.addClass('active');
   jQuery('div', ratediv).fadeIn(1000);
   if (fading)
   {
    clearTimeout(fading);
    fading = '';
   }
  });

  jQuery('.rating').mouseout(function(){
   //alert('out!');
   if (loading) 
    return;
   fading = setTimeout(
    (function(a){
      return function(){
       jQuery('div', a).fadeOut(1000);
      }
     }
    )(this), 1000);
  });
 });*/

 function rate(uid, fid, v)
 {
  jQuery('#r'+fid).prepend(jQuery('.loading.hidden').clone().removeClass('hidden').addClass('active'));

  loading = true;
  jQuery.getJSON(
   '/rate.php',
   {uid: uid, fid: fid, v: v},
   rate_done
  );

 }

 function rate_done(data)
 {
  if (data['error'])
  {
   alert(data['error']);
   return;
  }

  jQuery('.r'+data['uid']+' .ratevalue').html(data['rating']);
  jQuery('.r'+data['uid']+' .rateup').html('+');
  jQuery('.r'+data['uid']+' .ratedown').html('-');
  jQuery('.r'+data['uid']).addClass('inactive');//.unbind('mouseover').unbind('mouseout');
  //jQuery('.r'+data['uid'] + ' a').remove();
  jQuery('.loading.active').remove();

  loading = false;
 }


