/** bit.ly API **/
BitlyCB.shortenResponse = function(data) {
	var s = ''; 
	var first_result; 
	// Results are keyed by longUrl, so we need to grab the first one. 
	for ( var r in data.results ) {
		first_result = data.results[r]; break; 
	} 
	
	for (var key in first_result) { 
		// s += key + ":" + first_result[key].toString() + "\n"; 
		if ( key == 'shortUrl')
			s = first_result[key].toString();
	} 
	document.getElementById('sUrl').value = s;
}


function funShortUrl( type, sURL ) {
	document.getElementById('sType').value = type;
	BitlyClient.shorten(sURL, 'BitlyCB.shortenResponse');
	
	setTimeout("funReturnShare()", 500);
}


function funReturnShare() {
	surl 	= document.getElementById('sUrl').value;
	type 	= document.getElementById('sType').value;
	title = document.getElementById('sTitle').value;

	if( (typeof surl != "undefined") && surl != "") {
		switch(type) {
			
			case 'me2day': 
				var tag = 'ºí·ÎÅÍ´å³Ý ´º½º½ºÅ©·¦';
				var link = 'http://me2day.net/posts/new?new_post[body]="' + title + '":' + surl + '&new_post[tags]=' + encodeURIComponent(tag) ;
				popwin = window.open(link,'popwin', 'menubar=yes,toolbar=yes,status=yes,resizable=yes,location=yes,scrollbars=yes');
				
				if(popwin)
					popwin.focus();
			break;
			
			case 'twitter': 
				var link = 'http://twitter.com/home?status=' + title + ':' + surl ;
				//popwin = window.open(link,'popwin');
				popwin = window.open(link,'popwin', 'menubar=yes,toolbar=yes,status=yes,resizable=yes,location=yes,scrollbars=yes');
				
				if(popwin)
					popwin.focus();
				break;
			
			default:
				break;
		}
		return;
	} else { }
}
