$(function(){
      var $shade = $('#shade')
        , $magnified = $('#magnified')
      ;

      $shade
	  .click( hide_photo )
	  .css({
		   width: $(window).width(),
		   height: $(window).height()
	       })
      ;
      if( isIE6 ) {
	  $(window).scroll(
	      function () {
		  $shade.css('top', $(window).scrollTop());
	      }
	  );
      }


      $magnified
	  .css({
		   left: parseInt( ($(window).width() - 520) / 2 )
	       })
      ;


      $('ul.photos li a img').each( function () { $(this).click( magnify_photo ); } );

      //
      // [イベントハンドラ] 拡大写真を表示する
      //
      function magnify_photo () {
	  var $img     = $(this)
	    , $title   = $img.parent().prev()
	    , $comment = $img.parent().next()
	  ;

	  var url_img = $img.attr('src').replace(/\.s\.jpg$/, '.l.jpg');

	  var $img_l = $('<img />')
	      .attr('src', url_img)
	      .css({opacity: 1
		   })
	  ;

	  $shade.css('display', 'block');
	  $magnified
	      .add('a.close')
	      .click( hide_photo )
	  ;
	  $magnified
	      //
	      .find('.title')
	      .html($title.html())
	      .end()
	      //
	      .find('.img')
	      .append($img_l)
	      .end()
	      //
	      .find('.comment')
	      .html($comment.html())
	          .end()
	      .css({
		       top: 20 + $(window).scrollTop(),
		       display: 'block'
		   })
	  ;
	  return false;
      }

      //
      // [イベントハンドラ] 拡大写真を隠す
      //
      function hide_photo () {
	  $magnified
	      .find('.title')
	          .empty()
	          .end()
	      .find('.img')
	          .empty()
	          .end()
	      .find('.comment')
	          .empty()
	          .end()
	      .css('display', 'none')
	  ;
	  $shade.css('display', 'none');
	  return false;
      }

});

