﻿$(function() {
  var hide  = '/kyouyuu/image/16-16-minus.png';
  var show  = '/kyouyuu/image/16-16-plus.png';
  var processing = '/kyouyuu/image/loading_circle.gif';
  (new Image()).src = hide;
  (new Image()).src = show;
  (new Image()).src = processing;

  // get source code text file
  var source = $('#source_code');
  if ( $(source).length > 0 ) {
    var loading = $(
      "<div><img src='" + processing + "' alt='loading' /></div>"
    );
    $(source).prepend($(loading));
    $.ajax({
      cache:false,type:'GET',timeout:8000,
      url:$(source).children('a:first').attr('href'),
      success: function(text) {
        $(source).html('<pre>' 
          + text.replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
          + '</pre>'
        );
      },
      error: function(XMLHttpRequest, textStatus, errorThrown) {
        $(loading).remove();
      }
    });  
  }

  var hide_img = "<img class='show-hide' src='/kyouyuu/image/16-16-minus.png' style='padding-right:4px;vertical-align:top;' title='show/hide' />";
  $('h3.js-show-hide').each(function(){
    $(this).prepend(hide_img);
  });

  $('img.show-hide').live('click', function() {
    var list_no = '#listing-' + $(this).next('a').attr('name').substring(2);
    var n = $(list_no);
    // var n = $(this).find('ul');
    if ( $(n).is(':visible') ) {
      $(n).hide();
      $(this).attr('src', show);
    }
    else {
      $(n).show();
      $(this).attr('src', hide);
    }
  });

});  

