
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 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);
	
	//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);
	
	//Twitter
	anchor = document.createElement('a');
	anchor.setAttribute("class", "twitter twitter-share-button");
	anchor.setAttribute("href", "http://twitter.com/share");
	anchor.setAttribute("data-url", url);
	anchor.setAttribute("data-text", decodeURIComponent(title));
	anchor.setAttribute("data-count", "horizontal");
	anchor.setAttribute("data-via", "Francfranc_web");
	anchor.setAttribute("data-lang", "ja");
	text = document.createTextNode("ツイート");
	script = document.createElement("script");
	script.type = "text/javascript";
	script.src = 'http://platform.twitter.com/widgets.js';
	anchor.appendChild(text);
	social.appendChild(anchor);
	social.appendChild(script);
	
}


/* fac */
if (typeof fac == "undefined") fac = function() {};

fac.delegate = function  (this_object, method, args, join_args) {
	//fac.log("fac.delegate(" + [this_object, method, args, join_args] + ")");
	
	return function () {
		if (join_args) {
			var joined_args = new Array();
			var i;
			var length = arguments.length;
			for (i = 0; i < length; i++) {
				joined_args.push(arguments[i]);
			};
			joined_args = joined_args.concat(args);
			return method.apply(this_object, joined_args);
		}
		else if (args && args.length >= 1) {
			return method.apply(this_object, args);
		}
		else {
			return method.apply(this_object, arguments);
		};
	};
};

fac.log = function (args) {
	//console.log.apply(this, arguments);
	
	if ($("#fac_console_log").length == 0) {
		$("body").append('<div id="fac_console_log" style="width:200px; height:20em; position:fixed; _position:absolute; left:0; top:0; z-index:10000; background:#fff; border:1px solid #000; color:#000; text-align:left; overflow:auto;">::Log::</div>'); 
	};
	
	var console = $("#fac_console_log");
	
	console
		.append('<div>' + String(args) + '</div>')
		.scrollTop(console.scrollHeight);
};


/* fac.utils */
if (typeof fac.utils == "undefined") fac.utils = function() {};

fac.utils.setDigits = function (num, digits) {
	//fac.log("Util.setDigits (" + [num, digits] + ")");
	
	var num_string = String(num);
	while (num_string.length < digits) {
		num_string = "0" + num_string;
	};
	return num_string;
};

fac.utils.getDefinedValue = function () {
	//fac.log("Util.getDefinedValue (" + [] + ")");
	
	var i;
	var value;
	var value_length = arguments.length;
	for (i = 0; i < value_length; i++) {
		value = arguments[i];
		if (typeof value == "boolean" || (
			value != undefined && 
			value != null && 
			!(typeof value == "string" && value == "") && 
			!(typeof value == "number" && isNaN(value))
		)) {
			return value;
		};
	};
	
	return arguments[value_length - 1];
};


/* fac.utils.ImageLoader */
fac.utils.ImageLoader = function (source, prevent_cache) {
	//fac.log("ImageLoader (" + [source, prevent_cache] + ")");
	
	this.image = $('<img />');
	this.source = prevent_cache ? source + "?" + new Date().getTime() : source;
};

fac.utils.ImageLoader.ON_LOADED      = "onLoaded";

fac.utils.ImageLoader.prototype = {
	
	image                 : null, 
	source                : null, 
	
	start : function () {
		//fac.log("ImageLoader.start (" + [] + ")");
		
		this.image
			.hide()
			.attr('src', this.source)
			.appendTo(document.body)
			.load(fac.delegate(this, this.loaded))
			.error(fac.delegate(this, this.loaded));
			//.error(fac.delegateWithArgs(this, fac.log, ["error!"]));
	}, 
	
	loaded : function () {
		//fac.log("ImageLoader.loaded (" + [] + ")");
		
		this.image
			.show()
			.remove();
		
		$(this).trigger(fac.utils.ImageLoader.ON_LOADED, [this.image]);
	}
	
};

