$(document).ready(function(){
    prettyPrint(); // 语法高亮

    /* 侧边栏的收缩 */
    $("#sidebar .item>p").css('cursor', 'pointer');
    $("#sidebar .item>p").click(function(){
        $(this).next().slideToggle('fast');
    });


    /* 更换验证码 */
    var item = $('#vcode');
    var vcodeImg = item.attr('src')+'/?v=';
    item.css('cursor', 'pointer');
    item.attr('title', '点击更换一张新的验证码');
    item.click(function(){
        $(this).attr('src', vcodeImg + Math.random());
        return false;
    });


    /* 为没有输入法的用户提供一个搜狗云输入法。 */
    $('#input-method').css('display','block').text('搜狗云输入法').attr('disabled',false);
    $('#input-method').click(function(){
        (function(){var e=document.createElement('script');e.setAttribute('src','http://web.pinyin.sogou.com/web_ime/init.js');document.body.appendChild(e);})();
    });

    /* 评论回复功能 */
    $('#comments .replay').click(function(){
        var f = $(this).parent().next();
        if(f.find('#respond-form').length > 0)
        {
            $('#respond').append($('#respond-form'));
            $('#respond-form input[name="parent"]').attr('value', 0);
            $(this).text('回复');
        }else
        {
            $(this).parent().next().append($('#respond-form'));
            $('#respond-form input[name="parent"]').attr('value', $(this).attr('id'));
            $(this).text('取消回复');
        }
    });


    /* prettyprint 行号支持。 */
    if(!$.browser.msie)
    {
      var pre = $('.prettyprint');
      pre.each(function(){
          var code = $(this).html().replace(/<br\s*\/*>/ig, '</li><li>');
          code = '<ol><li>'+code+'</li></ol>';
          $(this).html(code);
      });
    }
});

