/* ---------------------------------------------------------------------------------------- */
/* COMMENTS                                                                                 */
/* ---------------------------------------------------------------------------------------- */

$(document).ready(function() {



  // Comments form --------------------------------------------------------------------------
  $("#comments #commentsform").ajaxForm({resetForm:true, success:function(responseText, statusText) {
  
    // Check if data is present
    if (responseText) {
    
      // Insert returned html
      $("#comments ul").eq(0).prepend(responseText);
      
      // Evaluate target height
      var targetHeight = $("#comments ul li:first").height();
      
      // Init animation
      $("#comments ul li:first").css("overflow", "hidden");
      $("#comments ul li:first").css("height", "0");
      $("#comments ul li:first").hide();
      
      // Execute animation
      $("#comments ul li:first").fadeIn(500);
      $("#comments ul li:first").animate( { height:targetHeight }, { queue:false, duration:250 } );
    
      // Evaluate number of comments
      var numComments = (isNaN(parseInt($("#commentscount").html())))?(0):(parseInt($("#commentscount").html()));
      
      // Adjust number of comments
      $("#commentscount").html(numComments + 1);
    }
  
  }});
  
  
  
  // Comments response ---------------------------------------------------------------------
  $("#comments ul li ul").scale9Grid({ top:5, right:5, bottom:5, left:5 });
  
  
});
