if (typeof Nicovideo == 'undefined') {
	Nicovideo = new Object();
}
if (typeof Nicovideo.Global == 'undefined') {
	Nicovideo.Global = {
		playerCount: 0,
		embedMode: "noflash"
	};
	(function () {
		if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] === "object" && navigator.mimeTypes && navigator.mimeTypes.length) {
			Nicovideo.Global.embedMode = "embed";
		} else if (typeof ActiveXObject !== "undefined") {
			try {
				var ax = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				if (ax) {
					Nicovideo.Global.embedMode = "object";
				}
			} catch (e) {}
		}
	})();
}

Nicovideo.version = '1.6.1';
Nicovideo.url = 'http://www.nicovideo.jp/';
Nicovideo.playerUrl = 'http://ext.nicovideo.jp/swf/player/thumbwatch.swf?ts=1422498786';

Nicovideo.Video = function (video) {
	if (video) {
		for (var key in video) {
			this[key] = video[key];
		}
	}
};
Nicovideo.Video.prototype = {
	getPlayURL: function () {
		return Nicovideo.url + 'watch/' + encodeURIComponent(this.v);
	},
	getShortTitle: function () {
		return this.title.substring(0, 60) +
			(this.title.length > 60 ? "..." : "");
	},
	getShortDescription: function () {
		return this.description.substring(0, 60) +
			(this.description.length > 60 ? "..." : "");
	}
};

Nicovideo.MiniPlayer = function (video, vars, width, height) {
	this.id          = Nicovideo.MiniPlayer.allocateId(this);
	this.video       = video;
	this.attributes  = {};
	this.parameters  = {};
	this.variables   = vars || {};
	this.width = width ? width : '485';
	this.height = height ? height : '385';
	if (window.innerWidth && this.width > window.innerWidth) {
		var scale = (window.innerWidth - 20) / this.width;		if (scale > 0) {
			this.width = this.width * scale;
			this.height = this.height * scale;
		}
	}
};
Nicovideo.MiniPlayer.prototype = {
	defaultAttributes: {},
	defaultParameters: {
		allowScriptAccess: 'always',
		allowFullScreen: 'true',
		bgcolor: '#000000',
		quality: 'high'
	},


	_merge: function () {
		var o = {};
		for (var i = 0, len = arguments.length; i < len; i++) {
			var arg = arguments[i];
			if (typeof arg != "object") continue;
			for (var key in arg) {
				o[key] = arg[key];
			}
		}
		return o;
	},
	_escape: function (s) {
		return String(s).replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
	},
	getHTML: function () {
		var id = this.id,
			video = this.video,
			attrs = this._merge(this.defaultAttributes, this.attributes),
			params = this._merge(this.defaultParameters, this.parameters),
			vars = this.variables;

		var flashvars = [];
		for (var key in vars) {
			flashvars.push(key + '=' + encodeURIComponent(vars[key]));
		}
		params.flashvars = flashvars.join("&");

		var html;
		switch (Nicovideo.Global.embedMode) {
		case "embed":
			html =
				'<embed type="application/x-shockwave-flash"'
				+ ' id="' + id + '"'
				+ ' name="' + id + '"'
				+ ' src="' + Nicovideo.playerUrl + '"'
				+ ' width="' + this.width  + '"'
				+ ' height="' + this.height + '"'
				;
			for (var key in params) {
				html += ' ' + key + '="' + params[key] + '"';
			}
			for (var key in attrs) {
				html += ' ' + key + '="' + attrs[key] + '"';
			}
			html += ' />';
			break;
		case "object":
			html =
				'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
				+ ' id="' + id + '"'
				+ ' name="' + id + '"'
				+ ' width="' + this.width + '"'
				+ ' height="' + this.height + '"'
				;
			for (var key in attrs) {
				html += ' ' + key + '="' + attrs[key] + '"';
			}
	 		html += '>';
			html += '<param name="movie" value="' + Nicovideo.playerUrl + '" />';
			for (var key in params) {
				html += '<param name="' + key + '" value="' + params[key] + '" />';
			}
			html += '</object>';
			break;
		default:
			html =
				'<div style="'
						+ 'width:' + (this.width === "100%" ? this.width : this.width + "px")
						+ '; height:' + (this.height === "100%" ? this.height : this.height + "px")
						+ '; display:inline-block; background:#000; color:#FFF; margin:0; padding:0; overflow:hidden;">'
				+ '<a href="' + video.getPlayURL() + '" target="_blank" title="' + this._escape(video.title) + '"'
						+ ' style="position:relative; display:inline-block; width:100%; height:100%;">'
					+ '<img src="' + video.thumbnail + '" alt="" style="width:100%; height:100%; border:none;" />';
			if (!video.isDeleted && (this.width === "100%" || this.width >= 240) && (this.height === "100%" || this.height >= 120)) {
				html += '<span style="display:inline-block; position:absolute; left:0; top:0; width:100%; height:100%;'
							+ ' background-image: url(http://res.nimg.jp/img/thumb/nico/play.png); background-repeat: no-repeat; background-position: center center;"></span>';
			}
			html += '</a>'
				+ '</div>';
			break;
		}

		return html;
	},
	write: function (id) {
		if (id === undefined) {
			document.write(this.getHTML());
		} else if (typeof id == "string") {
			var el = document.all ? document.all[id] : document.getElementById(id);
			if (el) el.innerHTML = this.getHTML();
		} else if (id) {
			id.innerHTML = this.getHTML();
		}
	}
};

