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=1417677079';

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/sm21494172" target="_blank">\u304b\u3093\u3053\u308c\u3075\u3041\u3093\u304f\u3089\u3076\u3010\u8266\u3053\u308c\u00d7\u3044\u30fc\u3042\u308b\u3075\u3041\u3093\u304f\u3089\u3076\u3011</a></p>'
		);
		return;
	}

	var video = new Nicovideo.Video({
		v: 'sm21494172'
	,	id: 'sm21494172'
	,	title: '\u304b\u3093\u3053\u308c\u3075\u3041\u3093\u304f\u3089\u3076\u3010\u8266\u3053\u308c\u00d7\u3044\u30fc\u3042\u308b\u3075\u3041\u3093\u304f\u3089\u3076\u3011'
	,	description: '\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u3000\u534a\u5e74\u4ee5\u4e0a\u3082\u30ec\u30a2\u99c6\u9010\u30ec\u30b7\u30d4\u56de\u3057\u3066\u308b\u3051\u3069\u3000\u672a\u3060\u306b\u96ea\u98a8\u304c\u6765\u306a\u3044\u4ffa\u93ae\u5b88\u5e9c\u3067\u3059\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u30aa\u30d5\u30dc\u30fc\u30ab\u30eb\u7248\u3000\u2192\u3000sm21638245\u539f\u66f2\uff1a\u3044\u30fc\u3042\u308b\u3075\u3041\u3093\u304f\u3089\u3076(sm18623327)\u3000\u539f\u4f5c\uff1a\u8266\u968a\u3053\u308c\u304f\u3057\u3087\u3093(http:\/\/goo.gl\/quVVG0)\u53c2\u8003\uff1a\u3077\u3088\u3077\u3088\u3075\u3041\u3093\u304f\u3089\u3076(sm19508389)\u3000\u5354\u529b\uff1ajink_k(\u30a2\u30c9\u30d0\u30a4\u30b6\u30fc),\u307f\u3085\u3046mylist\/25721128\u306a\u3093\u304b\u3042\u3052\u305f\uff1asm24572593'
	,	thumbnail: 'http:\/\/tn-skr1.smilevideo.jp\/smile?i=21494172.L'
	,	postedAt: new Date('2013\/08\/02 03:44:37 +0900')
	,	length: 182
	,	viewCount: 2413803
	,	mylistCount: 86777
	,	commentCount: 28074
	,	movieType: 'mp4'
	,	isDeleted: false	,	isMymemory: false	});
	var player = new Nicovideo.MiniPlayer(video, {
	'thumbWatch': '1'
	,'thumbPlayKey': '1417956240.0.1.sacjpWQHfrW_vHQCAYRgM-JGmj8.aHR0cDovL2thbmtvcmVkb3VqaW4uYmxvZy5mYzIuY29tL2Jsb2ctZW50cnktNjMzLmh0bWw=..'
	,'playerTimestamp': '1417677103'
	,'player_version_xml': '1417677101'
	,'player_info_xml': '1417589370'
	,'translation_version_json': '1415685948'
	,'v': 'sm21494172'
	,'videoId': 'sm21494172'
	,'thumbTitle': '\u304b\u3093\u3053\u308c\u3075\u3041\u3093\u304f\u3089\u3076\u3010\u8266\u3053\u308c\u00d7\u3044\u30fc\u3042\u308b\u3075\u3041\u3093\u304f\u3089\u3076\u3011'
	,'thumbDescription': '\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u56de\u3000\u534a\u5e74\u4ee5\u4e0a\u3082\u30ec\u30a2\u99c6\u9010\u30ec\u30b7\u30d4\u56de\u3057\u3066\u308b\u3051\u3069\u3000\u672a\u3060\u306b\u96ea\u98a8\u304c\u6765\u306a\u3044\u4ffa\u93ae\u5b88\u5e9c\u3067\u3059\u56de...'
	,'thumbImage': 'http:\/\/tn-skr1.smilevideo.jp\/smile?i=21494172.L'
	,'movie_type': 'mp4'
	,'wv_id': 'sm21494172'
	,'language': 'ja-jp'
	,'iee': '1'
	,'isWide': '1'
	,'noAdSense': '1'
	,'category': '\u30a8\u30f3\u30bf\u30fc\u30c6\u30a4\u30e1\u30f3\u30c8'
	,'categoryGroup': '\u30a8\u30f3\u30bf\u30e1\u30fb\u97f3\u697d'
	,'leaf_switch': '2'
	,'accessFromHash': '1417869840:fbc1f2f25d8ee196844f3fa2cfe1919e21f3f9eaf7c032a4e906d1b608b0f207'
	}, '320', '252');
	player.write();
})();

