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.0';
Nicovideo.url = 'http://www.nicovideo.jp/';
Nicovideo.playerUrl = 'http://ext.nicovideo.jp/swf/player/thumbwatch.swf?ts=1327297643';

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  || '485';
	this.height      = height || '385';
};
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 + 'px; 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 >= 240 && 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/sm9659259" target="_blank">\u3010AR\u30ab\u30d7\u30bb\u30eb\u3011\u3064\u3044\u306b\u30e2\u30cb\u30bf\u304b\u3089\u51fa\u3066\u304d\u3066\u304f\u308c\u305f \uff08\u88f8\u773cAR\uff09</a></p>'
		);
		return;
	}

	var video = new Nicovideo.Video({
		v: 'sm9659259'
	,	id: 'sm9659259'
	,	title: '\u3010AR\u30ab\u30d7\u30bb\u30eb\u3011\u3064\u3044\u306b\u30e2\u30cb\u30bf\u304b\u3089\u51fa\u3066\u304d\u3066\u304f\u308c\u305f \uff08\u88f8\u773cAR\uff09'
	,	description: '\u25a0\u30d4\u30b3\u30d7\u30ed\u30b8\u30a7\u30af\u30bf\u30fc\u306e\u529b\u3092\u501f\u308a\u3066\u3001\u30e2\u30cb\u30bf\u304b\u3089\u3061\u3087\u3063\u3068\u51fa\u3066\u304d\u3066\u3082\u3089\u3044\u307e\u3057\u305f\u3002\u25a0\u88f8\u773c\u3067\u898b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u25a0\u500b\u4eba\u30ec\u30d9\u30eb\u3067\u6848\u5916\u306a\u3093\u3068\u304b\u306a\u308b\u30c7\u30d0\u30a4\u30b9\u3068\u6280\u8853\u306e\u96c6\u5408\u4f53\u3067\u3059\u3002\u25a0 MMD\u30e2\u30c7\u30eb\u306b\u3088\u308b\u30c0\u30f3\u30b9\u6a5f\u80fd\u3068\u300c\u3053\u3063\u3061\u307f\u3066\u300d\u6a5f\u80fd\u306e\u307b\u3068\u3093\u3069\u306fARTK_Alive\u306e\u304a\u304b\u3052\u3067\u3059\u3088\u3002\u611f\u8b1d\uff01\u305d\u306e\u307b\u304b\u611f\u8b1d\u306f\u52d5\u753b\u672b\u5c3e\u306b\u3002\u25a0 \u300c2.75\u6b21\u5143\u300d\u9802\u304d\u307e\u3059\uff01\u25a0\uff11\uff14\u4e07\u518d\u751f\u30aa\u30ef\u30bf\uff3c(\uff3eo\uff3e)\uff0f\u25a0\u30d6\u30ed\u30b0\u6652\u3057\u3066\u304a\u304d\u307e\u3059\uff08\u307e\u3060\u3042\u307e\u308a\u8a73\u7d30\u66f8\u3044\u3066\u306a\u3044\u3067\u3059\u3051\u3069\uff09 http:\/\/hammm.blog21.fc2.com\/blog-entry-83.html'
	,	thumbnail: 'http:\/\/tn-skr4.smilevideo.jp\/smile?i=9659259'
	,	postedAt: new Date('2010\/02\/10 03:38:30 +0900')
	,	length: 320
	,	viewCount: 190638
	,	mylistCount: 2633
	,	commentCount: 3725
	,	movieType: 'mp4'
	,	isDeleted: false	,	isMymemory: false	});
	var player = new Nicovideo.MiniPlayer(video, {
	'thumbWatch': '1'
	,'thumbPlayKey': '1338362325.0.LBia87-LT6KAk4FRgZ8BBqFUfkI...'
	,'playerTimestamp': '1337572427'
	,'player_version_xml': '1337572616'
	,'player_info_xml': '1335635123'
	,'v': 'sm9659259'
	,'videoId': 'sm9659259'
	,'thumbTitle': '\u3010AR\u30ab\u30d7\u30bb\u30eb\u3011\u3064\u3044\u306b\u30e2\u30cb\u30bf\u304b\u3089\u51fa\u3066\u304d\u3066\u304f\u308c\u305f \uff08\u88f8\u773cAR\uff09'
	,'thumbDescription': '\u25a0\u30d4\u30b3\u30d7\u30ed\u30b8\u30a7\u30af\u30bf\u30fc\u306e\u529b\u3092\u501f\u308a\u3066\u3001\u30e2\u30cb\u30bf\u304b\u3089\u3061\u3087\u3063\u3068\u51fa\u3066\u304d\u3066\u3082\u3089\u3044\u307e\u3057\u305f\u3002\u25a0\u88f8\u773c\u3067\u898b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u25a0\u500b\u4eba\u30ec\u30d9\u30eb\u3067\u6848\u5916...'
	,'thumbImage': 'http:\/\/tn-skr4.smilevideo.jp\/smile?i=9659259'
	,'movie_type': 'mp4'
	,'wv_id': 'sm9659259'
	,'iee': '1'
	,'category': '\u30cb\u30b3\u30cb\u30b3\u6280\u8853\u90e8'
	,'categoryGroup': '\u79d1\u5b66\u30fb\u6280\u8853'
	,'leaf_switch': '2'
	}, '', '');
	player.write();
})();


