	var ELEMENT_NODE  = 1;
	var TEXT_NODE     = 3;
	var loginStatusForSettingMenu = false;
	// 板選択時のスレッド表示数
	var THREAD_LIST_NUM = 3;
	// 板ポップアップ時のスレッド表示数
	var THREAD_MAX_NUM = 10;
	// 番組数
	var CHANNEL_NUM = 8;
	// 表示設定ウィンドウ
	var propWin = null;
	// URL履歴ウィンドウ
	var historyWin = null;
	// スレッド用タイマーオブジェクト
	var tTimer = null;
	// 板用タイマーオブジェクト
	var bTimer = null;
	// 広告バナータイマーオブジェクト
	var adTimer = null;
	// スレッドスクロールタイマーオブジェクト
	var scTimer = null;
	//自動消滅レイヤータイマー
	var autoProgramListHiddenTimer = null;
	var autoTitleListHiddenTimer = null;
	var autoRelationHiddenTimer = null;
	var autoTypePreviewHiddenTimer = null;
	var systemMessageClearTimer = null;
	//
	//透過メニュー制御用オブジェクト
	var menuCtrl = null;
	var statisticMenuCtrl = null;
	// 
	var scTimeout = null;
	// アクティブユーザ用タイマーオブジェクト
	var activationTimer = null;
	// 即時アクティブユーザ更新フラグ
	var immediateUpdate = true;
	// メッセージ送信中かそうでないか
	var sendFlg = false;
	var threadLen = 0;
	var xmlfilename = "";
	// レス数
	var resNum = 0;
	// スレッドDOM
	var threadDom = null;
	// 
	var threadArray = new Array();
	var threadArraySide = new Array();
	// スクロールフラグ
	var scrollFlg = true;
	// スレッド文字色
	var font_color = "#000000";
	// スレッド背景色
	var bg_color = "#FFFFFF";
	// フォントサイズ
	var threadFontSize = 9;
	var threadFontFamily = "";
	var today  = 0;
	var chIdList = new Array("1ch","3ch","4ch","6ch","8ch","10ch","12ch","UHF");
	var chNumberAnalog = new Array("1","3","4","6","8","10","12","99");
	var chNameList = new Array("livenhk","liveetv","liventv","livetbs","livecx","liveanb","livetx","weekly");
	var chNamejpList = new Array("番組ch(NHK)","番組ch(教育)","番組ch(NTV)","番組ch(TBS)","番組ch(フジ)","番組ch(朝日)","番組ch(TX)","(UHF)");
	var chNamejpLongList = new Array("NHK総合","NHK教育","日テレ","ＴＢＳ","フジテレビ","テレ朝","テレ東","関東UHF");
	var nowFocusCh = null;
	var boardmainScrollval=0;
	var lastScrollPosition = -1;

	/* スレッドタイトルリスト */
	var nhk1TitleList = null;
	var nhk3TitleList = null;
	var ntvTitleList  = null;
	var tbsTitleList  = null;
	var cxTitleList   = null;
	var exTitleList   = null;
	var txTitleList   = null;
	var topTitleList  = null;
	var threadTitleList = new Array(CHANNEL_NUM);

	var tmpId = null;
	var initId = null;
	var currentThreadId = null;
	var loginFlg = false;
	var ballooMode = false;
	var mixMode = false;
	var errorCount = 0;
    var _2chUrl = null
	var prevOriginalThreadID = null;
	var barChartData = new Array();
	var resStatistics = new Array();
	var connStatistics = new Array();

	var tmpFontSize = 9;
	var tmpColorSet = '03';
	var threadColorSet = '03';
	var boardMax = false;
	var scrollMaxX = null;
	var agentIE = 0;
	var agentSafari = 0;
	var agentOpera = 0;
	
	var callBackMeter = null;
	var callBackGraph = null;
	var top3Thread = new Array();
	
	var firstTimeSelectThread = true;
	
	//スクロールステータス
	var _scrollStatus = false;

	//Flash設定ダイアログ管理
	var _onFLashSettingDialog = false;
	
	if(navigator.userAgent.toUpperCase().indexOf("MSIE") > 0) {
		agentIE = 1;
	}
	if(navigator.userAgent.toUpperCase().indexOf("SAFARI") > 0) {
		agentSafari = 1;
	}
	if(navigator.userAgent.toUpperCase().indexOf("OPERA") > 0) {
		agentOpera = 1;
	}

	var iphoneSubWindow = null;
	var nowTitle = null;
	
	var scrollerFontSize = 16;
	var scrollerFontColor = "#FFFFFF";
	var scrollerThreadLoopTime = 3000;

	// タイマー起動
	function mStartWatch(obj, methodName, time) {
		mStopWatch(obj);
		obj = setInterval(methodName, time);
		return obj;
	}

	// タイマー停止
	function mStopWatch(obj) {
		if(obj){
			clearInterval(obj);
			obj = null;
		}
	}

	/* 板初期化 */
	function initBoard(){
		initBoardreq = xmlHttpRequest();
		initBoardreq.onreadystatechange = function(){
			if (initBoardreq.readyState == 4) {
	            if (initBoardreq.status == 200) {
					board = initBoardreq.responseXML.getElementsByTagName("board");
					setThreadTitle(board);
					callBackGraph(topTitleList);
					callBackMeter(topTitleList);
					
					//topTitleList[j][0]  // 番組名
					//topTitleList[j][1]  // レス数
					//topTitleList[j][2]  // レス率
					//topTitleList[j][3]  // 接続数
					//topTitleList[j][0]  // 接続率

					// スレッド初期化
					if(initId == null || initId.length < 1) {
						// レス率の高いチャンネルを初期表示
						var index = 0;
						var value = 0;
						for(var i = 0; i < topTitleList.length; i++) {
							if(topTitleList[i][2] > value) {
								index = i;
								value = topTitleList[i][2];
							}
						}
						initId = chNameList[index]+"_";
					}

					selectThread(toChId(initId), initId);
	            } else {
	                errorRes("番組リストを取得できませんでした。");
	            }
			}
	    }

	    /* HTTPリクエスト実行 */
	    initBoardreq.open("GET", "/balloo/cgi/boardlist.php" , true);
	    initBoardreq.setRequestHeader("Cache-Control", "no-cache");
	    initBoardreq.setRequestHeader("Pragma", "no-cache");
	    initBoardreq.send(null);
	}
	
	function systemMessageClear() {
		if(systemMessageClearTimer != null) {
			clearInterval(systemMessageClearTimer);
			systemMessageClearTimer=null;
		}
		document.getElementById('system_message').innerHTML = "&nbsp;";
	}

	/* 板自動更新 */
	function boardUpdate(){
		initBoardreq = xmlHttpRequest();
		initBoardreq.onreadystatechange = function(){
			if (initBoardreq.readyState == 4) {
	            if (initBoardreq.status == 200) {
					board = initBoardreq.responseXML.getElementsByTagName("board");
					setThreadTitle(board);
					callBackGraph(topTitleList);
					callBackMeter(topTitleList);
	            } else {
	                errorRes("番組リストを取得できませんでした。");
	            }
			}
	    }

	    /* HTTPリクエスト実行 */
	    initBoardreq.open("GET", "/balloo/cgi/boardlist.php" , true);
	    initBoardreq.setRequestHeader("Cache-Control", "no-cache");
	    initBoardreq.setRequestHeader("Pragma", "no-cache");
	    initBoardreq.send(null);
	}

	/* 局ごとのスレッドリストセット */
	function setThreadTitle(board){
		topTitleList  = new Array('', '', '', '', '', '', '', '');

		for(i = 0; i < CHANNEL_NUM; i++){
			threadTitleList[i] = new Array();
			topTitleList[i] = new Array();
		}
		
		len = board.length;
		for(i = 0; i < len; i++){
			switch(board.item(i).getAttribute("name")){
				case chNameList[0]:
					if(threadTitleList[0].length <= 0){
						topTitleList[0] = new Array(board.item(i).getAttribute("threadname"), board.item(i).getAttribute("res"), board.item(i).getAttribute("res_statistics"), board.item(i).getAttribute("conn"), board.item(i).getAttribute("conn_statistics"));
					}
					threadTitleList[0].push(new Array(board.item(i).getAttribute("threadname"), board.item(i).getAttribute("filename"), board.item(i).getAttribute("href")));
					break;
				case chNameList[1]:
					if(threadTitleList[1].length <= 0){
						topTitleList[1] = new Array(board.item(i).getAttribute("threadname"), board.item(i).getAttribute("res"), board.item(i).getAttribute("res_statistics"), board.item(i).getAttribute("conn"), board.item(i).getAttribute("conn_statistics"));
					}
					threadTitleList[1].push(new Array(board.item(i).getAttribute("threadname"), board.item(i).getAttribute("filename"), board.item(i).getAttribute("href")));
					break;
				case chNameList[2]:
					if(threadTitleList[2].length <= 0){
						topTitleList[2] = new Array(board.item(i).getAttribute("threadname"), board.item(i).getAttribute("res"), board.item(i).getAttribute("res_statistics"), board.item(i).getAttribute("conn"), board.item(i).getAttribute("conn_statistics"));
					}
					threadTitleList[2].push(new Array(board.item(i).getAttribute("threadname"), board.item(i).getAttribute("filename"), board.item(i).getAttribute("href")));
					break;
				case chNameList[3]:
					if(threadTitleList[3].length <= 0){
						topTitleList[3] = new Array(board.item(i).getAttribute("threadname"), board.item(i).getAttribute("res"), board.item(i).getAttribute("res_statistics"), board.item(i).getAttribute("conn"), board.item(i).getAttribute("conn_statistics"));
					}
					threadTitleList[3].push(new Array(board.item(i).getAttribute("threadname"), board.item(i).getAttribute("filename"), board.item(i).getAttribute("href")));
					break;
				case chNameList[4]:
					if(threadTitleList[4].length <= 0){
						topTitleList[4] = new Array(board.item(i).getAttribute("threadname"), board.item(i).getAttribute("res"), board.item(i).getAttribute("res_statistics"), board.item(i).getAttribute("conn"), board.item(i).getAttribute("conn_statistics"));
					}
					threadTitleList[4].push(new Array(board.item(i).getAttribute("threadname"), board.item(i).getAttribute("filename"), board.item(i).getAttribute("href")));
					break;
				case chNameList[5]:
					if(threadTitleList[5].length <= 0){
						topTitleList[5] = new Array(board.item(i).getAttribute("threadname"), board.item(i).getAttribute("res"), board.item(i).getAttribute("res_statistics"), board.item(i).getAttribute("conn"), board.item(i).getAttribute("conn_statistics"));
					}
					threadTitleList[5].push(new Array(board.item(i).getAttribute("threadname"), board.item(i).getAttribute("filename"), board.item(i).getAttribute("href")));
					break;
				case chNameList[6]:
					if(threadTitleList[6].length <= 0){
						topTitleList[6] = new Array(board.item(i).getAttribute("threadname"), board.item(i).getAttribute("res"), board.item(i).getAttribute("res_statistics"), board.item(i).getAttribute("conn"), board.item(i).getAttribute("conn_statistics"));
					}
					threadTitleList[6].push(new Array(board.item(i).getAttribute("threadname"), board.item(i).getAttribute("filename"), board.item(i).getAttribute("href")));
					break;
				case chNameList[7]:
					if(threadTitleList[7].length <= 0){
						topTitleList[7] = new Array(board.item(i).getAttribute("threadname"), board.item(i).getAttribute("res"), board.item(i).getAttribute("res_statistics"), board.item(i).getAttribute("conn"), board.item(i).getAttribute("conn_statistics"));
					}
					threadTitleList[7].push(new Array(board.item(i).getAttribute("threadname"), board.item(i).getAttribute("filename"), board.item(i).getAttribute("href")));
					break;
				default:
					break;
			}
		}
	}
	
	/* 初期表示チャンネル取得スレッド */
	function getCookieValue(cookieName){
		cookie_value = "";
		if(window.navigator.cookieEnabled){
			if(document.cookie){
				cookies = document.cookie.split("; ");
				for(i = 0; i < cookies.length; i++){
					str = cookies[i].split("=");
					if(str[0] == cookieName){
						cookie_value = unescape(str[1]);
						break;
					}
				}
			}
		}
		return cookie_value;
	}

	function setCookie(key, value) {
		if(window.navigator.cookieEnabled){
			nowtime = new Date().getTime();
			clear_time = new Date(nowtime + (60 * 60 * 24 * 1000 * 365));
			expires = clear_time.toGMTString();
			document.cookie = key + "=" + value + "; expires=" + expires;
		}
	}

	function dat(res, no, time, who, originalNo, originalTID) {
		this.res = res;
		this.no = no;
		this.time = time;
		this.who = who;
		this.originalNo = originalNo;
		this.originalTID = originalTID;
	}

	/* スレッド差分取得 */
	function threadUpdate_iphone(id) {
		xmlhttp = xmlHttpRequest();
		xmlhttp.onreadystatechange = function(){
	        if (xmlhttp.readyState == 4) {
	            if (xmlhttp.status == 200) {
	            	errorCount = 0;
	            	speak = xmlhttp.responseXML.getElementsByTagName("speak");
	            	len = speak.length;
	            	var str = "";
					if(len > 0){
						// 取得したレス数
						len = speak.length;
						for(i = 0; i < len; i++){
							// 改行文字をbrタグに置換
							// アンカータグ変換
							str = "　　ID:" + speak.item(i).getAttribute("who") + "<br/>";
							str += speak.item(i).childNodes[0].nodeValue;
							str = str.replace(/\n/g, "<br/>");
							str = str.replace(/&#60;/g, "<");
							str = str.replace(/&#62;/g, ">");
							var originalNo = speak.item(i).getAttribute("originalNum");
							var originalID = speak.item(i).getAttribute("originalID");
							threadArray.push(new dat(str, speak.item(i).getAttribute("no"), speak.item(i).getAttribute("timestamp"), speak.item(i).getAttribute("who"), originalNo, originalID));
						}
						if(scTimer == null){
							scTimer = mStartWatch(scTimer, "showThread_iphone()", 200);
						}
					}
					
					var title = xmlhttp.responseXML.getElementsByTagName("thread").item(0).getAttribute("title");
					var ch_id = xmlhttp.responseXML.getElementsByTagName("thread").item(0).getAttribute("channel");
				} else {
		            if(xmlhttp.status == 400){
		            	// 引数lastnoが不正
						errorRes("リクエストが不正です。");
		            }else if(xmlhttp.status == 404){
		            	// スレッドXMLファイルがない
						errorRes("スレッドが見つかりませんでした。");
		            }else{
		            	// そのほかのエラー
						errorRes("レスポンスを取得できませんでした。");
		            }
					errorCount++;
					if(errorCount > 11) {
						mStopWatch(tTimer);
						tTimer=null;
		            	errorCount = 0;
					}
				}
	        }
		}

	    /* HTTPリクエスト実行 */
	    reqTime = new Date();
		if(threadArray && threadArray.length > 0) {
		    xmlhttp.open("GET", "/balloo/cgi/getthread.php?thread_id=" + id + "&lastno=" + threadArray[threadArray.length - 1].no, true);
		}else{
		    xmlhttp.open("GET", "/balloo/cgi/getthread.php?thread_id=" + id + "&lastno=0", true);
		}
	    xmlhttp.setRequestHeader("Cache-Control", "no-cache");
	    xmlhttp.setRequestHeader("Pragma", "no-cache");
	    xmlhttp.send(null);
	}

	/* スレッドスクロール */
	function scrollThread(sc){
		targetNode = document.getElementById('boardmain');
		if(scrollFlg && targetNode.scrollTop <= targetNode.scrollHeight){
			targetNode.scrollTop += sc;
		}else{
			mStopWatch(scTimeout);
			scTimeout = null;
		}
	}
	
	/* スレッドエリアにエラーメッセージ表示 */
	function errorRes(errorres){
		alert(errorres);
	}
	
	/* 広告バナー入れ替え */
	function bannerChange(){
		bannerReq = xmlHttpRequest();
		bannerReq.onreadystatechange = function(){
			if (bannerReq.readyState == 4) {
	            if (bannerReq.status == 200) {
					banner = bannerReq.responseText.split("\n", 2);
					ad1ImgNode = document.getElementById("ad1img");
					ad1ImgNode.removeAttribute("src");
					srcAttr = document.createAttribute("src");
					srcAttr.value = banner[0];
					ad1ImgNode.setAttributeNode(srcAttr);
					
					ad1LinkNode = document.getElementById("ad1link");
					ad1LinkNode.removeAttribute("href");
					hrefAttr = document.createAttribute("href");
					hrefAttr.value = banner[1];
					ad1LinkNode.setAttributeNode(hrefAttr);
	            } else {
	                window.alert("通信エラーが発生しました。" + bannerReq.status);
	            }
			}
	    }

	    /* HTTPリクエスト実行 */
	    bannerReq.open("GET", "./cgi/getbanner.php" , true);
	    bannerReq.send(null);
	}

	function addNode() {
		if(noText()) {
			return;
		}
		var textAreaValue = document.getElementById('input_area').value;
		var targetNode = document.getElementById('boardmain');
		var newTrNode = document.createElement("tr");
		var newTdLeftNode  = document.createElement("td");
		var newTdRightNode = document.createElement("td");
		var newAttrWidhtLeft  = document.createAttribute("width");
		var newAttrWidhtRight = document.createAttribute("width");
		var newTextLeftNode  = document.createTextNode(new String(targetNode.getElementsByTagName("tr").length+1));
		var newAttrValign = document.createAttribute("valign");
		var newAttrStyle = document.createAttribute("style");

		newTdLeftNode.appendChild(newTextLeftNode);

		textAreaValue.replace(">", "&gt;");
		textAreaValue.replace("<", "&lt;");
		if(textAreaValue.indexOf("\n") >= 0) {
			var texts = textAreaValue.split("\n");
			for(var i=0;i<texts.length;i++) {
				if(i > 0 ) {
					newTdRightNode.appendChild(createBRNode());
				}
				newTdRightNode.appendChild(document.createTextNode(texts[i]));
			}
		}else{
			newTdRightNode.appendChild(document.createTextNode(textAreaValue));
		}

		newAttrWidhtLeft.value  ='5%';
		newAttrWidhtRight.value ='95%';
		newAttrValign.value  ='top';
		newTdLeftNode.setAttributeNode(newAttrWidhtLeft);
		newTdLeftNode.setAttributeNode(newAttrValign);
		newTdRightNode.setAttributeNode(newAttrWidhtRight);

		newTrNode.appendChild(newTdLeftNode);
		newTrNode.appendChild(newTdRightNode);

		var targetTable = targetNode.getElementsByTagName("tr").item(0).parentNode;
		targetTable.appendChild(newTrNode);
		targetNode.scrollTop = targetNode.scrollHeight;
		document.getElementById('input_area').value = "";
	}

	function noText() {
		var textAreaValue = document.form1.input_area.value;
		textAreaValue.replace(" ", "");
		textAreaValue.replace("　", "");
		if(textAreaValue.length > 0) {
			return false;
		}
		return true;
	}

	function turnOn(chId) {
		var offId = toChId(initId);
		if(offId != null) {
			document.getElementById(offId+'_base').getAttributeNode('class').nodeValue = 'ch'+offId.slice(0,-2)+'_base_off';
		}
		if(chId != null) {
			document.getElementById(chId+'_base').getAttributeNode('class').nodeValue = 'ch'+chId.slice(0,-2)+'_base_on';
		}
	}

	function toChId(chName) {
		var chId = null;
		if(chName != null) {
			if(chName.indexOf('_') != -1) {
				chName = chName.substring(0,chName.indexOf('_'));
			}
			for(var i = 0; i < chNameList.length; i++) {
				if(chNameList[i] == chName) {
					chId = chIdList[i];
					break;
				}
			}
		}
		return chId;
	}
	
	function toAnalogChNum(chName) {
		var chAnaNum = null;
		if(chName != null) {
			if(chName.indexOf('_') != -1) {
				chName = chName.substring(0,chName.indexOf('_'));
			}
			for(var i = 0; i < chNameList.length; i++) {
				if(chNameList[i] == chName) {
					chAnaNum = chNumberAnalog[i];
					break;
				}
			}
		}
		return chAnaNum;
	}

	function toChIndex(chName) {
		if(chName != null) {
			if(chName.indexOf('_') != -1) {
				chName = chName.substring(0,chName.indexOf('_'));
			}
			for(var i = 0; i < chNameList.length; i++) {
				if(chNameList[i] == chName) {
					return i;
				}
			}
		}
		return -1;
	}

	/* スレッド選択 */
	function selectThread(ch_id, id) {
		initId = id;
		// Cookieが使用可能ならチャンネル情報をCookieに入れる
		setCookie("channel", escape(id.substring(0, id.indexOf("_") + 1)));
		threadLen = 0;
		mStopWatch(tTimer);
		tTimer=null;
	}

	// 発言更新時にFlashから呼び出される関数
	function updateThreadInfo(threadId, threadTitle) {
		currentThreadId = threadId;
//		document.title = "Balloo.jp - " + threadTitle;
		document.title = "Balloo.jp";
		_2chUrl = get2chUrl(initId.substring(0, initId.indexOf("_")+1), initId);
		if(immediateUpdate) {
			immediateUpdate = false;
			activate();
		}
	}

	function get2chUrl(label, filename) {
		var templabel =  label.indexOf("_") > 0 ? label.substring(0, label.indexOf("_")) : label;
		for(var i=0;i<chNameList.length;i++) {
			if(templabel == chNameList[i]) {
				var threadTitle = threadTitleList[i];
				if(filename == label+".xml") {
					return threadTitle[0][2];
				}
				for(var j=0;j<threadTitle.length;j++) {
					if(threadTitle[j][1].indexOf(filename) >= 0) {
						return threadTitle[j][2];
					}
				}
				return threadTitle[0][2];
			}
		}
	}

	/* レスアンカーポップアップ */
	function showRelation(resno, suffix) {
		//TODO
		//
		//
		return;
	}

	function createBRNode() {
		return document.createElement("br");
	}

	function getOffsetTop(obj) {
		if(obj.parentNode) {
			if(obj.nodeName.toLowerCase() == 'td') {
				return 0 + getOffsetTop(obj.parentNode);
			}else{
				return obj.offsetTop + getOffsetTop(obj.parentNode);
			}
		}else{
			if(obj.offsetTop) {
				return obj.offsetTop;
			}
		}
		return 0;
	}

	function getOffsetLeft(obj) {
		if(obj.parentNode) {
			if(obj.nodeName.toLowerCase() == 'tr') {
				return 0 + getOffsetLeft(obj.parentNode);
			}else{
				return obj.offsetLeft + getOffsetLeft(obj.parentNode);
			}
		}else{
			if(obj.offsetTop) {
				return obj.offsetLeft;
			}
		}
		return 0;
	}

	function hiddenLayer(target) {
		var dialogNode = document.getElementById(target); 
		dialogNode.style.visibility='hidden';
	}

	function setScrollTop(top, height) {
		var scrollMax = document.getElementById('boardmain').scrollHeight;
		boardmainScrollval = top;
	}

	function closeRelation() {
		var mainTableNode = document.getElementById('tablemain');
		var tableBgcolor  = mainTableNode.getAttributeNode('bgcolor');
		mStopWatch(autoRelationHiddenTimer);
		autoRelationHiddenTimer = null;
		hiddenLayer("relation");
	}

	/* メッセージ送信 */
	function sendInputMessage(){
		if(noText()){
			return ;
		}
		document.form1.input_area.disabled = false;
		document.form1.submit_btn.disabled = false;
		sendMessage(document.form1.input_area.value);
		document.form1.input_area.value = "";
	}

	function sendMessage(message) {
		sendFlg = true;
		messagePost = xmlHttpRequest();
	    /* レスポンスデータ処理用のコールバック関数を定義 */
		messagePost.onreadystatechange = function(){
	        if(messagePost.readyState == 4){
	            if(messagePost.status == 200){
					if(messagePost.responseText != "1"){
						errorRes("投稿に失敗しました。");
					}
	            }else if(messagePost.status == 400){
	                errorRes("メッセージ内容が不正です。<br/>文字数は500文字までです。");
	            }else if(messagePost.status == 404){
	            	errorRes("メッセージ送信に失敗しました。");
	            }
				if(ballooMode) {
					document.form1.input_area.disabled = false;
				}
				document.form1.submit_btn.disabled = false;
	            sendFlg = false;
	        }
		}

		var val = "message_body=" + encodeURI(message);
		val += "&thread_id=" + currentThreadId;
		val += "&user_id=" + tmpId;
	    /* HTTPリクエスト実行 */
	    messagePost.open("POST", "/balloo/cgi/send.php", true);
		messagePost.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
	    messagePost.send(val);
	}

	function sendByEnter(event) {
		if(event.keyCode == 13) {
			sendInputMessage();
		}
	}

	function mixModeControl(mode) {
		mixMode = mode;
		setCookie("mix_mode", mode ? "true" : "false");
		if(initId != null) {
			firstTimeSelectThread = true;
			selectThread(toChId(initId), initId);
		}
	}
	
	/* フォントサイズを上げる */
	function upFontSize(){
		if(threadFontSize <= 18){
			threadFontSize++;
			tablemain.style.fontSize = threadFontSize + "pt";
		}
	}
	
	/* フォントサイズを下げる */
	function downFontSize(){
		if(threadFontSize >= 6){
			threadFontSize--;
			tablemain.style.fontSize = threadFontSize + "pt";
		}
	}

	/* スレッド内文字色変更 */
	function changeFontColor(c){
		font_color = c;
		// Cookieが使用可能ならチャンネル情報をCookieに入れる
		setCookie("font_color", escape(font_color));
		document.getElementById("tablemain").style.color = c;
		node = document.getElementById("tablemain").getElementsByTagName("a");
		len = node.length;
		for(i = 0; i < len; i++){
			node.item(i).style.color = c;
		}
	}
	
	/* 背景色変更 */
	function changeBgColor(c){
		bg_color = c;
		// Cookieが使用可能ならチャンネル情報をCookieに入れる
		setCookie("bg_color", escape(bg_color));
		document.getElementById('tablemain').getAttributeNode('bgcolor').value = c;
	}
	
	function closeWindow(){
		if(propWin){
			propWin.close();
		}
		if(historyWin){
			historyWin.close();
		}
	}

	function trimString(value, length) {
		if(value.replace(/\[.+\]/,"") != null && value.replace(/\[.+\]/,"").length > 1) {
			value = value.replace(/\[.+\]/,"");
		}
		if(value.length >= length) {
			var newValue = value.substring(0, length-1);
			return newValue+"...";
		}
		return value;
	}

	function activate() {
		var userReq = xmlHttpRequest();
		userReq.onreadystatechange = function(){
			if (userReq.readyState == 4) {
				if (userReq.status == 200) {
					if(userReq.responseXML.getElementsByTagName("status")[0].firstChild.nodeValue == '0') {
						tmpId = userReq.responseXML.getElementsByTagName("guid")[0].firstChild.nodeValue;
						showUser();
					}
				}
			}
		}

		var val = "user_id=" + (tmpId != null ? encodeURI(tmpId) : "");
		val += "&thread_id=" + (currentThreadId != null ? encodeURI(currentThreadId) : "");
		/* HTTPリクエスト実行 */
		userReq.open("POST", "./cgi/activateuser.php" , true);
		userReq.setRequestHeader("Cache-Control", "no-cache");
		userReq.setRequestHeader("Pragma", "no-cache");
		userReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		userReq.send(val);
	}
	
	function resize() {
		var margin = 5;
		var mainLayerMargin = 20;
		var topMargin = 38;
		if(agentIE) {
			var bottomHeight = document.documentElement.clientHeight < defaultHeight ? 72 : 36;
			document.getElementById('bottom').style.top = document.documentElement.clientHeight - margin - bottomHeight;
			var h = document.documentElement.clientHeight - bottomHeight - mainLayerMargin - topMargin;
			itaH = h > 0 ? h : itaH;
			document.getElementById('wallpaper').style.width  = document.documentElement.clientWidth + "px";
			document.getElementById('wallpaper').style.height = (document.documentElement.clientHeight - 40) + "px";
			resizeBoard('ita', itaX, itaY, '80%', itaH);
		}
		else {
			var bottomHeight = window.innerHeight < defaultHeight ? 72 : 36;
			var h = window.innerHeight - bottomHeight - topMargin;
			itaH = h > 0 ? h : itaH;
			var x = isNaN(itaX) ? itaX : itaX + 'px';
			var y = isNaN(itaY) ? itaY : itaY + 'px';
			var w = isNaN(itaW) ? itaW : itaW + 'px';
			var innerH = itaH - document.getElementById('bottom').clientHeight;
			innerH = isNaN(innerH) ? innerH : innerH + 'px';
			h = isNaN(itaH) ? itaH+5 : (itaH+5) + 'px';
			document.getElementById('wallpaper').style.width = document.documentElement.clientWidth + "px";
			document.getElementById('wallpaper').style.height = (innerHeight - 60) + "px";
			resizeBoard('dummylayer', x, y, '80%', h);
			resizeBoard('ita', x, y, '100%', innerH);
		}
		if(flash) {
			flash.resizeBoard(getBoardSize());
		}
	}


	function getCutPxStringFromNumber(str) {
		var strNum = new String(str);
		if(strNum.toLowerCase().indexOf("px") > 0) {
			return strNum.substring(0, strNum.length - 2);
		}
		return strNum;
	}

	function getBoardSize() {
		var obj = document.getElementById('ita');
		var width = 0;
		if (isIE) {
			width = document.documentElement.scrollLeft + document.documentElement.clientWidth - 5;
		}else{
			width = innerWidth - 5;
		}
		var left = boardMax ? 25 : 130;
		width = width - left;
		var result = new Array(left,
							   getCutPxStringFromNumber(obj.top),
							   width, 
							   getCutPxStringFromNumber(obj.style.height));
		return result.join(",");
	}

	function insertBr(text, num) {
		var result = "";
		var count = 0;
		for (var i=0; i<text.length; i++) {
			var c = text.charAt(i);
			var n = escape(c);
			if (n.length < 4) {
				count++;
			} else {
				if(c.match("[｡-ﾟ]")) {
					count++;
				} else {
					count+=2;
				}
			}
			result += c;
			if(count >= num) {
				result += "<br/>";
				count = 0;
			}
		}
		return result;
	}

	function htmlspecialchars(target) {
		if(target == null) {
			return null;
		}
		var result = new String(target);
		result = result.replace("&", "&amp;");
		result = result.replace("\"", "&quot;");
		result = result.replace("'", "&#39;");
		result = result.replace("<", "&lt;");
		result = result.replace(">", "&gt;");
		return result;
	}

	function changeMode(mode) {
		switch(mode) {
			case 1:
				document.getElementById('mode1_btn').getAttributeNode('class').nodeValue = 'mode1_btn_on';
				document.getElementById('mode2_btn').getAttributeNode('class').nodeValue = 'mode2_btn_off';
				document.getElementById('mode3_btn').getAttributeNode('class').nodeValue = 'mode3_btn_off';
				setMode(true, true);
				break;
			case 2:
				document.getElementById('mode1_btn').getAttributeNode('class').nodeValue = 'mode1_btn_off';
				document.getElementById('mode2_btn').getAttributeNode('class').nodeValue = 'mode2_btn_on';
				document.getElementById('mode3_btn').getAttributeNode('class').nodeValue = 'mode3_btn_off';
				setMode(true, false);
				break;
			case 3:
				document.getElementById('mode1_btn').getAttributeNode('class').nodeValue = 'mode1_btn_off';
				document.getElementById('mode2_btn').getAttributeNode('class').nodeValue = 'mode2_btn_off';
				document.getElementById('mode3_btn').getAttributeNode('class').nodeValue = 'mode3_btn_on';
				setMode(false, true);
				break;
		}
		if(flash != null) {
			flash.changeMode(String(mode));
		}
	}

	function setMode(isBalloo, isMix) {
		if(!isBalloo) {
			// 2ch
			document.form1.input_area.disabled = true;
		} else {
			// balloo
			document.form1.input_area.disabled = false;
			document.form1.submit_btn.disabled = false;
		}
		ballooMode = isBalloo;
		mixModeControl(isMix);
		setCookie("balloo_mode", new String(ballooMode));
	}

	function showFontSizeSelect() {
		var select = document.getElementById('font_size_select');
		select.style.visibility = 'hidden';
		var pos = getPos(document.getElementById('size_img'));
		select.style.position = 'absolute';
		select.style.left = pos.x + 110;
		select.style.top = pos.y + 5;
		select.style.visibility = 'visible';
	}

	function getPos(elm) {
		var target = elm;
		var pos = new function() {
			this.x = 0;
			this.y = 0;
		}
		while(target) {
			pos.x += target.offsetLeft;
			pos.y += target.offsetTop;
			target = target.offsetParent;
		}
		return pos;
	}

	function saveSetting() {
		changeFontSize(tmpFontSize);
		changeFontFamily(document.form1.select_font_family.value);
		changeColorSet(tmpColorSet);
	}

	function closeSettingPanel(ok) {
		if(ok) {
			saveSetting();
		}
		var panel = document.getElementById('panel');
		panel.style.position = 'absolute';
		clearInnerHtml('setting_user_regist');
		clearInnerHtml('setting_user_edit');
		clearInnerHtml('setting_password');
		clearInnerHtml('setting_user_leave');

		// close
		hiddenLayer('setting_color');
		hiddenLayer('setting_type');
		hiddenLayer('setting_user_regist');
		hiddenLayer('setting_user_edit');
		hiddenLayer('setting_password');
		hiddenLayer('setting_user_leave');
		hiddenLayer('panel_btn02');
		hiddenLayer('panel_btn04');
		hiddenLayer('panel_btn05');
		hiddenLayer('panel');
		hiddenLayer('backscreen');
	}

	function clearInnerHtml(id) {
		document.getElementById(id).innerHTML = "";
	}

	function changeSettingTab(num) {
		var settingColor = document.getElementById('setting_color');
		var settingType = document.getElementById('setting_type');
		var settingUserRegist = document.getElementById('setting_user_regist');
		var settingUserEdit = document.getElementById('setting_user_edit');
		var settingPassword = document.getElementById('setting_password');
		var settingUserLeave = document.getElementById('setting_user_leave');

		settingColor.style.visibility = 'hidden';
		settingType.style.visibility = 'hidden';
		settingUserRegist.style.visibility = 'hidden';
		settingUserEdit.style.visibility = 'hidden';
		settingPassword.style.visibility = 'hidden';
		settingUserLeave.style.visibility = 'hidden';

		clearInnerHtml('setting_user_regist');
		clearInnerHtml('setting_user_edit');
		clearInnerHtml('setting_password');
		clearInnerHtml('setting_user_leave');

		switch(num) {
			case 1:
				settingColor.style.top = settingColor.parentNode.style.top + 10;
				settingColor.style.left = settingColor.parentNode.style.left + 110;
				settingColor.style.visibility = 'visible';
				break;
			case 2:
				selectFixedFormMessage(1);
				settingType.style.top = settingType.parentNode.style.top + 10;
				settingType.style.left = settingType.parentNode.style.left + 110;
				settingType.style.visibility = 'visible';
				break;
			case 3:
				settingUserRegist.innerHTML = getInnerHtmlRegistUserInput();
				settingUserRegist.style.top = settingUserRegist.parentNode.style.top + 10;
				settingUserRegist.style.left = settingUserRegist.parentNode.style.left + 110;
				settingUserRegist.style.visibility = 'visible';
				break;
			case 4:
				settingUserEdit.innerHTML = getInnerHtmlEditUserInput();
				editUserInit();
				settingUserEdit.style.top = settingUserEdit.parentNode.style.top + 10;
				settingUserEdit.style.left = settingUserEdit.parentNode.style.left + 110;
				settingUserEdit.style.visibility = 'visible';
				break;
			case 5:
				settingPassword.innerHTML = getInnerHtmlEditPasswordInput();
				editPasswordInit();
				settingPassword.style.top = settingPassword.parentNode.style.top + 10;
				settingPassword.style.left = settingPassword.parentNode.style.left + 110;
				settingPassword.style.visibility = 'visible';
				break;
			case 6:
				settingUserLeave.innerHTML = getInnerHtmlLeaveInput();
				leaveInit();
				settingUserLeave.style.top = settingUserLeave.parentNode.style.top + 10;
				settingUserLeave.style.left = settingUserLeave.parentNode.style.left + 110;
				settingUserLeave.style.visibility = 'visible';
				break;
		}
	}

	function setTmpFontSize() {
		var select = document.form1.select_font_size;
		tmpFontSize = select.options[select.selectedIndex].value;
	}

	function setTmpColor(colorSet) {
		tmpColorSet = colorSet;
	}
	
	function sortDescArray(arg1, arg2){
		if(arg1 == arg2) {
			return 0;
		}else
		if(arg1 > arg2) {
			return -1;
		}else{
			return 1;
		}
	}
	
	function round(num, decimalPlace) {
		var result = num;
		var m = Math.pow(10, decimalPlace);
		result = result * m;
		result = Math.round(result);
		result = result / m;
		return result;
	}

	function changeBoardArea() {
		boardMax = !boardMax;
		var left = boardMax ? "12px" : "170px";
		var width = boardMax ? "98%" : "80%";
		var visibility = boardMax ? "hidden" : "visible";

		document.getElementById("area_btn").getAttributeNode('class').nodeValue = boardMax ? "min_btn" : "max_btn";
		document.getElementById("head").style.left = left;
		document.getElementById("logo").style.visibility = visibility;
		document.getElementById("date_time").style.visibility = visibility;
		document.getElementById("statistics").style.visibility = visibility;
		itaX = left;
		itaW = width;
		if(agentIE) {
			resizeBoard('ita', left, document.getElementById("ita").style.top, width, document.getElementById('ita').style.height);
		}
		else {
			resizeBoard('dummylayer', left, document.getElementById("dummylayer").style.top, width, document.getElementById('dummylayer').style.height);
			resizeBoard('ita', left, document.getElementById("ita").style, "100%", document.getElementById('ita').style.height);
			document.getElementById("bottom").style.marginLeft = boardMax ? "170px" : "0px";
		}
		if(flash) {
			flash.resizeBoard(getBoardSize());
		}
	}

	function addRelationNoToText(no) {
		document.form1.input_area.value = ">>"+no+" "+document.form1.input_area.value;
	}

	//iphone
	function init_iphone(meterFunc, graphFunc) {

		callBackMeter = meterFunc;
		callBackGraph = graphFunc;
		
		var fontSize = getCookieValue("font_size");
		var fontFamily = getCookieValue("font_family");
		var colorSet = getCookieValue("color_set");

		ballooMode = true;
		mixModeControl(true);
		setCookie("balloo_mode", new String(true));

		// スレッド初期化(Cookieから初期表示チャンネルを読み込み)
		initId = getCookieValue("channel");

		// 板リスト初期化
		initBoard();
		startBoardUpdate();

		// アクティブユーザ用タイマー起動
		activationTimer = mStartWatch(activationTimer, "activate_iphone()", 60000);
		var statisticsLayer = document.getElementById("statistics");
	}

	function stopBoardUpdate() {
		mStopWatch(bTimer);
	}
	
	function startBoardUpdate() {
		// 板リスト自動更新用タイマー起動
		bTimer = mStartWatch(bTimer, "boardUpdate()", 2500);
	}

	function activate_iphone() {
		var userReq = xmlHttpRequest();
		userReq.onreadystatechange = function(){
			if (userReq.readyState == 4) {
				if (userReq.status == 200) {
					if(userReq.responseXML.getElementsByTagName("status")[0].firstChild.nodeValue == '0') {
						tmpId = userReq.responseXML.getElementsByTagName("guid")[0].firstChild.nodeValue;
					}
				}
			}
		}

		var val = "user_id=" + (tmpId != null ? encodeURI(tmpId) : "");
		val += "&thread_id=" + (currentThreadId != null ? encodeURI(currentThreadId) : "");
		/* HTTPリクエスト実行 */
		userReq.open("POST", "/balloo/cgi/activateuser.php" , true);
		userReq.setRequestHeader("Cache-Control", "no-cache");
		userReq.setRequestHeader("Pragma", "no-cache");
		userReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		userReq.send(val);
	}
	
	function threadView_iphone(ch, force) {
		if(boardMax || force) {
			if(ch == 1) {
				selectThread(chIdList[0], chNameList[0]+"_");
			}else
			if(ch == 3) {
				selectThread(chIdList[1], chNameList[1]+"_");
			}else
			if(ch == 4) {
				selectThread(chIdList[2], chNameList[2]+"_");
			}else
			if(ch == 6) {
				selectThread(chIdList[3], chNameList[3]+"_");
			}else
			if(ch == 8) {
				selectThread(chIdList[4], chNameList[4]+"_");
			}else
			if(ch == 10) {
				selectThread(chIdList[5], chNameList[5]+"_");
			}else
			if(ch == 12) {
				selectThread(chIdList[6], chNameList[6]+"_");
			}else
			if(ch == 99) {
				selectThread(chIdList[7], chNameList[7]+"_");
			}
			_scrollStatus = false;
		}
		setCookie("channel", escape(initId.substring(0, initId.indexOf("_") + 1)));
	}

	function scrollBottom_iphone() {
		var targetNode = document.getElementById('boardmain');
		targetNode.scrollTop = targetNode.scrollHeight;
	}
	
	function searchPeece() {
		var searchHTML = "http://peece.net/oudan/iphone/search.html?q="+nowTitle+"&all=1&sort_order=1&site_kind=1";
		hideThread_iphone();
		window.open(searchHTML, "peecenet");
	}

	function initThread_iphone(id, index, isFull){
		if(id == ""){
			errorRes("チャンネルを選択してください。");
			return ;
		}
		threadView_iphone(id, isFull)
		nowTitle = topTitleList[index][0];
		document.getElementById("thtitle").innerHTML = nowTitle;
		
		threadArray = new Array();
		threadDom = null;
		boardmainScrollval = 0;
		var initThreadreq = xmlHttpRequest();
		initThreadreq.onreadystatechange = function(){
	        if(initThreadreq.readyState == 4){
	            if(initThreadreq.status == 200){
	            	errorCount = 0;
	            	if(isFull) {
						speak = initThreadreq.responseXML.getElementsByTagName("speak");
						threadLen = speak.length;
						targetNode = document.getElementById('boardmain');
						targetNode.style.visibility = "visible";
						document.getElementById('closebutton').style.visibility = "visible";
						tableNode = document.getElementById('tablemain');
						tbody = document.getElementById('tbodymain');
						document.getElementById('sendmessage').style.visibility = "visible";
						for(i = 0; i < threadLen; i++){
							if((!ballooMode && !(speak.item(i).getAttribute("location") == '2ch' || speak.item(i).getAttribute("location") == 'system_2ch'))
								|| (ballooMode && !mixMode && (speak.item(i).getAttribute("location") == '2ch' || speak.item(i).getAttribute("location") == 'system_2ch'))) {
								continue;
							}
							newTrNode = document.createElement("tr");
							newAttrWidhtLeft  = document.createAttribute("width");
							newAttrExpLeftId  = document.createAttribute("expID");
							newAttrWidhtRight = document.createAttribute("width");
							newAttrValign = document.createAttribute("valign");
							newAttrStyle = document.createAttribute("class");
							newAttrAlignLeftToRightTd  = document.createAttribute("align");
							newAttrWidhtLeft.value  ='5%';
							newAttrExpLeftId.value  = speak.item(i).getAttribute("no");
							newAttrWidhtRight.value ='95%';
							newAttrValign.value  ='top';
							newAttrStyle.value = 'left_no';
							newAttrAlignLeftToRightTd.value = 'left';

							newTextLeftNode = document.createTextNode(speak.item(i).getAttribute("originalNum"));
							newTdLeftNode  = document.createElement("td");
							newTdRightNode = document.createElement("td");
							newTdLeftNode.setAttributeNode(newAttrStyle);
							newTdLeftNode.setAttributeNode(newAttrWidhtLeft);
							newTdLeftNode.setAttributeNode(newAttrValign);
							newTdLeftNode.setAttributeNode(newAttrExpLeftId);
							
							newTdRightNode.setAttributeNode(newAttrWidhtRight);
							newTdRightNode.setAttributeNode(newAttrAlignLeftToRightTd);
							newTdLeftNode.appendChild(newTextLeftNode);
							// 改行をbrタグに置換
							// 指定文字列をアンカータグに変換
							if(speak.item(i).getAttribute("location") == '2ch' || speak.item(i).getAttribute("location") == 'balloo') {
								str = "　　ID:" + speak.item(i).getAttribute("who") + "<br/>";
								str += speak.item(i).childNodes[0].nodeValue;
							}else{
								str = speak.item(i).childNodes[0].nodeValue;
							}
							str = str.replace(/\n/g, "<br/>");
							str = str.replace(/&#60;/g, "<");
							str = str.replace(/&#62;/g, ">");
							threadArray.push(new dat(str, speak.item(i).getAttribute("no"), speak.item(i).getAttribute("timestamp"), speak.item(i).getAttribute("who"), speak.item(i).getAttribute("originalNum"), speak.item(i).getAttribute("originalID")));
							newTdRightNode.innerHTML = str;
							
							newTrNode.appendChild(newTdLeftNode);
							newTrNode.appendChild(newTdRightNode);
							tbody.appendChild(newTrNode);
						}
						//DEBUG
						threadLen = threadArray.length;
						
						font_color = getCookieValue("font_color");
						if(font_color != "undefined" && font_color != ""){
							changeFontColor(font_color);
						}else{
							font_color ="#000000";
						}
						
						bg_color = getCookieValue("bg_color");
						if(bg_color != "undefined" && bg_color != ""){
							changeBgColor(bg_color);
						}else{
							bg_color = "#FFFFFF";
						}

			            targetNode.scrollTop = targetNode.scrollHeight;
						document.title = "Balloo.iPhone - ";
						initThreadreq.responseXML.getElementsByTagName("thread").item(0).getAttribute("serial");

						tTimer = mStartWatch(tTimer, "threadUpdate_iphone('" + initId + "')", 3000);
						currentThreadId = initThreadreq.responseXML.getElementsByTagName("thread").item(0).getAttribute("serial");
						activate_iphone();
	            	}else{
						currentThreadId = initThreadreq.responseXML.getElementsByTagName("thread").item(0).getAttribute("serial");
						activate_iphone();
	            	}
				} else {
		            if(initThreadreq.status == 400){
		            	// 引数lastnoが不正
		            	errorRes("スレッドを取得できませんでした。");
		            }else if(initThreadreq.status == 404){
		            	// スレッドXMLファイルがない
		            	errorRes("スレッドが見つかりませんでした。");
		            }else{
		            	// そのほかのエラー
		            	errorRes("スレッドの初期化に失敗しました。");
		            }
					errorCount++;
					if(errorCount > 11) {
						mStopWatch(tTimer);
						tTimer = null;
		            	errorCount = 0;
					}
				}

	        }
	    }

	    /* HTTPリクエスト実行 */
	    reqTime = new Date();
	    initThreadreq.open("GET", "/balloo/cgi/getthread.php?thread_id=" + initId + "&lastno=-30" , true);
	    initThreadreq.setRequestHeader("Cache-Control", "no-chace");
	    initThreadreq.setRequestHeader("Pragma", "no-chace");
	    initThreadreq.send(null);
	}
	
	function hideThread_iphone(){
		document.getElementById('boardmain').style.visibility = "hidden";
		document.getElementById('closebutton').style.visibility = "hidden";
		document.getElementById('sendmessage').style.visibility = "hidden";
		mStopWatch(tTimer);
		tTimer = null;
	}

	function errorRes_iphone(errorres){
			targetNode = document.getElementById('boardmain');
			tableNode = document.getElementById('tablemain');
			tbody = document.getElementById('tbodymain');
			newTrNode = document.createElement("tr");
			newAttrWidhtLeft  = document.createAttribute("width");
			newAttrWidhtRight = document.createAttribute("width");
			newAttrValign = document.createAttribute("valign");
			newAttrWidhtLeft.value  ='5%';
			newAttrWidhtRight.value ='95%';
			newAttrValign.value  ='top';
			newTextLeftNode = document.createTextNode("");
			newTdLeftNode  = document.createElement("td");
			newTdRightNode = document.createElement("td");
			newTdLeftNode.setAttributeNode(newAttrWidhtLeft);
			newTdLeftNode.setAttributeNode(newAttrValign);
			newTdRightNode.setAttributeNode(newAttrWidhtRight);
			newTdLeftNode.appendChild(newTextLeftNode);
			newTdRightNode.innerHTML = "<font color=\"red\">" + errorres + "</font>";
			newTrNode.appendChild(newTdLeftNode);
			newTrNode.appendChild(newTdRightNode);
			tbody.appendChild(newTrNode);
			targetNode.scrollTop = targetNode.scrollHeight;
			tableNode.appendChild(tbody);
		}

	/* スレッド表示 */
	function showThread_iphone() {
    	// speak = xmlhttp.responseXML.getElementsByTagName("speak");
    	// len = speak.length;
		if(threadLen < threadArray.length){
			// speak = xmlhttp.responseXML.getElementsByTagName("speak");
			targetNode = document.getElementById('boardmain');
			tableNode = document.getElementById('tablemain');
			tbody = document.getElementById('tbodymain');
			if(scrollFlg){
				targetNode.scrollTop = targetNode.scrollHeight;
			}
			// 取得したレス数
			// len = speak.length;
			// threadLen += len;
			// 現在表示されているのレス数
			// trLength = targetNode.getElementsByTagName("tr").length;
			len = threadArray.length;
			showTime = parseInt(threadArray[threadLen].time);
			for(i = threadLen; i < len; i++){
				if(showTime < parseInt(threadArray[i].time)){
					break;
				}
				
				newTrNode = document.createElement("tr");
				newAttrWidhtLeft  = document.createAttribute("width");
				newAttrExpLeftId  = document.createAttribute("expID");
				newAttrWidhtRight = document.createAttribute("width");
				newAttrValign = document.createAttribute("valign");
				newAttrAlignLeftToRightTd  = document.createAttribute("align");
				newAttrStyleRightTd = document.createAttribute("style");
				newAttrWidhtLeft.value  ='5%';
				newAttrExpLeftId.value  = threadArray[i].no;
				newAttrWidhtRight.value ='95%';
				newAttrValign.value  ='top';
				newAttrAlignLeftToRightTd.value = 'left';
				//TODO
				//FONT SIZE FIX!!
				//
				newAttrStyleRightTd.value = 'font-size:10px;';
				//
				//
				threadLen++;
				if(prevOriginalThreadID) {
					if(threadArray[i].originalTID != prevOriginalThreadID) {
						prevOriginalThreadID = threadArray[i].originalTID;
					}
				}else{
					prevOriginalThreadID = threadArray[i].originalTID;
				}
				var orgNum = new Number(threadArray[i].originalNo);
				if(orgNum > 0) {
					newTextLeftNode = document.createTextNode(threadArray[i].originalNo);
				}else{
					newTextLeftNode = document.createTextNode("*"+threadArray[i].no);
				}
				newTdLeftNode  = document.createElement("td");
				newTdRightNode = document.createElement("td");
				newTdLeftNode.setAttributeNode(newAttrWidhtLeft);
				newTdLeftNode.setAttributeNode(newAttrValign);
				newTdLeftNode.setAttributeNode(newAttrExpLeftId);
				newTdRightNode.setAttributeNode(newAttrWidhtRight);
				newTdRightNode.setAttributeNode(newAttrAlignLeftToRightTd);
				newTdRightNode.setAttributeNode(newAttrStyleRightTd);
				newTdLeftNode.appendChild(newTextLeftNode);

				newTdRightNode.innerHTML = threadArray[i].res;
				newTrNode.appendChild(newTdLeftNode);
				newTrNode.appendChild(newTdRightNode);
				tbody.appendChild(newTrNode);
			}
			// スレッドが1000を越えたら先頭から削除
			// sumHeight = targetNode.scrollHeight;
			tbodyLen = tbody.getElementsByTagName("tr").length - 1000;
			if(tbodyLen > 0){
				for(i = 0; i < tbodyLen; i++){
					tbody.removeChild(tbody.firstChild);
					threadLen--;
					threadArray.shift();
				}
			}
			
			if(scrollFlg){
				scHeight = targetNode.scrollHeight - targetNode.scrollTop;
				if(scHeight > 0){
					sc = scHeight / 10;
					scTimeout = mStartWatch(scTimeout, "scrollThread(" + sc + ")", 100);
				}
			}
			
		}
	}

	function deleteThread_iphone_side() {
		if(threadArraySide.length > 1){
			while(threadArraySide.length < 2){
				threadArraySide.shift();
			}
		}
	}
	
	function initThread_iphone_side(isFull, parentLayerID){
		var id = toAnalogChNum(initId);
		var index = toChIndex(initId);

		if(id == ""){
			errorRes("チャンネルを選択してください。");
			return ;
		}
		
		threadArraySide = new Array();
		threadDom = null;
		boardmainScrollval = 0;
		var initThreadreq = xmlHttpRequest();
		initThreadreq.onreadystatechange = function(){
	        if(initThreadreq.readyState == 4){
	            if(initThreadreq.status == 200){
	            	errorCount = 0;
	            	if(isFull) {
						speak = initThreadreq.responseXML.getElementsByTagName("speak");
						threadLen = speak.length;
						var messages = new Array();
						for(i = 0; i < threadLen; i++){
							if((!ballooMode && !(speak.item(i).getAttribute("location") == '2ch' || speak.item(i).getAttribute("location") == 'system_2ch'))
								|| (ballooMode && !mixMode && (speak.item(i).getAttribute("location") == '2ch' || speak.item(i).getAttribute("location") == 'system_2ch'))) {
								continue;
							}

							// 改行をbrタグに置換
							// 指定文字列をアンカータグに変換
							var str = speak.item(i).childNodes[0].nodeValue;
							str = str.replace(/&#60;/g, "<");
							str = str.replace(/&#62;/g, ">");
							messages[messages.length] = str;
							if(i+1 >= threadLen) {
								threadArraySide.push(new dat(str, speak.item(i).getAttribute("no"), speak.item(i).getAttribute("timestamp"), speak.item(i).getAttribute("who"), speak.item(i).getAttribute("originalNum"), speak.item(i).getAttribute("originalID")));
							}
						}
						
						var parentLayer = document.getElementById(parentLayerID);
						var scroller = new SideScroll(parentLayer, scrollerFontSize, scrollerFontColor, scrollerThreadLoopTime);
						scroller.start(messages);

						tTimer = mStartWatch(tTimer, "threadUpdate_iphone_side('" + initId + "','"+parentLayerID+"')", scrollerThreadLoopTime);
						currentThreadId = initThreadreq.responseXML.getElementsByTagName("thread").item(0).getAttribute("serial");
						activate_iphone();
	            	}else{
						currentThreadId = initThreadreq.responseXML.getElementsByTagName("thread").item(0).getAttribute("serial");
						activate_iphone();
	            	}
				} else {
		            if(initThreadreq.status == 400){
		            	// 引数lastnoが不正
		            	errorRes("スレッドを取得できませんでした。");
		            }else if(initThreadreq.status == 404){
		            	// スレッドXMLファイルがない
		            	errorRes("スレッドが見つかりませんでした。");
		            }else{
		            	// そのほかのエラー
		            	errorRes("スレッドの初期化に失敗しました。");
		            }
					errorCount++;
					if(errorCount > 11) {
						mStopWatch(tTimer);
						tTimer = null;
		            	errorCount = 0;
					}
				}

	        }
	    }

	    /* HTTPリクエスト実行 */
	    reqTime = new Date();
	    initThreadreq.open("GET", "/balloo/cgi/getthread.php?thread_id=" + initId + "&lastno=-30" , true);
	    initThreadreq.setRequestHeader("Cache-Control", "no-chace");
	    initThreadreq.setRequestHeader("Pragma", "no-chace");
	    initThreadreq.send(null);
	}

	function threadUpdate_iphone_side(id, parentLayerID) {
		xmlhttp = xmlHttpRequest();
		xmlhttp.onreadystatechange = function(){
	        if (xmlhttp.readyState == 4) {
	            if (xmlhttp.status == 200) {
	            	errorCount = 0;
	            	speak = xmlhttp.responseXML.getElementsByTagName("speak");
	            	len = speak.length;
	            	var str = "";
					if(len > 0){
						// 取得したレス数
						len = speak.length;
						var messages = new Array();
						for(i = 0; i < len; i++){
							// 改行文字をbrタグに置換
							// アンカータグ変換
							var str = speak.item(i).childNodes[0].nodeValue;
							str = str.replace(/&#60;/g, "<");
							str = str.replace(/&#62;/g, ">");
							messages[messages.length] = str;
							var originalNo = speak.item(i).getAttribute("originalNum");
							var originalID = speak.item(i).getAttribute("originalID");
							if(i+1 >= len) {
								threadArraySide.push(new dat(str, speak.item(i).getAttribute("no"), speak.item(i).getAttribute("timestamp"), speak.item(i).getAttribute("who"), originalNo, originalID));
							}
						}
						var parentLayer = document.getElementById(parentLayerID);
						var scroller = new SideScroll(parentLayer, scrollerFontSize, scrollerFontColor, scrollerThreadLoopTime);
						scroller.start(messages);
						deleteThread_iphone_side();
					}
					
				} else {
		            if(xmlhttp.status == 400){
		            	// 引数lastnoが不正
						errorRes("リクエストが不正です。");
		            }else if(xmlhttp.status == 404){
		            	// スレッドXMLファイルがない
						errorRes("スレッドが見つかりませんでした。");
		            }else{
		            	// そのほかのエラー
						errorRes("レスポンスを取得できませんでした。");
		            }
					errorCount++;
					if(errorCount > 11) {
						mStopWatch(tTimer);
						tTimer=null;
		            	errorCount = 0;
					}
				}
	        }
		}

	    /* HTTPリクエスト実行 */
	    reqTime = new Date();
		if(threadArraySide && threadArraySide.length > 0) {
		    xmlhttp.open("GET", "/balloo/cgi/getthread.php?thread_id=" + id + "&lastno=" + threadArraySide[threadArraySide.length - 1].no, true);
		}else{
		    xmlhttp.open("GET", "/balloo/cgi/getthread.php?thread_id=" + id + "&lastno=0", true);
		}
	    xmlhttp.setRequestHeader("Cache-Control", "no-cache");
	    xmlhttp.setRequestHeader("Pragma", "no-cache");
	    xmlhttp.send(null);
	}
