/* === modules/videos/js/content.js (22.02.2010 18:05:24) === */
function loadcomments(page) {
  $.post('/modules/videos/php/ajax.videos.php', {action:'loadcomments', mediaid: $('input#mediaid').val(), page:page}, function(response) {
    $('div#ajax_comments').html(response);
    $('div#ajax_comments div.pages a').click(switchpage);
    $('table.comment a[rel^=delete]').click(deletecomment);
    $('textarea#comment-message').val('');
    $('div#addcomment').hide();
    $('input#writecomment').show();
    location.hash = '#comments';
  });
}

function postcomment() {
  $.post('/modules/videos/php/ajax.videos.php', {action:'postcomment', mediaid: $('input#mediaid').val(), comment: $('textarea#comment-message').val()}, function(response) {
    loadcomments(1);
  });
  return false;
}

function switchpage() {
  var page = $(this).attr('rel').substr(5);
  loadcomments(page);
  return false;
}

function deletecomment() {
  switch(language) {
    case 'de': question = 'Diesen Kommentar löschen?'; break;
    case 'it': question = 'Rimuovere questo commento?'; break;
    default: question = 'Delete this comment?'; break;
  }
  if (confirm(question)) {
    var page = 1;
    if ($('div#ajax_comments div.pages a.page.active').length) {
      page = $('div#ajax_comments div.pages a.page.active').attr('rel').substr(5);
    }
    $.post('/modules/videos/php/ajax.videos.php', {action:'deletecomment', commentsid: $(this).attr('rel').substr(7)}, function(response) {
      loadcomments(page);
    });
  }
  return false;
}

$(document).ready(function() { 
//if ($.browser.webkit) return true;
  $('input#writecomment').click(function() {
    $('div#addcomment').show();
    $(this).hide();
    location.hash = '#addcomment';
    return false;
  });
  $('table.comment a[rel^=delete]').click(deletecomment);
  $('div#ajax_comments div.pages a').click(switchpage);
  $('input#postcomment').click(postcomment);
  if ($('div.addcomment[id!=addcomment]').length) {
    $('div.addcomment[id!=addcomment]').show();
  }
});
