function tweetBtnDraw(){
	var docSrc = '';
	docSrc += '<div><a href="#tweet!" onclick="doTweet(); return false;">';
	docSrc += '<img src="/img/btn_tweet.gif" alt="この商品についてつぶやく" onmouseover="this.src=\'/img/btn_tweet_on.gif\';" onmouseout="this.src=\'/img/btn_tweet.gif\';" />';
	docSrc += '</a></div>';
	document.write(docSrc);
}

function doTweet() {
	var bitly_id  = 'blossom39';
	var bitly_key = 'R_58638ef4b6fa4d8657fc88eea370f5d8';

	var apiUrl = 'http://api.bit.ly/shorten';
	apiUrl += '?version=2.0.1';
	apiUrl += '&format=json';
	apiUrl += '&callback=tweetCallback';
	apiUrl += '&login=' + bitly_id;
	apiUrl += '&apiKey=' + bitly_key;
	apiUrl += '&longUrl=';
		
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = apiUrl + encodeURIComponent(location.href);
	document.body.appendChild(script);
}


function tweetCallback(json) {
	var d = document;
	var w = window;
	var l = location;
	var e = encodeURIComponent;
	var sel = '';
	if(d.selection) sel = d.selection.createRange().text;
	else if (w.selection) sel = w.selection.createRange().text;
	else if (d.getSelection) sel = d.getSelection();
	else if (w.getSelection) sel = w.getSelection();
	if(sel != '') sel += ' ';

	var f = 'http://twitter.com/home/?status=' + e(sel + d.title + ' ' + json.results[location.href]['shortUrl']);
	if(!w.open(f, 'tweet')) l.href = f;
}

