window.onload = function(){
  for(var i=0; i<document.links.length; i++) {
    if((document.links[i].hostname != "")&&
(document.links[i].hostname != "kilinbox.net")&&
(document.links[i].hostname != "kilinbox.ath.cx")&&
(document.links[i].hostname != "kilinbox.com")&&
(document.links[i].hostname != "kilinbox.jp")) {
      document.links[i].target="_blank";
    }
  }
};

function clearVideoList()
{
	document.videoForm.keywords.value = "";
	document.videoForm.keywords.removeAttribute('disabled');
	//clearTimeout(timerIDV);
	dataReloadVideo();
};

function videoSearch(num)
{
	var keywords = document.videoForm.keywords.value;
	keywords = keywords.replace(/^\s+|\s+$/g, "");
	keywords = keywords.replace("\\","\\\\");

	if (keywords=="") return;
	document.videoForm.keywords.setAttribute('disabled','true');

	keywords = encodeURI(keywords);
	keywords = keywords.replace(/\&/g,"%26");
	keywords = keywords.replace(/\+/g,"%2b");
	keywords = keywords.replace(/\#/g,"%23");

	httpVObj = createXMLHttp();
	httpVObj.onreadystatechange = function(){
		if ((httpVObj.readyState == 4) && (httpVObj.status == 200)) {
			var contents = parseJSONV(httpVObj.responseText);
			document.getElementById("video_result").innerHTML = contents;
			document.getElementById("video_navi").innerHTML = "";
			if(contents!="") document.getElementById("video_navi").innerHTML += '<a href="JavaScript:onclick=videoSearch('+(num+10)+')">前の10件</a>';
			if (num>0) document.getElementById("video_navi").innerHTML+=' | <a href="JavaScript:onclick=videoSearch('+(num-10)+')">次の10件</a>';
		}
	}
	if (httpVObj)
	{
		httpVObj.open("GET","read_mytube.php?num="+num+"&q="+keywords,true);
		httpVObj.setRequestHeader("content-type", "application/x-www-form-urlencoded;charset=UTF-8");
		httpVObj.send(null);
	}

	//clearTimeout(timerIDV);
};

function createXMLHttp(){
	var xmlhttp;
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
};

function dataLoadVideo(num)
{
	httpVObj = createXMLHttp();
	httpVObj.onreadystatechange = function(){
		if ((httpVObj.readyState == 4) && (httpVObj.status == 200)) {
			var contents = parseJSONV(httpVObj.responseText);
			document.getElementById("video_result").innerHTML = contents;
			document.getElementById("video_navi").innerHTML = "";
			if(contents!="") document.getElementById("video_navi").innerHTML += '<a href="JavaScript:onclick=dataLoadVideo('+(num+10)+')">前の10件</a>';
			if (num>0) document.getElementById("video_navi").innerHTML+=' | <a href="JavaScript:onclick=dataLoadVideo('+(num-10)+')">次の10件</a>';
		}
	}
	if (httpVObj)
	{
		httpVObj.open("GET","read_mytube.php?num="+num,true);
		httpVObj.setRequestHeader("content-type", "application/x-www-form-urlencoded;charset=UTF-8");
		httpVObj.send(null);
	}

	//clearTimeout(timerIDV);
	//timerIDV = setTimeout("dataLoadVideo("+num+")",1000);
};

function dataReloadVideo()
{
	httpVObj = createXMLHttp();

	httpVObj.onreadystatechange = function(){
		if ((httpVObj.readyState == 4) && (httpVObj.status == 200)) {
				document.getElementById("video_result").innerHTML = parseJSONV(httpVObj.responseText);
				document.getElementById("video_navi").innerHTML = '<a href="JavaScript:onclick=dataLoadVideo(10)">前の10件</a>';
		}
	}
	if (httpVObj)
	{
		httpVObj.open("GET",'read_mytube.php',true);
		httpVObj.setRequestHeader("content-type", "application/x-www-form-urlencoded;charset=UTF-8");
		httpVObj.send(null);
	}

	//timerIDV = setTimeout("dataReloadVideo()",1000);

};

// JSONのデータを解析して表示
function parseJSONV(jsData)
{
	eval(jsData)
	var resultData = data.num+"個検出<br/>";
	for(var i=0; i<data.item.length; i++) {
		
		if(data.item[i].type=="image") var itext = '<a href="JavaScript:onclick=ImagePlay(\''+data.item[i].filename+'\')">'+data.item[i].title+"</a>"+'　<a href="JavaScript:onclick=ImagePlayFull(\''+data.item[i].filename+'\')">[フルスクリーンで再生]</a>';
		else if(data.item[i].type=="ZOOMIFY") var itext = '<a href="JavaScript:onclick=ZoomifyPlay(\''+data.item[i].filename.substr(data.item[i].filename, data.item[i].filename.length-4)+'\')">'+data.item[i].title+"</a>"+'　<a href="JavaScript:onclick=ZoomifyPlayFull(\''+data.item[i].filename.substr(data.item[i].filename, data.item[i].filename.length-4)+'\')">[フルスクリーンで再生]</a>';
		else if(data.item[i].type=="FLV"||data.item[i].type=="H.264") var itext = '<a href="JavaScript:onclick=VideoPlay(\''+data.item[i].filename+'\')">'+data.item[i].title+"</a>";
		else if((data.item[i].type=="Flash")||(data.item[i].type=="FlashLite1.1")) var itext = '<a href="JavaScript:onclick=FlashPlay(\''+data.item[i].filename+'\')">'+data.item[i].title+"</a>"+'　<a href="JavaScript:onclick=FlashPlayFull(\''+data.item[i].filename+'\')">[フルスクリーンで再生]</a>';
		var itype = '<img src="';
		if(data.item[i].type=="image") itype+='./items/image.png';
		else if(data.item[i].type=="ZOOMIFY") itype+='./items/panolama.png';
		else if(data.item[i].type=="FLV"||data.item[i].type=="H.264") itype+='./items/video.png';
		else if((data.item[i].type=="Flash")||(data.item[i].type=="FlashLite1.1")) itype+='./items/flash.png';
		itype+='" style="vertical-align: middle;" />';
		var itime = data.item[i].year+"/"+data.item[i].month+"/"+data.item[i].day;
		resultData += itext+itype+'　<a href="index.php?diary='+data.item[i].year+data.item[i].month+data.item[i].day+'&category=diary#diary'+data.item[i].num+'">この記事はこちら</a>('+itime+")<br />";
	}
	return resultData;
};

function VideoPlay(fName)
{
  html='<object data="./swf/flvplayer_v3.swf" type="application/x-shockwave-flash" width="640" height="360" id="FLV">';
  html+='<param name="src" value="./swf/flvplayer_v3.swf" />';
  html+='<param name="FlashVars" value="cpath=http://kilinbox.net/images/'+fName+'" />';
  html+='<param name="allowFullScreen" value="true" />';
  html+='<param name="bgcolor" value="#000000" />';
  html+='</object>';
  document.getElementById("player_result").innerHTML = html;
};

function ImagePlay(fName)
{
  html='<object data="./swf/mytube_image.swf" type="application/x-shockwave-flash" width="640" height="360" id="FLV">';
  html+='<param name="src" value="./swf/mytube_image.swf" />';
  html+='<param name="FlashVars" value="cpath=./images/'+fName+'" />';
  html+='</object>';
  document.getElementById("player_result").innerHTML = html;
};

function ImagePlayFull(fName)
{
  var ms=navigator.appVersion.indexOf("MSIE");
  var ie4=(ms>0) && (parseInt(navigator.appVersion.substring(ms+5, ms+6)) >= 4)
  var nesc=navigator.appName.lastIndexOf("Netscape"); //一致した位置(0)を返す
  var nesc4=(nesc >= 0) && (parseInt(navigator.appVersion.substring(0,2)) >= 4);	html='<body style="margin:0px;background-color:#000">';
	html+='<object data="./swf/mytube_image.swf" type="application/x-shockwave-flash" width="100%" height="100%" id="FLV">';
	html+='<param name="src" value="./swf/mytube_image.swf" />';
	html+='<param name="FlashVars" value="cpath=./images/'+fName+'" />';
	html+='<param name="scale" value="exactfit" />';
	html+='</object>';
  if (nesc4){
    Mywin = window.open("about:blank","Mywin",
"scrollbars,width=" + window.screen.width + ",height=" + window.screen.height);
    Mywin.moveTo(0,0);
    Mywin.focus();
  }else if (ie4){
    Mywin = window.open("about:blank","screen","fullscreen=yes");
  }else{
  }
	Mywin.document.open();
	Mywin.document.write(html);
	Mywin.document.close();
};

function ZoomifyPlay(fName)
{
  html='<object data="./swf/zoomifyViewer.swf" type="application/x-shockwave-flash" width="640" height="360" id="Panolama">';
  html+='<param name="src" value="./swf/zoomifyViewer.swf" />';
  html+='<param name="FlashVars" VALUE="zoomifyImagePath=http://kilinbox.net/images/zoomify/'+fName+'" />';
  html+='<param name="quality" value="high" />';
  html+='<param name="previewImage" value="" />';
	html+='</object>';
  document.getElementById("player_result").innerHTML = html;
};

function ZoomifyPlayFull(fName)
{
  var ms=navigator.appVersion.indexOf("MSIE");
  var ie4=(ms>0) && (parseInt(navigator.appVersion.substring(ms+5, ms+6)) >= 4)
  var nesc=navigator.appName.lastIndexOf("Netscape"); //一致した位置(0)を返す
  var nesc4=(nesc >= 0) && (parseInt(navigator.appVersion.substring(0,2)) >= 4);	html='<body style="margin:0px;background-color:#000">';
	html+='<object data="./swf/zoomifyViewer.swf" type="application/x-shockwave-flash" width="100%" height="100%" id="Panolama">';
	html+='<param name="src" value="./swf/zoomifyViewer.swf" />';
	html+='<param name="FlashVars" VALUE="zoomifyImagePath=http://kilinbox.net/images/zoomify/'+fName+'" />';
	html+='<param name="scale" value="exactfit" />';
	html+='<param name="previewImage" value="" />';
	html+='</object>';
  if (nesc4){
    Mywin = window.open("about:blank","Mywin",
"scrollbars,width=" + window.screen.width + ",height=" + window.screen.height);
    Mywin.moveTo(0,0);
    Mywin.focus();
  }else if (ie4){
    Mywin = window.open("about:blank","screen","fullscreen=yes");
  }else{
  }
	Mywin.document.open();
	Mywin.document.write(html);
	Mywin.document.close();
};

function FlashPlay(fName)
{
  html='<object data="images/'+fName+'" type="application/x-shockwave-flash" width="500" height="500" id="Flash">';
  html+='<param name="src" value="images/'+fName+'" />';
  html+='<param name="quality" value="high" />';
  html+='<param name="wmode" value="opaque" />';
	html+='</object>';
  document.getElementById("player_result").innerHTML = html;
};

function FlashPlayFull(fName)
{
  var ms=navigator.appVersion.indexOf("MSIE");
  var ie4=(ms>0) && (parseInt(navigator.appVersion.substring(ms+5, ms+6)) >= 4)
  var nesc=navigator.appName.lastIndexOf("Netscape"); //一致した位置(0)を返す
  var nesc4=(nesc >= 0) && (parseInt(navigator.appVersion.substring(0,2)) >= 4);	html='<object data="images/'+fName+'" type="application/x-shockwave-flash" width="100%" height="100%" id="Flash">';
  html+='<param name="src" value="images/'+fName+'" />';
  html+='<param name="quality" value="high" />';
  html+='<param name="wmode" value="opaque" />';
  html+='<param name="scale" value="exactfit" />';
	html+='</object>';
  if (nesc4){
    Mywin = window.open("about:blank","Mywin",
"scrollbars,width=" + window.screen.width + ",height=" + window.screen.height);
    Mywin.moveTo(0,0);
    Mywin.focus();
  }else if (ie4){
    Mywin = window.open("about:blank","screen","fullscreen=yes");
  }else{
  }
	Mywin.document.open();
	Mywin.document.write(html);
	Mywin.document.close();
};