function include_blog(url) {

  $.ajax({

    url      : url, 
    type     : 'GET',
    dataType : 'json',
    timeout  : 5000,
    success  : function( json ) {

      $( "#header-tw-inner" ).html( json[0].text + "<a href='http://twitter.com/obunsha_toefl/status/" + json[0].id + "'>" + relative_time( json[0].created_at ) + "</a>" );

      for( i=0; i<3; i++ ) {

        r = new RegExp("(https?://[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+)", "g");
        var text   = json[i].text.replace( r, '<a href="$1">$1 </a>');

        $( "#twitter-inner ul" ).append(
          $( "<li></li>" ).html( text ).append(
            $( "<a></a>" )
              .attr( "href", "http://twitter.com/obunsha_toefl/status/" + json[i].id )
              .append( $( "<span></span>" ).addClass("time").html( relative_time( json[i].created_at ) )
            )
          )
        )
      }
    },
    error: function() {

      $( "#header-tw-inner" ).html( "ここでつぶやいています。" ).append(
          $( "<a></a>" ).attr( "href", "http://twitter.com/obunsha_toefl/" ).html( "twitter" )
      )
    }
  });
};

function include_twitter(url) {

  $.ajax({

    url  : url,
    type : 'GET',
    dataType: 'json',
    timeout: 5000,
    success: function( json ) {

      for( i=0; i<3; i++ ) {

        var blog_data = {
          title      : json.entries[i].title,
          entry_url  : json.entries[i].link,
          entry_body : json.entries[i].summary,
          entry_time : json.entries[i].issued.replace(/T\d+:\d+:\d+/,"").replace(/-/g,"/")
        }

        // body blog
        $( "#obunsha-blog" ).append(
          $( "<div></div>" ).addClass( "top-article" ).addClass( "clearfix" ).addClass( "blog" + (i+1) ).append(
            $( "<h5></h5>" ).append(
              $( "<span></span>" ).html( "編集部ブログ" )
            )
          )
        )
        $( ".blog" + (i+1) ).append(
          $( "<h4></h4>" ).append(
            $( "<a></a>" ).attr( "href", blog_data.entry_url ).html( blog_data.title ).append( "<br>" ).parent().append(
              "<span class='meta'><span class='update'>" + blog_data.entry_time + "</span> | <a href='http://obunsha-toefl.livedoor.biz/'>編集部ブログ</a></span>"
            )
          )
        )
        $( ".blog" + (i+1) ).append(
          $( "<p></p>" ).html( blog_data.entry_body ).append(
            $( "<a></a>" ).attr( "href", blog_data.entry_url ).html( "つづきを読む" )
          )
        )
      }
    },
    error: function() {
      //何もなし
    }
  });
};


$(function(){

  $('.dialog').dialog({
    autoOpen: false,
    width: 650,
    modal: true,
    buttons: {
      "OK": function() { 
        $(this).dialog("close"); 
      }
    }
  });

  $('.dialog_link').click(function(){
    var index = $(this).attr("id").slice(11);
    $('#dialog' + index).dialog('open');
    return false;
  });

  $('#twitter .dialog_link').hover(
    function() { $(this).addClass('ui-state-hover'); }, 
    function() { $(this).removeClass('ui-state-hover'); }
  );
});



