$(function() {
  var handler = $('.informations h2');
  handler.click(function(){
    if($("+ul",this).css("display")=="none"){
        $("+ul",this).slideDown("slow");
    } else {
      $("+ul",this).slideUp("slow");
    }
  });
  
  $('p:has(img)').addClass('image_paragraph');
  
  $('#azash_comment_form form').live('submit', function() {
    var submitButtons = $('input[type=submit]');
    submitButtons.attr('disabled', 'disabled');
    
    $(this).ajaxSubmit({
      dataType: 'xml',
      data: { 'referrer' : document.referrer },
      success: function(data) {
        alert('コメントが投稿されました。');
        location.reload(false);
      },
      error: function(data) {
        alert('コメント投稿に失敗しました。');
        alert(data.responseText);
        submitButtons.removeAttr('disabled');
      }// ,
      //         beforeSend: function(xhr){
      //           xhr.withCredentials = true;
      //         }
    });
    return false;
  });
  
  $.ajax({
    url: window.Rana.comment_api_url + "/comments",
    data: { 'site_id' : '1', 'path' : window.Rana.page_url },
    dataType: 'html',
    // beforeSend: function(xhr){
    //   xhr.withCredentials = true;
    // },
    success: function(html) {
      html = $(html);
      $('#comments').append($('<h2>コメント</h2>'));
      $('#comments').append(html.filter('#azash_comments'));
      $('#comment_form').append(html.filter('#azash_comment_form'));
    },
    error: function() {
      // alert('error');
    }
  });
});
