if (typeof Nicovideo == 'undefined') {
	Nicovideo = new Object();
}
if (typeof Nicovideo.Global == 'undefined') {
	Nicovideo.Global = {
		players: {},
		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=1477290049';

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.listeners   = {};
	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'
	},

	addEventListener: function (type, listener) {
		type = String(type).toLowerCase();
		if (!this.listeners[type]) {
			this.listeners[type] = [];
		}
		this.listeners[type].push(listener);
	},
	removeEventListener: function (type, listener) {
		type = String(type).toLowerCase();
		if (this.listeners[type]) {
			var a = this.listeners[type];
			for (var i = a.length - 1; i >= 0; i--) {
				if (a[i] === listener) {
					a.splice(i, 1);
				}
			}
		}
	},
	fire: function (type, args) {
		type = String(type).toLowerCase();
		if (this.listeners[type]) {
			args = [this].concat(args || []);
			var a = this.listeners[type];
			for (var i = 0, l = a.length; i < l; i++) {
				var v = a[i];
				(typeof v == "string" ? window[v] : v).apply(window, args);
			}
		}
	},

	_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++);
	Nicovideo.Global.players[id] = player;
	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);
				}
			}
		});
	});
}

window.onNicoPlayerReady = function (id) {
	var player = Nicovideo.Global.players[id];
	if (player) player.fire("onReady");
};
window.onNicoPlayerStatus = function (id, newStatus) {
	var player = Nicovideo.Global.players[id];
	if (player) {
		player.fire("onStateChange", [newStatus]);
		if (newStatus == "end") {
			player.fire("onVideoEnd");
		}
	}
};

