$(function(){
	var url      = "";
    var login   = "hrdsupport";
    var apiKey  = "R_6b887f79fef1eaafcaec05c1053eebf4";
	var longUrl  = location.href;

	var targetUrl = "http://api.bit.ly/shorten?version=2.0.1&longUrl=" + encodeURIComponent(longUrl) + "&login=" + login + "&apiKey=" + apiKey;

    $.ajax({
        type : "GET",
        url : targetUrl,
        dataType : "jsonp",
        success: function(data) {
            if (data.statusCode == "OK") {
                url = 'http://twitter.com/home?status='+encodeURIComponent(document.title+' ' + data.results[longUrl]["shortUrl"]);
            } else {
            	url = 'http://twitter.com/home?status='+encodeURIComponent(document.title+' ' + encodeURIComponent(location.href));
            }
        }
    });

    $(".twitter").click(function(){
        if(url != "") {
            window.open(url, 'twitter');
            return false;
        }
    });
	$(".hatena").click(function(){
        window.open('http://b.hatena.ne.jp/add?mode=confirm&title=' + encodeURIComponent(document.title) + '&url='+encodeURIComponent(location.href), 'hatena');
		return false;
	});
});

