$(function () {
  var taglength = $("#tag_cloud a").length;
  var clrArr = ["#FFFFFF", "#E4E3D3", "#49637A"];
  for (var i = 0; i < taglength; i++) {
    $('#tag_cloud .tag-link-' + (Math.random() * taglength * 2 >> 0)).css("color", clrArr[(Math.random() * clrArr.length) >> 0]);
  }

  $('#link-recent').live("click", function () {
    $('#block-recent').show(300);
    $('#block-comments').hide(300);
  });

  $('#link-comments').live("click", function () {
    $('#block-comments').show(300);
    $('#block-recent').hide(300);
  });

  $("#sidebar span.sidebarIcons img").hover(

  function () {
    $(this).fadeTo(170, 0.7)
  }, function () {
    $(this).fadeTo(170, 1)
  });

  $("#content div.readmore").each(function () {
    var $link = $("a", this).first();
    var $title = $("h2 a", $(this).closest("div.post")).first();
    $(this).click(function () {
      window.location.href = $link.attr("href");
    }).css("cursor", "pointer");
    $(this).attr("title", "Read more: " + $title.text());
    $(this).hover(

    function () {
      $(this).animate({
        paddingLeft: "13px"
      }, 200)
    }, function () {
      $(this).animate({
        paddingLeft: "10px"
      }, 200)
    });
  });

  $("#content div.post img.alignleft").each(function () {
    var $title = $("h2 a", $(this).closest("div.post")).first();
    if ($title.length > 0) {
      $(this).click(function (e) {
        window.location.href = $title.attr("href");
      }).css("cursor", "pointer").attr("title", "Read more: " + $title.text()).hover(

      function () {
        $(this).fadeTo(170, 0.8)
      }, function () {
        $(this).fadeTo(170, 1)
      });
    }
  });

  $("#sidein li").live("click", function () {
    window.location.href = $("a", this).attr("href");
  }).css("cursor", "pointer")

   $.ajax({
            url: 'http://api.twitter.com/1/statuses/user_timeline.json/',
            type: 'GET',
            dataType: 'jsonp',
            data: {
                screen_name: "mknol",
                include_rts: true,
                count: 3,
                include_entities: true
            },
            success: function(data, textStatus, xhr) {
 
                 var html = '<li class="tweet"><a href="http://www.twitter.com/USER" class="usrname">@USER</a>: TWEET_TEXT <small class="date"><a href="http://twitter.com/USER/status/ID/">AGO</a></small></li>';
         
                 // append tweets into page
                 for (var i = 0; i < data.length; i++) {
                    $("#tweets").append(
                        html.replace('TWEET_TEXT', ify.clean(data[i].text) )
                            .replace(/USER/g, data[i].user.screen_name)
                            .replace('AGO', data[i].created_at.toString().split("+")[0])
                            .replace(/ID/g, data[i].id_str)
                    );
                 }                 
            }  
 
        });
 var ify = {
      link: function(tweet) {
        return tweet.replace(/\b(((https*\:\/\/)|www\.)[^\"\']+?)(([!?,.\)]+)?(\s|$))/g, function(link, m1, m2, m3, m4) {
          var http = m2.match(/w/) ? 'http://' : '';
          return '<a class="twtr-hyperlink" target="_blank" href="' + http + m1 + '">' + ((m1.length > 25) ? m1.substr(0, 24) + '...' : m1) + '</a>' + m4;
        });
      },
 
      at: function(tweet) {
        return tweet.replace(/\B[@＠]([a-zA-Z0-9_]{1,20})/g, function(m, username) {
          return '<a target="_blank" class="twtr-atreply" href="http://twitter.com/intent/user?screen_name=' + username + '">@' + username + '</a>';
        });
      },
 
      list: function(tweet) {
        return tweet.replace(/\B[@＠]([a-zA-Z0-9_]{1,20}\/\w+)/g, function(m, userlist) {
          return '<a target="_blank" class="twtr-atreply" href="http://twitter.com/' + userlist + '">@' + userlist + '</a>';
        });
      },
 
      hash: function(tweet) {
        return tweet.replace(/(^|\s+)#(\w+)/gi, function(m, before, hash) {
          return before + '<a target="_blank" class="twtr-hashtag" href="http://twitter.com/search?q=%23' + hash + '">#' + hash + '</a>';
        });
      },
 
      clean: function(tweet) {
        return this.hash(this.at(this.list(this.link(tweet))));
      }
    } 


});

Cufon.replace('#menu span', {fontFamily: 'minBold', hover: true});
