var cur_post_id = false;
function init_player() {
  width = 860;
  height = 600;
  parameters = "location='/radio/posluchaj',menubar=0,height="+height+",width="+width+",toolbar=0,scrollbars=0,status=0,resizable=1,left="+(screen.width-width)/2+",screenX=" + (screen.width-width)/2 + ",top=" + (screen.height-(height + 110))/2  + ",screenY=" + (screen.height-(height + 110))/2;
  window.open('/radio/posluchaj', 'toksport_player', parameters).focus();
  return false;
}
function comm_show(comm_txt, comm_type) {
  $('#comm').removeClass('alert-error');
  $('#comm').removeClass('alert-ok');
  $('#comm').removeClass('alert-info');
  $('#comm').addClass('alert-' + comm_type);
  $('#comm .intxt').html(comm_txt);
  $('#comm').animate({
         opacity: 1, bottom: 5
      }, 500, "linear", function(){ timeout_info = setTimeout(comm_hide, 3000); } );
}

function comm_hide() {
  $('#comm').animate({
         opacity: 0, bottom: -45
      }, 500, "linear", function(){ timeout_info = setTimeout(comm_hide, 3000); } );
}

function comm_view() {
  if (_Komunikat_Tekst != false && _Komunikat_Typ != false) {
    comm_show(_Komunikat_Tekst, _Komunikat_Typ);
  }
}


function survey_vote(sid, aid) {
  $.post("/sonda/glosuj", { sid: sid, aid: aid  },
    function(data){

      if (data.status == -1) {
      comm_show('Podane parametry nie są prawidłowe', 'error');
      }
      if (data.status == -2) {
      comm_show('Sonda została zakończona.', 'error');
      }
      if (data.status == -3) {
      comm_show('Głos już wcześniej został oddany.', 'error');
      }
      if (data.status == 1) {
      comm_show('Głos został oddany poprawnie.', 'ok');
      }
	  $('#answers'+sid+' .progress .in').css( {width: 0});
      if (data.rezultaty) {

        for (r = 0; r < data.rezultaty.length; r++) {
          $('#answers'+sid+' .normal').removeClass('normal');
          $('#answers'+sid+' .ans' + data.rezultaty[r].id+' .progress .in').animate( { width:data.rezultaty[r].procent + "%"},2000 )
          $('#answers'+sid+' .ans' + data.rezultaty[r].id+' .pr').html('<b>'+data.rezultaty[r].procent+'</b>%');
        }
        $('#answers'+sid+' .nrm').hide();
        $('#answers'+sid+' .hd').show();
      }

    },'json');

  return false;
}

function forum_quote_post(post_id) {
  $('#form-forum-reply #comment').val('[quote]'+$('#p'+post_id+' .cnt').html()+'[/quote]\n');
  $('#form-forum-reply #comment').focus();
  return false;
}

function forum_delete_post(post_id) {
	cur_post_id = post_id;
	$.prompt('Czy napewno chcesz usunąć ten post?<small>Operacja nie będzie odwracalna</small>',{ callback: forum_delete_post_callback, buttons: { Tak: true, Nie: false }, focus: 1 });
	return false;
}

function reload_this() {
	document.location.reload();
}

function forum_delete_post_callback(st) {
	if (st == true) {
		$.post("/forum/usun/" + cur_post_id, {  },
		  function(data){
		    if (data.c == 1) {
				$('#p'+data.id).animate({
				         opacity: 0, height: 0
				      }, 1000, "linear", function(){ $('#p'+data.id).hide(); } );
		    	comm_show('Operacja wykonana poprawnie.', 'ok');
		    	setTimeout(reload_this,2000);
		    }
		    if (data.c == -1) {
		    	comm_show('Brak uprawnień do usunięcia.', 'error');
		    }
		    if (data.c == -2) {
		    	comm_show('Wątek posiada inne posty.', 'error');
		    }
		  },'json');
	}

	cur_post_id = false;
}