Nicovideo.MiniPlayer.allocateId = function (player) {
	var id = 'external_nico_' + (Nicovideo.Global.playerCount++);
	return id;
};

if (document.all && !window.opera) {
	window.attachEvent("onbeforeunload", function () {
		window.attachEvent("onunload", function () {
			for (var i = 0, l = Nicovideo.Global.playerCount; i < l; i++) {
				var id = 'external_nico_' + i, el = document.all ? document.all[id] : document.getElementById(id);
				if (el && el.parentNode) {
					for (var key in el) {
						if (typeof el[key] == 'function')
							el[key] = null;
					}
					el.parentNode.removeChild(el);
				}
			}
		});
	});
}


(function () {
	var b = true;
	try {
		var w = window.parent, self = window.self;
		while (w && w != self) {
			if (w.location.host != self.location.host) {
				b = false;
				break;
			}
			if (w === w.parent) break;
			w = w.parent;
		}
	} catch (e) {
		b = false;
	}

	if (!b) {
		Nicovideo = undefined;
		document.write(
			'<p><a href="http://www.nicovideo.jp/watch/1262869455" target="_blank">\u30c7\u30fc\u30c8\u30b3\u30fc\u30b9\u306e\u30de\u30b8\u30b9\u30ad\u30e9\u30b8\u30aa\u3000\u7b2c\uff13\u56de</a></p>'
		);
		return;
	}

	var video = new Nicovideo.Video({
		v: '1262869455'
	,	id: 'so9319968'
	,	title: '\u30c7\u30fc\u30c8\u30b3\u30fc\u30b9\u306e\u30de\u30b8\u30b9\u30ad\u30e9\u30b8\u30aa\u3000\u7b2c\uff13\u56de'
	,	description: '\uff1c2009\u5e7404\u670824\u65e5\u767a\u58f2\uff1e\u30de\u30b8\u30b9\u30ad\u767a\u30a2\u30a4\u30c9\u30eb\u30e6\u30cb\u30c3\u30c8\u300c\u30c7\u30fc\u30c8\u30b3\u30fc\u30b9\u300d\u306e\uff2e\uff25\uff34\u30c6\u30ec\u30d3\uff1f\u3067\u3059\u3002\u304a\u305f\u3088\u308a\u7d76\u8cdb\u52df\u96c6\u4e2d\u3067\u3059\uff01\uff01\u756a\u7d44\u306e\u524d\u5f8c\u306b\u306f\u3001\u30d2\u30ed\u30a4\u30f3\u306e\u30df\u30cb\u30c9\u30e9\u30de\u3082\u3042\u308a\u307e\u3059\u3001\u4eca\u56de\u306f\u7531\u7d00\u83dc\u3068\u4e00\u7dd2\u306b\u30e9\u30b8\u30aa\u3092\u8074\u304f\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002\u304a\u305f\u3088\u308a\u3092\u9001\u3063\u3066\u304f\u308c\u305f\u65b9\u306b\u306f\u3001\u6bce\u6708\u30d7\u30ec\u30bc\u30f3\u30c8\u30dc\u30a4\u30b9\u304c\u8cb0\u3048\u3061\u3083\u3044\u307e\u3059\u3088\uff01\uff01\u30d1\u30fc\u30bd\u30ca\u30ea\u30c6\u30a3\uff1a\u5929\u6d25\u308a\u3055\uff08\u6c11\u5b89\u3068\u3082\u3048\uff09\u30df\u30cb\u30c9\u30e9\u30de\uff1a\u5bae\u5d0e\u7531\u7d00\u83dc\uff08\u5b89\u7396\u6df1\u97f3\uff09\u30c7\u30fc\u30c8\u30b3\u30fc\u30b9\u30e1\u30f3\u30d0\u30fc\u3000\u5929\u6d25\u308a\u3055\uff08\u6c11\u5b89\u3068\u3082\u3048\uff09\uff0f\u5449\u7fbd\u6210\u7f8e\uff08\u52a0\u702c\u611b\u5948\uff09\uff0f\u5f53\u9ebb\u7f8e\u5e06\uff08\u307f\u308b\u304f\uff09\u00a9MOONSTONE\u25a0\u7f8e\u5c11\u5973\u30b2\u30fc\u30e0\u30e6\u30fc\u30b6\u30fc\u306e\u793e\u4ea4\u5834\u30c1\u30e3\u30f3\u30cd\u30eb \u8679\u8996\u8074\u899a\u5ba4 \u21d2 ch304'
	,	thumbnail: 'http:\/\/tn-skr1.smilevideo.jp\/smile?i=9319968'
	,	postedAt: new Date('2009\/02\/06 10:00:00 +0900')
	,	length: 1252
	,	viewCount: 14312
	,	mylistCount: 4
	,	commentCount: 340
	,	movieType: 'mp4'
	,	isDeleted: false	,	isMymemory: false	});
	var player = new Nicovideo.MiniPlayer(video, {
	'thumbWatch': '1'
	,'thumbPlayKey': '1423087302.0.1.0uKTQgdl0vrX38JedYVxJZbX3Q0.aHR0cDovL21vb24tc3RvbmUuanAvcHJvZHVjdC9tczA4L2luZGV4MDguaHRtbA==..'
	,'playerTimestamp': '1422858136'
	,'player_version_xml': '1422858134'
	,'player_info_xml': '1418278282'
	,'translation_version_json': '1415685948'
	,'v': '1262869455'
	,'videoId': 'so9319968'
	,'thumbTitle': '\u30c7\u30fc\u30c8\u30b3\u30fc\u30b9\u306e\u30de\u30b8\u30b9\u30ad\u30e9\u30b8\u30aa\u3000\u7b2c\uff13\u56de'
	,'thumbDescription': '\uff1c2009\u5e7404\u670824\u65e5\u767a\u58f2\uff1e\u30de\u30b8\u30b9\u30ad\u767a\u30a2\u30a4\u30c9\u30eb\u30e6\u30cb\u30c3\u30c8\u300c\u30c7\u30fc\u30c8\u30b3\u30fc\u30b9\u300d\u306e\uff2e\uff25\uff34\u30c6\u30ec\u30d3\uff1f\u3067\u3059\u3002\u304a\u305f\u3088\u308a\u7d76\u8cdb\u52df\u96c6\u4e2d\u3067\u3059\uff01\uff01...'
	,'thumbImage': 'http:\/\/tn-skr1.smilevideo.jp\/smile?i=9319968'
	,'movie_type': 'mp4'
	,'wv_id': 'so9319968'
	,'language': 'ja-jp'
	,'is_community_thread': '1'
	,'noAdSense': '1'
	,'category': 'R-18'
	,'categoryGroup': 'R-18'
	,'leaf_switch': '1'
	,'accessFromHash': '1423000902:f0d8f6394855972eb83e81c16abdcffe62eb23b8aad9ab5d4daf1a549b9136b1'
	}, '280', '240');
	player.write();
})();

