var currentRate = <?=intval($rate)?>;
var currentPreview = 0;

function overRate(value) {
  showRate(currentRate,value);
}

function showRate(value,preview) {
  if ((preview>0) && (currentPreview==preview)) return;
  currentPreview = preview;
  html = "";
  result = "";
  for (i=1; i<=5; i++) {
    html = 'onMouseOver="javascript:overRate('+i+');" onClick="javascript:changeRate('+i+');" style="cursor:pointer"';
	  if (preview>0) {
      if (i<=preview) result = result+'<img src="/img/starOk.gif" '+html+" />";
	    else
	    if (i<=currentRate) result = result+'<img src="/img/starOk.gif" '+html+" />";
	                 else result = result+'<img src="/img/starNok.gif" '+html+" />";
    } else {
	  if (i<=value) result = result+'<img src="/img/starOk.gif" '+html+" />";
	           else result = result+'<img src="/img/starNok.gif" '+html+" />";
	  }
  }
  if (preview>0) toShow=preview; else toShow=value;
  switch(toShow) {
    case 0 : name = "<font color='#777777'>Notez ce truc</font>"; break;
	  case 1 : name = "Inutile"; break;
	  case 2 : name = "Pas terrible"; break;
	  case 3 : name = "Pas mal"; break;
	  case 4 : name = "Int&eacute;ressant"; break;
	  case 5 : name = "G&eacute;nial"; break;
  }
  $("#rateZone").html(result);
  $("#rateName").html(name);
}

function changeRate(value) {
  currentRate=value;
  currentPreview=0;
  showRate(value,0);
  $("#rate").val(value);
}

function warningTip(_idTip,_idUser) {
  $.get("<?=$_SERVER['PHP_SELF']?>",{ action:"warningTip",idTip:_idTip,idUser:_idUser },function(returnValue) {
	  if (returnValue=='OK') alert("Votre alerte a bien été prise en compte.\nMerci de votre contribution.");
		if (returnValue=='ALREADY') alert("Vous nous avez déjà alerté sur ce truc.");
	});
}

function warningComment(_idComment,_idUser) {
  $.get("<?=$_SERVER['PHP_SELF']?>",{ action:"warningComment",idComment:_idComment,idUser:_idUser },function(returnValue) {
	  if (returnValue=='OK') alert("Votre alerte a bien été prise en compte.\nMerci de votre contribution.");
		if (returnValue=='ALREADY') alert("Vous nous avez déjà alerté sur ce commentaire.");
	});
}

function showBookmark(_object) {
  var coords = findPos(_object);
	var x = coords[0]+2;
	var y = coords[1]+_object.offsetHeight+2;
  $("#bookmarkBox").css('left',x+'px');
	$("#bookmarkBox").css('top',y+'px');
	$("#bookmarkBox").show('fast');
}

function bookmarkClose() {
  $("#bookmarkBox").hide('fast');
}
