(function() {
	var ignore = [];
	var root = document.getElementById("online_view");
	var btn = document.getElementById("online_next_btn");
	var dummy = document.createElement("div");
	var obj = document.createElement("div");
	obj.id = "online_girl_view";
	var nn = document.createElement("div");
	nn.id = "online_girl_nick_name";

	window.replaceVideo = function() {
		var http = new HttpClient(function(data) {
			if(data == "empty") {
				ignore = [];
				return replaceVideo();
			}

			var dst = document.getElementById("online_girl_view");

			try {
				data = eval(data);
			} catch(er) {
				var div = document.createElement("div");
				nn.innerHTML = "";
				dummy.replaceChild(div, dst);
				dummy.appendChild(dst);
				dummy.innerHTML = "";
				return;
			}

			var args = "client_hash=" + data.c_hash + "&chat_instance=" + data.i_name + "&server=" + data.no;

			nn.innerHTML =
				'<a href="javascript:void(open(\'http://www.bb-chat.tv/online.php?ldc&amp;id=' + data.hash + '\',\'bb_popup\',\'width=750,height=441,resizable=1\'));">' +
				data.nick_name +
				'</a>';
			dummy.innerHTML =
				'<object data="/img/online_view.swf?' + args + '" type="application/x-shockwave-flash" width="180" height="135" id="online_girl_view">' +
				'<param name="movie" value="/img/online_view.swf?' + args + '">' +
				'<param name="quality" value="high">' +
				'</object>';
			root.replaceChild(dummy.lastChild, dst);
			//しっかりとFLASHを潰しておく
			dummy.appendChild(dst);
			dummy.innerHTML = "";

			ignore.push(data.hash);
		});
		var n = ignore.length;
		for(var i = 0; i < n; i++) {
			http.body["ignore[" + i + "]"] = ignore[i];
		}
		http.onerror = function() {};
		http.request("post", "/ajax/get_online_girl.php");
	};

	root.insertBefore(obj, root.firstChild);
	root.insertBefore(nn, obj);
	addEvent(btn, "click", replaceVideo);

	replaceVideo();
})();

