mousepop = function(poptype, data, pt) {
  var div = $('<div class=mousepop id=' + poptype + '>'+data+'</div>');
  div.bind('mouseleave', function() { $(this).remove(); });
  switch (poptype) {
    case 'abbr-popup': {
      div.html(data);
      $('body').prepend(div);
      myl = pt.x-20;
      myt = pt.y-20;
      div.css( { left: myl+'px', top: myt+'px' } ).show();
      return div;
    } break;
    case 'cats-navigator': {
      div.html(data);
      $('body').prepend(div);
      myt = pt.y-20;
      div.css( { left: 'auto', right: '8px', top: myt+'px' } ).show();
      return div;
    } break;
    default: {
      div.html(data);
      $('body').prepend(div);
      myt = pt.y-20;
      div.css( { left: 'auto', right: 0, top: myt+'px' } ).show();
      return div;
    } break;
  }
}
$(function() { //on DOM ready
  $('abbr').click(function() { window.location.href = "/profile.php?mode=viewprofile&u="+this.innerHTML; });
/*  $('abbr').bind('mouseleave', function() {
    $(this).unbind('mousemove');
    if (window['abbr_popup_timeout']) clearTimeout(window['abbr_popup_timeout']);
  });
  $('abbr').mouseover(function(event) {
    abbrname=this.innerHTML;
    pgX = event.pageX; pgY = event.pageY;
    $(this).mousemove(function(event) {
      pgX = event.pageX; pgY = event.pageY;
    });
    if (window['abbr_popup_timeout']) clearTimeout(window['abbr_popup_timeout']);
    window['abbr_popup_timeout'] = setTimeout(function() {
      var pop = mousepop('abbr-popup', '<a href="/profile.php?mode=viewprofile&u='+abbrname+'"><img src="/images/spinner.gif" /></a>', { x: pgX, y: pgY });
      $.post('/aja.php', { command: 'abbr-popup', name: abbrname }, function(data) {
        pop.html(data);
      });
    }, 1000);
  });*/

	$("textarea.autogrow").keyup( function()
	{
		storeCaret(this);
		var rowcount = $(this).val().split("\n").length;
		var rowhe = parseInt($(this).css('fontSize')) + 3;
		 /*if ( ( $(this).height() < (rowhe*rowcount) ) && ($("input#disablegrowing").attr('checked')) )
		 {
		   $(this).height(rowhe*rowcount + 50);
		 }
		 else if ( $(this).height() > (rowhe*rowcount)  )
		 {
		    $(this).height(rowhe*rowcount+20);
		 }*/
		 if ( ($("input#disablegrowing").attr('checked')) )
		 {
		   $(this).height(rowhe*rowcount + 30);
		 }
		 
		 
	});
	
	$("input.votestar").mouseover( function()
	{
		var th = $(this);
		var ind = parseInt(th.attr("rv"));
		var thind = 0;
		/*$(this).css("color","red");*/
		
		th.parent().find("input.votestar").each( function ()
		{
		  thind = parseInt($(this).attr("rv"));
		  if (thind <= ind)
		  {
			  $(this).css("color","red");
		  }
		});
	});
	
	$("input.votestar").mouseout( function()
	{
	  var th = $(this);
	  th.parent().find("input.votestar").css("color","black");
	});
	
	
	$("span.newspoiler_title").click( function() 
	{
		var th = $(this);
		var spbody = th.parent().find("div.newspoiler_data");
		if (spbody.css("display") != "block")
		{
		  spbody.css("display","block");
		}
		else
		{
		  spbody.css("display","none");
		}
	});


    // highlight torrent's row and link for dl
    $('.torrentsList .row_line').hover(function() {
        $(this).children('td').addClass('overTorrent');
        $(this).find('.torrentLink').addClass('overTorrentLink');
    }).mouseleave(function() {
        $(this).children('td').removeClass('overTorrent');
        $(this).find('.torrentLink').removeClass('overTorrentLink');
    });

});

