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/1416469449" target="_blank">\u3067\u304d\u305f\u3066\u30b5\u30f3\u30d7\u30eb\u3092\u5909\u5f62\u3055\u305b\u3066\u307f\u305f\uff01\u300cGearTribe\u521d\u97f3\u30df\u30afGT\u30d7\u30ed\u30b8\u30a7\u30af\u30c8...</a></p>'
		);
		return;
	}

	var video = new Nicovideo.Video({
		v: '1416469449'
	,	id: 'so24953932'
	,	title: '\u3067\u304d\u305f\u3066\u30b5\u30f3\u30d7\u30eb\u3092\u5909\u5f62\u3055\u305b\u3066\u307f\u305f\uff01\u300cGearTribe\u521d\u97f3\u30df\u30afGT\u30d7\u30ed\u30b8\u30a7\u30af\u30c82014Ver. \u300d '
	,	description: '\u7d76\u8cdb\u4e88\u7d04\u53d7\u4ed8\u4e2d\u306e\u5909\u5f62\u30ed\u30dc\u300cGearTribe\u521d\u97f3\u30df\u30afGT\u30d7\u30ed\u30b8\u30a7\u30af\u30c82014Ver.\u300d\u3002\u304a\u304b\u3052\u3055\u307e\u3067\u5927\u53cd\u97ff\u3044\u305f\u3060\u3044\u3066\u304a\u308a\u307e\u3059\u304c\u3001\u4e2d\u306b\u306f\u300c\u672c\u5f53\u306b\u5909\u5f62\u3067\u304d\u308b\u306e\uff1f\u300d\u3068\u304b\u300c\u3069\u3046\u305b\u30ac\u30ef\u5909\u5f62\u3067\u3057\u3087w\u300d\u300c\u30c9\u30e9\u30a4\u30d0\u30fc\u306f\u5727\u6b7b\u3060\u306aw\u300d\u306a\u3069\u306e\u304a\u58f0\u3082\u3044\u305f\u3060\u3044\u3066\u304a\u308a\u307e\u3059\u3002\u305d\u3093\u306a\u3054\u610f\u898b\u306b\u304a\u7b54\u3048\u3059\u3079\u304f\u3001\u5b9f\u969b\u306b\u30b5\u30f3\u30d7\u30eb\u3092\u5909\u5f62\u3055\u305b\u3066\u3044\u308b\u52d5\u753b\u3092\u3054\u7528\u610f\u3057\u307e\u3057\u305f\u3002\u5909\u5f62\u524d\u5f8c\u3067\u4f59\u5270\u30d1\u30fc\u30c4\u306e\u306a\u3044\u3001\u307e\u3055\u306b\u300c\u5b8c\u5168\u5909\u5f62\u300d\u3068\u3044\u3048\u308b\u6a5f\u69cb\u306f\u3082\u3061\u308d\u3093\u3001\u30d5\u30ed\u30f3\u30c8\u30b9\u30dd\u30a4\u30e9\u30fc\u3068\u30ea\u30a2\u30a6\u30a4\u30f3\u30b0\u3092\u53d6\u308a\u5916\u3057\u3001\u30c4\u30a4\u30f3\u30c6\u30fc\u30eb\u306b\u3067\u304d\u308b\u3068\u3044\u3046\u3053\u3060\u308f\u308a\u306b\u3082\u3054\u6ce8\u76ee\u304f\u3060\u3055\u3044\uff01\u3067\u304d\u305f\u3066\u30db\u30e4\u30db\u30e4\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u3059\u306e\u3067\u3001\u672c\u6765\u306a\u3089\u304a\u898b\u305b\u3067\u304d\u308b\u6bb5\u968e\u3067\u306f\u306a\u3044\u306e\u3067\u3059\u304c\u6cb3\u68ee\u76e3\u7763\u306b\u3088\u308b\u7dfb\u5bc6\u306a\u5909\u5f62\u6a5f\u69cb\u3092\u582a\u80fd\u3057\u3066\u3044\u305f\u3060\u304d\u305f\u304f\u3001\u4e00\u8db3\u5148\u306b\u516c\u958b\u3044\u305f\u3057\u307e\u3059\uff01http:\/\/www.goodsmile.info\/ja\/gsrbmw\/'
	,	thumbnail: 'http:\/\/tn-skr1.smilevideo.jp\/smile?i=24953932'
	,	postedAt: new Date('2014\/11\/20 16:42:46 +0900')
	,	length: 178
	,	viewCount: 709
	,	mylistCount: 29
	,	commentCount: 19
	,	movieType: 'mp4'
	,	isDeleted: false	,	isMymemory: false	});
	var player = new Nicovideo.MiniPlayer(video, {
	'thumbWatch': '1'
	,'thumbPlayKey': '1418092251.0.1.CiBNITDc5JYdMPADdIr21SPJOCM.aHR0cDovL2hhdHN1bmVtaWt1MTAwNi5ibG9nLmZjMi5jb20v..'
	,'playerTimestamp': '1417677103'
	,'player_version_xml': '1417677101'
	,'player_info_xml': '1417589370'
	,'translation_version_json': '1415685948'
	,'v': '1416469449'
	,'videoId': 'so24953932'
	,'thumbTitle': '\u3067\u304d\u305f\u3066\u30b5\u30f3\u30d7\u30eb\u3092\u5909\u5f62\u3055\u305b\u3066\u307f\u305f\uff01\u300cGearTribe\u521d\u97f3\u30df\u30afGT\u30d7\u30ed\u30b8\u30a7\u30af\u30c82014Ver. \u300d '
	,'thumbDescription': '\u7d76\u8cdb\u4e88\u7d04\u53d7\u4ed8\u4e2d\u306e\u5909\u5f62\u30ed\u30dc\u300cGearTribe\u521d\u97f3\u30df\u30afGT\u30d7\u30ed\u30b8\u30a7\u30af\u30c82014Ver.\u300d\u3002\u304a\u304b\u3052\u3055\u307e\u3067\u5927\u53cd\u97ff\u3044\u305f\u3060\u3044\u3066\u304a\u308a...'
	,'thumbImage': 'http:\/\/tn-skr1.smilevideo.jp\/smile?i=24953932'
	,'movie_type': 'mp4'
	,'wv_id': 'so24953932'
	,'language': 'ja-jp'
	,'is_community_thread': '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': '1'
	,'accessFromHash': '1418005851:9ef6c561c7da6b9f9ddc9ae1a918bf79ac99f91225709b55adee8d48377c62d6'
	}, '490', '307');
	player.write();
})();

