/* 外部Widgetsの生成 */

function CreateWidgets( use_tweet, use_fblike, use_fbcomment, tw_account, fb_appid, info_fbcomment ){
	FaceBookLoader(fb_appid, info_fbcomment);
	if( $("#twtweet") && use_tweet == 1 ){
		TwButtonLoader( tw_account );
	}
	if( $("#fblike") && use_fblike == 1 ){
		FbButtonLoader();
	}
	if( $("#use_fbcomment") && use_fbcomment == 1 ){
		FbCommentLoader();
	}
}

/* ツイートボタン */
function TwButtonLoader( tw_account ){
	var url   = $("#kiji_url").text();
	$("#twtweet").append('<a href="http://twitter.com/share" class="twitter-share-button" data-url="' + url + '" data-count="horizontal" data-via="' + tw_account + '" data-lang="ja">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>');
}

/* 「いいね！」ボタン */
function FbButtonLoader(){
	var url = $("#kiji_url").text();
	var title = $(".title").text();
	$("#fblike").append('<fb:like href="' + url + '" layout="button_count" show_faces="false" title="' + title + '" ></fb:like>');
}

/* フェイスブックコメント */
function FbCommentLoader(){
	var url   = $("#kiji_url").text();
	var title = $(".title").text();
	$("#fb_comment").append('<fb:comments class="fbcomments" width="500" href="' + url + '" title="' + title + '" num_posts="5" notify="true" ></fb:comments>');
}

/* フェイスブックスクリプト */
function FaceBookLoader(app_id, info_fbcomment){
	$("body").append('<div id="fb-root"></div>');
	window.fbAsyncInit = function(app_id) {
		FB.init({
			appId : app_id,
			status : true, // check login status
			cookie : true, // enable cookies to allow the server to access the session
			xfbml : true // parse XFBML
		});
		if(info_fbcomment == "" || info_fbcomment == 0 ){
			/* コメント通知 */
			var sendPath = '/fbCommentsEN.cgi';
			fbCommentsEN(sendPath);
		}
	};
	(function() {
		$("#fb-root").append('<script type="text/javascript" src="https://connect.facebook.net/ja_JP/all.js" async="true" ></script>');
	}());
}