(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/sm8134939" target="_blank">\u3010\u624b\u66f8\u304dMAD\u3011\u307c\u304b\u304a\u3093!\u3010\u3051\u3044\u304a\u3093!OP\u30d1\u30ed\u3011</a></p>'
		);
		return;
	}

	var video = new Nicovideo.Video({
		v: 'sm8134939'
	,	id: 'sm8134939'
	,	title: '\u3010\u624b\u66f8\u304dMAD\u3011\u307c\u304b\u304a\u3093!\u3010\u3051\u3044\u304a\u3093!OP\u30d1\u30ed\u3011'
	,	description: '\u30dc\u30ab\u30ed\u3067\u3051\u3044\u304a\u3093OP\u306e\u30d1\u30ed\u30c7\u30a3\u63cf\u3044\u3066\u307f\u307e\u3057\u305f\u3002\u307b\u307c\u30c8\u30ec\u30b9\u3067\u80cc\u666f\u3082\u307b\u3068\u3093\u3069\u5143\u52d5\u753b\u306e\u6d41\u7528\u3067\u3059\u3002\u670d\u306e\u30c7\u30b6\u30a4\u30f3\u3068\u304b\u697d\u5668\u3068\u304b\u63cf\u304d\u5fd8\u308c\u591a\u3044\u3067\u3059(\u30fb\u03c9\u30fb\uff40)\u3042\u305a\u306b\u3083\u3093\u306f\u3054\u3081\u3093\u306a\u3055\u3044(\u00b4\uff40)\u25c6\u97f3\u6e90\u306fsm6892984\u3092\u304a\u501f\u308a\u3057\u307e\u3057\u305f\u3002\u86c7\u8db3\u3060\u3063\u305f\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u30ea\u30f3\u30ec\u30f3\u3067\u3061\u3087\u3053\u3063\u3068\u30b3\u30fc\u30e9\u30b9\u5165\u308c\u3066\u307e\u3059\u3002\u25c6\u6bd4\u8f03\u52d5\u753b(sm8138249)\u30b8\u30a7\u30d0\u30f3\u30cb!\u3000\u25c6\u7de8\u96c6\u3057\u3066\u30ba\u30ec\u4fee\u6b63\u3057\u3066\u3044\u305f\u3060\u3044\u305f\u6bd4\u8f03\u52d5\u753b(sm8176237)\u25c6(10\/31)\u97f3\u6e90\u306e\u4f5c\u8005\u3055\u3093\u3067\u3042\u308bESCII\u3055\u3093\u304c\u5168\u54e1\u6b4c\u5531\u7248\u3092\u4f5c\u3063\u3066\u304f\u3060\u3055\u3044\u307e\u3057\u305f\u2192sm8662648\u25c6(2\/7)50\u4e07\u518d\u751f\uff01\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\uff01\u25c6(2012.6\/12)\u30df\u30ea\u30aa\u30f3\u518d\u751f\uff01\uff01\u305f\u304f\u3055\u3093\u898b\u3066\u3044\u305f\u3060\u3044\u3066\u611f\u8b1d\u3067\u3059\uff012\u671f\u30d1\u30ed\u3082\u63cf\u304d\u307e\u3057\u305f \u2192 sm15955457\u3000'
	,	thumbnail: 'http:\/\/tn-skr4.smilevideo.jp\/smile?i=8134939'
	,	postedAt: new Date('2009\/09\/04 22:23:11 +0900')
	,	length: 90
	,	viewCount: 1314365
	,	mylistCount: 49804
	,	commentCount: 23947
	,	movieType: 'mp4'
	,	isDeleted: false	,	isMymemory: false	});
	var player = new Nicovideo.MiniPlayer(video, {
	'thumbWatch': '1'
	,'thumbPlayKey': '1483692010.1.1.-KxBXdeYNttJ6y-5jlhsuOFTtaM.aHR0cDovL2QuaGF0ZW5hLm5lLmpwL2hldGFyb28yMy8=...0'
	,'playerTimestamp': '1477540563'
	,'player_version_xml': '1477540558'
	,'player_info_xml': '1477631020'
	,'translation_version_json': '1481782207'
	,'v': 'sm8134939'
	,'videoId': 'sm8134939'
	,'thumbTitle': '\u3010\u624b\u66f8\u304dMAD\u3011\u307c\u304b\u304a\u3093!\u3010\u3051\u3044\u304a\u3093!OP\u30d1\u30ed\u3011'
	,'thumbDescription': '\u30dc\u30ab\u30ed\u3067\u3051\u3044\u304a\u3093OP\u306e\u30d1\u30ed\u30c7\u30a3\u63cf\u3044\u3066\u307f\u307e\u3057\u305f\u3002\u307b\u307c\u30c8\u30ec\u30b9\u3067\u80cc\u666f\u3082\u307b\u3068\u3093\u3069\u5143\u52d5\u753b\u306e\u6d41\u7528\u3067\u3059\u3002\u670d\u306e\u30c7\u30b6\u30a4\u30f3\u3068\u304b\u697d\u5668\u3068\u304b\u63cf\u304d\u5fd8...'
	,'thumbTags': '\u521d\u97f3\u30df\u30af VOCALOID VOCALOID\u540d\u30ab\u30d0\u30fc\u66f2\u30ea\u30f3\u30af VOCALOID\u30a2\u30cb\u30e1OPED\u30d1\u30ed\u30ea\u30f3\u30af \u624b\u63cf\u304dMAD\u6bbf\u5802\u5165\u308a \u91ce\u751f\u306e\u4eac\u30a2\u30cb \u307c\u304b\u304a\u3093\uff01 VOCALOID\u30a2\u30cb\u30e1\u5316\u8a08\u753b VOCALOID\u5b66\u751f\u5316\u8a08\u753b \u9a5a\u7570\u306e\u518d\u73fe\u7387 \u3051\u3044\u304a\u3093\uff01'
	,'thumbImage': 'http:\/\/tn-skr4.smilevideo.jp\/smile?i=8134939'
	,'movie_type': 'mp4'
	,'wv_id': 'sm8134939'
	,'language': 'ja-jp'
	,'iee': '1'
	,'noAdSense': '1'
	,'category': 'VOCALOID'
	,'categoryGroup': '\u30a8\u30f3\u30bf\u30e1\u30fb\u97f3\u697d'
	,'leaf_switch': '2'
	,'accessFromHash': '1483605610:913475179e4e5901d1f5104ac99e7a96a560ea9d092416cd95d3c5efae30e967'
	}, '', '');
	player.write();
})();

