
var main_area = 628;

function setMediaPlayer (source, width, height) {
	
	var scale = main_area / width;
	var video_width = main_area;
	var video_height = Math.round(height * scale) + 44;
	
	var player_file = "/jp/images/mediaplayer.swf";
	var skin_file = "/jp/images/SkinUnderPlayStopSeekFullVol.swf";
	var flash_vars = "skin_file=" + skin_file + "&source_file=" + source + "&url=" + location.href;
	
	var swfobject = "";
	swfobject += '<object width="' + video_width + '" height="' + video_height + '">';
	swfobject += '<param name="movie" value="' + player_file + '"></param>';
	swfobject += '<param name="allowFullScreen" value="true"></param>';
	swfobject += '<param name="allowScriptAccess" value="always"></param>';
	swfobject += '<param name="FlashVars" value="' + flash_vars + '" />';
	swfobject += '<embed src="' + player_file + '" type="application/x-shockwave-flash" allowScriptAccess="always" allowFullScreen="true" flashVars="' + flash_vars + '" width="' + video_width + '" height="' + video_height + '"></embed>';
	swfobject += '</object>';
	document.write(swfobject);
}

function setSocialLinks (url, title) {
	
	document.write('<div id="social"></div>');
	var social = document.getElementById('social');
	var head = document.getElementsByTagName("head")[0] || document.documentElement;
	
	var login = 'francfranc';
	var apiKey = 'R_469973867742805109b34f4652bb6e36';
	var bitly_url = 'http://api.bit.ly/shorten?version=2.0.1&format=json&callback=bitlyCallback&login=' + login + '&apiKey=' + apiKey + '&longUrl=' + encodeURIComponent(url);
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = bitly_url;
	social.appendChild(script);
	
	this.bitlyCallback = function (json) {
		
		var short_url = encodeURIComponent(json.results[url]['shortUrl']);
		var anchor;
		var icon;
		var count;
		var text;
		var script;
		
		//Title
		var lead = document.createElement('strong');
		text = document.createTextNode("この記事をシェアする");
		lead.appendChild(text);
		text = document.createTextNode("  ");
		lead.appendChild(text);
		social.appendChild(lead);
		
		//Twitter
		anchor = document.createElement('a');
		anchor.className  = 'twitter';
		anchor.rel = 'nofollow';
		anchor.href = 'http://twitter.com/home/?status=' + title + ' ' + short_url;
		anchor.target = '_blank';
		anchor.title = 'この記事をTwitterでつぶやく';
		icon = document.createElement('img');
		icon.src = '/jp/images/icon_twitter.gif';
		icon.alt = 'Twitter';
		icon.width = 16;
		icon.height = 16;
		text = document.createTextNode(" ");
		anchor.appendChild(icon);
		social.appendChild(anchor);
		social.appendChild(text);
		
		//Topsy
		anchor = document.createElement('a');
		anchor.id = 'tweet_count';
		anchor.rel = 'nofollow';
		anchor.href = 'http://topsy.com/tb/' + escape(url.replace('http://', ''));
		anchor.target = '_blank';
		text = document.createTextNode(" ");
		social.appendChild(anchor);
		social.appendChild(text);
		
		script = document.createElement("script");
		script.src = 'http://otter.topsy.com/trackbacks.js?callback=topsyCallback&url=' + encodeURIComponent(url);
		script.charSet = "utf-8";
		head.appendChild(script);
		
		//Hatena Bookmark
		anchor = document.createElement('a');
		anchor.className = 'hatenabookmark';
		anchor.rel = 'nofollow';
		anchor.href = 'http://b.hatena.ne.jp/entry/' + url;
		anchor.target = '_blank';
		anchor.title = 'この記事をはてなブックマークでシェア';
		icon = document.createElement('img');
		icon.src = '/jp/images/icon_hatenabookmark.gif';
		icon.alt = 'はてなブックマーク';
		icon.width = 16;
		icon.height = 16;
		count = document.createElement('img');
		count.src = 'http://b.hatena.ne.jp/entry/image/' + url;
		text = document.createTextNode(" ");
		anchor.appendChild(icon);
		anchor.appendChild(count);
		social.appendChild(anchor);
		social.appendChild(text);
		
		//livedoor clip
		anchor = document.createElement('a');
		anchor.className = 'livedoorclip';
		anchor.rel = 'nofollow';
		anchor.href = 'http://clip.livedoor.com/page/' + url;
		anchor.target = '_blank';
		anchor.title = 'この記事をlivedoorクリップでシェア';
		icon = document.createElement('img');
		icon.src = '/jp/images/icon_livedoorclip.gif';
		icon.alt = 'livedoorクリップ';
		icon.width = 16;
		icon.height = 16;
		count = document.createElement('img');
		count.src = 'http://image.clip.livedoor.com/counter/small/' + url;
		text = document.createTextNode(" ");
		anchor.appendChild(icon);
		anchor.appendChild(count);
		social.appendChild(anchor);
		social.appendChild(text);
		
		//Yahoo! Bookmark
		anchor = document.createElement('a');
		anchor.className = 'yahoobookmark';
		anchor.rel = 'nofollow';
		anchor.href = 'http://bookmarks.yahoo.co.jp/url/' + url;
		anchor.target = '_blank';
		anchor.title = 'この記事をYahoo!ブックマークに登録';
		icon = document.createElement('img');
		icon.src = '/jp/images/icon_yahoobookmark.gif';
		icon.alt = 'Yahoo!ブックマーク';
		icon.width = 16;
		icon.height = 16;
		count = document.createElement('img');
		count.src = 'http://num.bookmarks.yahoo.co.jp/image/small/' + url;
		text = document.createTextNode(" ");
		anchor.appendChild(icon);
		anchor.appendChild(count);
		social.appendChild(anchor);
		social.appendChild(text);
		
		//Facebook
		anchor = document.createElement('a');
		anchor.className = 'facebook';
		anchor.name = 'fb_share';
		anchor.type = 'icon';
		anchor.share_url = url;
		anchor.title = 'この記事をfacebookでシェア';
		script = document.createElement("script");
		script.type = "text/javascript";
		script.src = 'http://static.ak.fbcdn.net/connect.php/js/FB.Share';
		text = document.createTextNode(" ");
		social.appendChild(anchor);
		social.appendChild(script);
		social.appendChild(text);
	}
	
	this.topsyCallback = function (json) {
		
		var response = json.response;
		
		if (!response.total) {return false;}
		
		var element = document.getElementById('tweet_count');
		if (element) {
			var suffix = response.total > 1 ? "tweets" : "tweet";
			element.innerHTML = response.total + suffix + "&nbsp;";
			element.style.display = "inline";
		}
	}
	
}

