var lists = new Array();
var item = new Array();
var kana = new Array();
var sortedIndex = new Array();

var categoryString;
var detailMax = 10;
var listMax = 25;
var isSortedByKana = false;
var midashiHTML = '';

var iconNewHTML = new Array(2);
iconNewHTML[0] = '';
iconNewHTML[1] = '<img src="../../images/icon_new.gif" width="23" height="14" alt="new">';

var cnum =0;

var mode = 2;

var thisURL = '';
var targetNum = 0;

//コールバック関数 ( 受信時に実行されます )
  function on_loadedFootage(oj)
  {
    //responseXMLでレスポンスを取得
    var xdoc  =  oj.responseXML

    //詳細リストを出力
	cnum++
    putoutFootage(xdoc);
	//putoutList(0);
  }

  //送信用関数
  function loadFootage(url)
  {
    sendRequest(on_loadedFootage,'','GET',url,true,true) 
  }
  
  function putoutFootage(x){
	  var items = x.getElementsByTagName("item");
	  var lists =  x.getElementsByTagName("lists");
	  var n = 1;
	//  if(lists[0].attributes[0].value =='NHK Scoops'){
	  if(mode==1){
		  n = 1;
	  }else if(mode==2){
		  n = 2;
	  }
	  else{
		n = 3;  
	  }
	  var sampleView = '';
	  var html = ''
	//  html += '<h2>';
	//  html += lists[0].attributes[0].value;
	//  html += '</h2>';
	  for(var i=0; i<items.length; i++){
	    sampleView = '';
		html += '<div class="viewBox">';
		if(items[i].getElementsByTagName("sample").item(0).childNodes.length>0){
			sampleView += '<DIV class="sampleView">';
			sampleView += '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="160" height="144">';
			sampleView += '<PARAM name="movie" value="player_525.swf">';
			sampleView += '<PARAM name="quality" value="high">';
			sampleView += '<PARAM name="flashvars" value="movieFile=nf_flvs/'+items[i].getElementsByTagName("sample").item(0).firstChild.nodeValue+'&photoFile=nf_images/'+items[i].getElementsByTagName("images").item(0).firstChild.nodeValue+'&totalTime=67">';
			sampleView += '<EMBED src="player_525.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="160" height="144" flashvars="movieFile=nf_flvs/'+items[i].getElementsByTagName("sample").item(0).firstChild.nodeValue+'&photoFile=nf_images/'+items[i].getElementsByTagName("images").item(0).firstChild.nodeValue+'&totalTime=67">';
			sampleView += '</EMBED></OBJECT></DIV>';
		}else{
			sampleView += '<DIV class="sampleView" style="margin-bottom:24px;"><img src="nf_images/'+items[i].getElementsByTagName("images").item(0).firstChild.nodeValue+'" width="240px"></div>';
		}
		html += sampleView;
		dumpImg(sampleView);
		dumpClear();
		
		html += '<h3 class="title">';
		if(items[i].getElementsByTagName("name").length>0 && items[i].getElementsByTagName("name").item(0).childNodes.length>0){
			html +=  items[i].getElementsByTagName("name").item(0).firstChild.nodeValue;
		}
		html += '</h3>';
		html += '<p class="descript">';
		html +=  items[i].getElementsByTagName("info").item(0).firstChild.nodeValue;
		html += '</p>';
		html += '</div>'
	  }
	  document.getElementById("c"+n).innerHTML+=html+'<div class="clear"></DIV>';
  }
  

function filterByCode( tmpXml, tmpTarget ) {

	if ( !tmpXml || !tmpTarget ) {
		return tmpXml;
	}

	tmpTarget = tmpTarget.toUpperCase();

	var tags = document.location.href.match(/\#.*tag=([a-z,]*)/);

	if ( !tags || ( tags.length != 2 ) ) {
		tmpAction = false;
	}
	else {
		var tag = tags[1].toString().toUpperCase();
		if ( tmpTarget == tag ) {
			tmpAction = true;
		}
		else {
			tmpAction = false;
		}
	}

	var switchIsLoaded = document.getElementById('catalog-switcher') || false;
	if ( !switchIsLoaded ) {
		var switcher = document.createElement('div');
		switcher.setAttribute('id','catalog-switcher');
	}
	else {
		switcher = switchIsLoaded;
	}

	var catXML = document.body.getAttribute('onload').toString().split("'"),
		curLang = lang[ pagelang ];
	
	var msg = {
		'click': {
			e: '&gt;&gt; Click',
			j: '&gt;&gt; クリック'
		},
		'dft': {
			e: 'You can access to the International Versions of NHK programs produced by the Japan Media Communication Center (JAMCO) established in 1991 for the purpose of promoting international mutual understanding and contributing to the development of broadcast in the world.',
			j: '放送番組国際交流センター（JAMCO）が国際版を制作しているNHK番組にアクセスすることができます。'
		},
		'JAMCO': {
			e: 'Back to the list of NHK International.',
			j: 'NHKインターナショナル制作の映像一覧へ戻る'
		}
	};

	if ( !tmpAction ) {
		switcher.innerHTML = msg.dft[ curLang ] + ' <a href="#tag=jamco" onclick="document.location.href=this.href;loadFile(\'' + catXML[1] + curLang + '.xml\');document.body.className=\'' + tmpTarget.toLowerCase()  + '\';window.scrollTo(0,0);return false;">' + msg.click[ curLang ] + '</a>';
	}
	else {
		document.documentElement.className = tmpTarget.toLowerCase();
		switcher.innerHTML = msg[ tmpTarget  ][ curLang ] +  ' <a href="#tag=nhk" onclick="document.location.href=this.href;loadFile(\'' + catXML[1] + curLang + '.xml\');document.body.className=\'nhk\';window.scrollTo(0,0);return false;">' + msg.click[ curLang ] + '</a>';
	}

	if ( !switchIsLoaded ) {
		var content = document.getElementById('contents') || false;
		if ( content ) {
			var firstContentChild = content.childNodes[0];
			content.insertBefore( switcher, firstContentChild );
		}
	}

	var html = tmpXml.getElementsByTagName("lists")[0],
		defaultHTML = '<lists category="' + encodeURIComponent( html.getAttribute('category') ) + '"></lists>',
		newList;
	if ( document.implementation.createDocument ) {
   		var parser = new DOMParser(),
	    	doc = parser.parseFromString( defaultHTML, "application/xml" );
	     newList = doc.childNodes[0];
    	// MSIE
    } else if (window.ActiveXObject) {
       	var doc = document.createElement('div'),
       	newList = document.createElement('list');
       	newList.setAttribute('category', html.getAttribute('category') );
       	doc.appendChild( newList );      	
   	}

	document._importNode = function(oNode, bImportChildren) {
    	var oNew;
    	if ( oNode.nodeType == 1) {
        	 oNew = document.createElement(oNode.nodeName);
        	for ( var i = 0; i < oNode.attributes.length; i++ ) {
            	if ( oNode.attributes[i].nodeValue != null && oNode.attributes[i].nodeValue != '' ) {
                	var attrName = oNode.attributes[i].name;
    	           	if (attrName == "class") {
	                  	oNew.setAttribute("className", oNode.attributes[i].value);
		            } else {
		                oNew.setAttribute(attrName, oNode.attributes[i].value);
        	       	}
            	}
        	}
        	if(oNode.style != null && oNode.style.cssText != null) {
         	  	oNew.style.cssText = oNode.style.cssText;
    		}
	    } else if(oNode.nodeType == 3) {
        	oNew = document.createTextNode(oNode.nodeValue);
    	}

	    if ( bImportChildren && oNode.hasChildNodes() ) {
        	for ( var oChild = oNode.firstChild; oChild; oChild = oChild.nextSibling ) {
        		if ( ( oChild.nodeType == 1 ) || ( oChild.nodeType == 3 ) ) {
	            	oNew.appendChild( document._importNode( oChild, true ) );
	            }
        	}
    	}

    	return oNew;
	};

	for ( var j=0, tmpItems = html.getElementsByTagName('item'); j<tmpItems.length; j++ ) {
		var curItem = tmpItems[ j ],
			code = curItem.getElementsByTagName('code') || false;
		if ( code.length > 0 ) {
			var codeLabel = ( ( code[0].firstChild || {} ).nodeValue || '' ).toString().toUpperCase();
			if ( !tmpAction && ( tmpTarget != codeLabel ) ) {
				if ( !document.importNode ) {
					var newItem = document._importNode( curItem, true );
					newList.appendChild( newItem );
				}
				else {
					var newItem = document._importNode( curItem, true );
					newList.appendChild( newItem );
				}
			}
			else if ( tmpAction && ( tmpTarget == codeLabel ) ) {
				if ( !document.importNode ) {
					var newItem = document._importNode( curItem, true );
					newList.appendChild( newItem );
				}
				else {
					var newItem = doc.importNode( curItem, true );
					newList.appendChild( newItem );
				}
			}
		}
	}

	return doc;
}


//コールバック関数 ( 受信時に実行されます )
  function on_loadedXML(oj)
  {
    //responseXMLでレスポンスを取得
    var xdoc  =  filterByCode( oj.responseXML, 'JAMCO' );

	//XMLを配列に変換します
	//XML内の"name"という名前のタグ(要素)の配列を作る
    lists = xdoc.childNodes; //xdoc.getElementsByTagName("lists");

    //XML内の"name"という名前のタグ(要素)の配列を作る
    item = xdoc.getElementsByTagName("item");

	//XML内の"kana"という名前のタグ(要素)の配列を作る
	kana  = xdoc.getElementsByTagName("kana");
	
	//sortedIndex初期化（未ソート）
	sortedIndex  = new Array(item.length);
	for (i=0 ; i<item.length; i++){ 
		sortedIndex[i] = item[i];
	}
	isSortedByKana = false;
	
	
	//カタログのカテゴリ
	categoryString = lists[0].getAttribute('category'); //lists[0].attributes[0].value;
	midashiHTML = '<p>'+categoryString+'</p>';
	

    //詳細リストを出力
     putoutDetail(targetNum);
	//putoutList(0);
  }
  
//コールバック関数 ( 受信時に実行されます )
  function on_loadedXMLLi(oj)
  {
    //responseXMLでレスポンスを取得
    var xdoc  =  filterByCode( oj.responseXML, 'JAMCO' );
	
	//XMLを配列に変換します
	//XML内の"name"という名前のタグ(要素)の配列を作る
    lists =  xdoc.childNodes; //xdoc.getElementsByTagName("lists");
  
    //XML内の"name"という名前のタグ(要素)の配列を作る
    item = xdoc.getElementsByTagName("item");
	
	//XML内の"kana"という名前のタグ(要素)の配列を作る
	kana  = xdoc.getElementsByTagName("kana");
	
	//sortedIndex初期化（未ソート）
	sortedIndex  = new Array(item.length);
	for (i=0 ; i<item.length; i++){ 
		sortedIndex[i] = item[i];
	}
	isSortedByKana = false;
	
	
	//カタログのカテゴリ
	categoryString =  lists[0].getAttribute('category'); //lists[0].attributes[0].value;
	midashiHTML = '<p>'+categoryString+'</p>';
	
	//kanaでソート
	sortnameKana(sortedIndex);
	

    //詳細リストを出力
     //putoutDetail(targetNum);
	putoutList(targetNum);
  }
 
  //送信用関数
   function loadFile(url)
  {
	targetNum = 0;
	thisURL = url;
    sendRequest(on_loadedXML,'','GET',url,true,true) 
  }
  
  function loadFile2(url,num)
  {
	targetNum = num;
    sendRequest(on_loadedXML,'','GET',url,true,true) 
  }
  
  function loadFileLi(url)
  {
	targetNum = 0;
	thisURL = url;
    sendRequest(on_loadedXMLLi,'','GET',url,true,true) 
  }
  
  function loadFileLi2(url,num)
  {
	targetNum = num;
    sendRequest(on_loadedXMLLi,'','GET',url,true,true) 
  }
  
  
  
  //詳細を出力
  function putoutDetail(n)
  {
	
	//スレッドの最大値
	var itemMax = (n+1)*detailMax;
	if(itemMax > item.length) itemMax = item.length;
	
    //リストヘッダを生成
	
	//リンクテキスト
	var linkHTML = '<div class="pageLink">';
	if(n!=0)		{linkHTML += '<a class="btn_l" onClick="javascript:loadFile2(\''+thisURL+'\','+eval(n-1)+'); window.scroll(0,0);" href="javascript:;">Prev.</a> ';}
	else			{linkHTML += '';}
					linkHTML +='<div class="pageIndex">'
	for(i =0; i<(item.length/detailMax); i++){
		if(i==n)	{linkHTML += '<span class="number">'+eval(i+1)+'</span>';}
		else		{linkHTML += '<a class="number" onClick="javascript:loadFile2(\''+thisURL+'\','+i+'); window.scroll(0,0);" href="javascript:;">'+eval(i+1)+'</a>';}
	}
					linkHTML +='</div>'
	if(n!=Math.floor(item.length/detailMax)) 
					{linkHTML += '<a class="btn_r" onClick="javascript:loadFile2(\''+thisURL+'\','+eval(n+1)+'); window.scroll(0,0);" href="javascript:;">Next</a>';}
	else			{linkHTML += '';}
					linkHTML += '</div>';
	
    html = '<div id="listTop">';
	html +='<h2 id="categoryName">'+decodeURIComponent(midashiHTML)+'</h2>';
	html +='<div id="controlTop"><div class="btn_viewChange_detail_selected">Details</div>'+'<a class="btn_viewChange_sort" onClick="javascript:loadFileLi(\''+thisURL+'\');" href="javascript:;">Arphabetical</a>'+linkHTML+'</div>';
	html +='<div class="clear"></div>';
	html +='</div>';
	
	//alert(item[0].getElementsByTagName("sample").item(0).firstChild.nodeValue != '');
    
    //"item"タグが出てきた順に処理します
    for( i = n*detailMax ; i < itemMax ; i++ )
    {
		 var sampleView = '';
		if(item[i].getElementsByTagName("sample").length>0 && item[i].getElementsByTagName("sample").item(0).childNodes.length>0 && item[i].getElementsByTagName("images").length>0 && item[i].getElementsByTagName("images").item(0).childNodes.length>0){
			
			var timeLength = '0';
			if(item[i].getElementsByTagName("sampleTime").length>0 && item[i].getElementsByTagName("sampleTime").item(0).childNodes.length>0){
				timeLength = item[i].getElementsByTagName("sampleTime").item(0).firstChild.nodeValue;
			}
			
			sampleView = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="240" height="204">'
						+'<param name="movie" value="player.swf">'
						+'<param name="quality" value="high">'
						+'<PARAM name="flashvars" value="movieFile=flvs/'+ item[i].getElementsByTagName("sample").item(0).firstChild.nodeValue 
						+'&amp;photoFile=images/'+ item[i].getElementsByTagName("images").item(0).firstChild.nodeValue
						+'&amp;totalTime='+ timeLength +'">'
						+'<embed src="player.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="240" height="204"'
						+'FLASHVARS="movieFile=flvs/'+ item[i].getElementsByTagName("sample").item(0).firstChild.nodeValue 
						+'&amp;photoFile=images/'+ item[i].getElementsByTagName("images").item(0).firstChild.nodeValue
						+'&amp;totalTime='+ timeLength +'"></embed>'
						+'</object>'
		}else if(item[i].getElementsByTagName("images").length>0 && item[i].getElementsByTagName("images").item(0).childNodes.length>0){
			sampleView = '<img src="images/'+ item[i].getElementsByTagName("images").item(0).firstChild.nodeValue +'" width="240px"  alt="'+item[i].getElementsByTagName("name").item(0).firstChild.nodeValue+'">';
		}
		
        //各要素内のfirstChildのデータだけを取り出す
		html += '<!-- item ['+i+'] -->';
		html += '<div class="item_detail">';
		html += '<div class="info">';
        //html += '<h3 class="title">'+'['+i+']'+ item[i].getElementsByTagName("name").item(0).firstChild.nodeValue + '</h3>';
		 html += '<h3 class="title">'+item[i].getElementsByTagName("name").item(0).firstChild.nodeValue + iconNewHTML[item[i].getElementsByTagName("new").item(0).firstChild.nodeValue]+ '</h3>';
		html += '<p class="data">'
		if(item[i].getElementsByTagName("length").length>0 && item[i].getElementsByTagName("length").item(0).childNodes.length>0){
			html += item[i].getElementsByTagName("length").item(0).firstChild.nodeValue +'/';
		}
		if(item[i].getElementsByTagName("code").length>0 && item[i].getElementsByTagName("code").item(0).childNodes.length>0){
			html += item[i].getElementsByTagName("code").item(0).firstChild.nodeValue +'/';
		}
		if(item[i].getElementsByTagName("lang").length>0 && item[i].getElementsByTagName("lang").item(0).childNodes.length>0){
			html += item[i].getElementsByTagName("lang").item(0).firstChild.nodeValue;
		}
		html += '</p>';
		if(item[i].getElementsByTagName("info").length>0 && item[i].getElementsByTagName("info").item(0).childNodes.length>0){
			html += '<p class="descript">'+parseBrake(item[i].getElementsByTagName("info").item(0).firstChild.nodeValue) + '</p>';
		}
        html += '</div>'
		html += '<div class="sampleView">'+sampleView+'</div>'
        html += '<div class="clear"></div>'
		html+=makeEpisode(i,0);
		html += '</div>'
    }
    
	//リンクテキスト
	html +='<div id="controlBottom"><div class="btn_viewChange_detail_selected">Details</div>'+'<a class="btn_viewChange_sort" onClick="javascript:loadFileLi(\''+thisURL+'\');  window.scroll(0,0);" href="javascript:;">Arphabetical</a>'+linkHTML+'</div>';
	html +='<div class="clear"></div>';
	html +='</div>';
	
	//出力
	document.getElementById("itemList").innerHTML=html
	//alert(item[0].getElementsByTagName("episode").item(0).getElementsByTagName("epi_length").item(0).firstChild==null);
	//alert(item[0].getElementsByTagName("epi_length").item(0).firstChild.length);
  }
  

  
  
  function makeEpisode(n,mode){  //mode0 detail, mode1 list, return html
  	var html = '';
	var attri ='';
	if(mode==0)	var epiArr = item[n].getElementsByTagName("episode");
	if(mode==1)	var epiArr = sortedIndex[n].getElementsByTagName("episode");
	if(epiArr.length > 0 && epiArr.item(0).childNodes.length>0 && mode==0){
		for(var i=0; i<epiArr.length; i++){
			html+='<div class="episode">';
			html+='<div class="epi_info">';
			
			for(var j=0; j<epiArr[i].getElementsByTagName("epi_name").length; j++){
				attri ='';
				html+='<h4 class="epi_title">';
				if(epiArr[i].getElementsByTagName("epi_name").item(j).childNodes.length>0){
					html+= epiArr[i].getElementsByTagName("epi_name").item(j).firstChild.nodeValue
					if(epiArr[i].getElementsByTagName("epi_new").childsLength>0 && epiArr[i].getElementsByTagName("epi_new").item(j).childNodes.length>0){																										
						html+= iconNewHTML[item[i].getElementsByTagName("epi_new").item(j).firstChild.nodeValue];
					}else{
						if(epiArr[i].getElementsByTagName("epi_name").item(j).getAttribute("new") !=null){
							html+=iconNewHTML[epiArr[i].getElementsByTagName("epi_name").item(j).getAttribute("new") ];
						}
						if(epiArr[i].getElementsByTagName("epi_name").item(j).getAttribute("code") !=null){
							attri+=epiArr[i].getElementsByTagName("epi_name").item(j).getAttribute("code") ;
							if(epiArr[i].getElementsByTagName("epi_name").item(j).getAttribute("length") !=null){
								attri+='/'+epiArr[i].getElementsByTagName("epi_name").item(j).getAttribute("length") ;
							}
						}
						else if(epiArr[i].getElementsByTagName("epi_name").item(j).getAttribute("length") !=null){
							attri+=epiArr[i].getElementsByTagName("epi_name").item(j).getAttribute("length") ;
						}
						if(attri!=''){
							attri = '<span class="epi_data" style="font-weight:normal;">'+' ('+attri+')'+'</span>';	
						}
					}
					
					
				}
				html+=attri+'</h4>';
			}
			/*
			html+='<p class="epi_data">';
			html+= '&nbsp;(';
						   
			var epi_length=''
			if(epiArr[i].getElementsByTagName("epi_length").childsLength>0 && epiArr[i].getElementsByTagName("epi_length").item(0).childNodes.length>0){
				epi_length=epiArr[i].getElementsByTagName("epi_length").item(0).firstChild.nodeValue+'/';
			}
			var epi_code='';
			if(epiArr[i].getElementsByTagName("epi_code").childsLength>0 && epiArr[i].getElementsByTagName("epi_code").item(0).childNodes.length>0){
				epi_code= epiArr[i].getElementsByTagName("epi_code").item(0).firstChild.nodeValue;
			}
			html+= ')';
			html+='</p>';
			*/
			
			if(epiArr[i].getElementsByTagName("epi_info").length>0 && epiArr[i].getElementsByTagName("epi_info").item(0).childNodes.length>0){
				html+='<p class="epi_descript">'+ parseBrake(epiArr[i].getElementsByTagName("epi_info").item(0).firstChild.nodeValue)+'</p>';
			}
			
			
			html+='</div>';
			html+= sampleView(epiArr,i);
			html+='</div>';
		}
		html+='<div class="clear"></div>'
	}
	if(epiArr.length > 0 && epiArr.item(0).childNodes.length>0 && mode==1){
		for(var i=0; i<epiArr.length; i++){
			html+='<div class="episode">';
			html+= sampleView2(epiArr,i);
			html+='<div class="epi_info">';
			for(var j=0; j<epiArr[i].getElementsByTagName("epi_name").length; j++){
				attri ='';
				html+='<h4 class="epi_title">';
				if(epiArr[i].getElementsByTagName("epi_name").item(j).childNodes.length>0){
					html+= epiArr[i].getElementsByTagName("epi_name").item(j).firstChild.nodeValue
					if(epiArr[i].getElementsByTagName("epi_new").length>0 && epiArr[i].getElementsByTagName("epi_new").item(j).childNodes.length>0){																										
						html+= iconNewHTML[item[i].getElementsByTagName("epi_new").item(j).firstChild.nodeValue];
					}else{
						if(epiArr[i].getElementsByTagName("epi_name").item(j).getAttribute("new") !=null){
							html+=iconNewHTML[epiArr[i].getElementsByTagName("epi_name").item(j).getAttribute("new") ];
						}
						if(epiArr[i].getElementsByTagName("epi_name").item(j).getAttribute("code") !=null){
							attri+=epiArr[i].getElementsByTagName("epi_name").item(j).getAttribute("code") ;
							if(epiArr[i].getElementsByTagName("epi_name").item(j).getAttribute("length") !=null){
								attri+='/'+epiArr[i].getElementsByTagName("epi_name").item(j).getAttribute("length") ;
							}
						}
						else if(epiArr[i].getElementsByTagName("epi_name").item(j).getAttribute("length") !=null){
							attri+=epiArr[i].getElementsByTagName("epi_name").item(j).getAttribute("length") ;
						}
						if(attri!=''){
							attri = '<span class="epi_data" style="font-weight:normal;">'+' ('+attri+')'+'</span>';	
						}
					}
					
					
				}
				html+=attri+'</h4>';
			}
			/*
			html+='<p class="epi_data">';
			html+= '&nbsp;(';
			if(epiArr[i].getElementsByTagName("epi_length").item(0).firstChild!=null){
				html+=epiArr[i].getElementsByTagName("epi_length").item(0).firstChild.nodeValue+'/';
			}
			if(epiArr[i].getElementsByTagName("epi_code").item(0).firstChild!=null){
				html+= epiArr[i].getElementsByTagName("epi_code").item(0).firstChild.nodeValue;
			}
			html+= ')';
			html+='</p>';
			*/
			if(epiArr[i].getElementsByTagName("epi_info").length>0 && epiArr[i].getElementsByTagName("epi_info").item(0).childNodes.length>0){
				html+='<p class="epi_descript">'+ parseBrake(epiArr[i].getElementsByTagName("epi_info").item(0).firstChild.nodeValue)+'</p>';
			}
			html+='</div>';
			html+='<div class="clear"></div>'

			html+='</div>';
		}
		html+='<div class="clear"></div>'
	
	}
	return html;
	
	//trace(item[n].getElementsByTagName("episode").item(0).getElementsByTagName("epi_name").item(0).firstChild.nodeValue);
  }
  
  function sampleView(ar,i){
	 var sampleView = '';
	 if(ar[i].getElementsByTagName("epi_sample").length>0 &&ar[i].getElementsByTagName("epi_sample").item(0).childNodes.length>0){
			
			var timeLength = '0';
			if(ar[i].getElementsByTagName("epi_sampleTime").length>0 && ar[i].getElementsByTagName("epi_sampleTime").item(0).childNodes.length>0){
				timeLength = ar[i].getElementsByTagName("epi_sampleTime").item(0).firstChild.nodeValue;
			}
			
			sampleView = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="240" height="204">'
						+'<param name="movie" value="player.swf">'
						+'<param name="quality" value="high">'
						+'<PARAM name="flashvars" value="movieFile=flvs/'+ ar[i].getElementsByTagName("epi_sample").item(0).firstChild.nodeValue 
						+'&amp;photoFile=images/'+ ar[i].getElementsByTagName("epi_images").item(0).firstChild.nodeValue
						+'&amp;totalTime='+ timeLength +'">'
						+'<embed src="player.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="240" height="204"'
						+'FLASHVARS="movieFile=flvs/'+ ar[i].getElementsByTagName("epi_sample").item(0).firstChild.nodeValue 
						+'&amp;photoFile=images/'+ ar[i].getElementsByTagName("epi_images").item(0).firstChild.nodeValue
						+'&amp;totalTime='+ timeLength +'"></embed>'
						+'</object>';
			sampleView ='<div class="epi_sampleView">' + sampleView + '</div><div class="clear"></div>';
		}else if(ar[i].getElementsByTagName("epi_images").length>0 && ar[i].getElementsByTagName("epi_images").item(0).childNodes.length>0){
			sampleView = '<img src="images/'+ ar[i].getElementsByTagName("epi_images").item(0).firstChild.nodeValue +'"  alt="'+ar[i].getElementsByTagName("epi_name").item(0).firstChild.nodeValue+'" width="240px">';
			sampleView ='<div class="epi_sampleView h180">' + sampleView + '</div><div class="clear"></div>';
		}
		return sampleView;
  }
  
  function sampleView2(ar,i){
	 var sampleView = '';
 	if(ar[i].getElementsByTagName("epi_sample").length>0 &&ar[i].getElementsByTagName("epi_sample").item(0).childNodes.length>0){
				
			var timeLength = '0';
			if(ar[i].getElementsByTagName("epi_sampleTime").length>0 && ar[i].getElementsByTagName("epi_sampleTime").item(0).childNodes.length>0){
				timeLength = ar[i].getElementsByTagName("epi_sampleTime").item(0).firstChild.nodeValue;
			}
			
			sampleView = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="240" height="204">'
						+'<param name="movie" value="player.swf">'
						+'<param name="quality" value="high">'
						+'<PARAM name="flashvars" value="movieFile=flvs/'+ ar[i].getElementsByTagName("epi_sample").item(0).firstChild.nodeValue 
						+'&amp;photoFile=images/'+ ar[i].getElementsByTagName("epi_images").item(0).firstChild.nodeValue
						+'&amp;totalTime='+ timeLength +'">'
						+'<embed src="player.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="240" height="204"'
						+'FLASHVARS="movieFile=flvs/'+ ar[i].getElementsByTagName("epi_sample").item(0).firstChild.nodeValue 
						+'&amp;photoFile=images/'+ ar[i].getElementsByTagName("epi_images").item(0).firstChild.nodeValue
						+'&amp;totalTime='+ timeLength +'"></embed>'
						+'</object>';
			sampleView ='<div class="view">' + sampleView + '</div>';
		}else if(ar[i].getElementsByTagName("epi_images").length>0 && ar[i].getElementsByTagName("epi_images").item(0).childNodes.length>0){
			sampleView = '<img src="images/'+ ar[i].getElementsByTagName("epi_images").item(0).firstChild.nodeValue +'"  alt="'+ar[i].getElementsByTagName("epi_name").item(0).firstChild.nodeValue+'" width="240px">';
			sampleView ='<div class="view h180">' + sampleView + '</div>';
		}
		return sampleView;
  }
  
  //リストを出力
  function putoutList(n)
  {
	
	//スレッドの最大値
	var itemMax = (n+1)*listMax;
	if(itemMax > item.length) itemMax = item.length;
	
    //リストヘッダを生成
	
	//リンクテキスト
	var linkHTML = '<div class="pageLink">';
	if(n!=0)		{linkHTML += '<a class="btn_l" onClick="javascript:loadFileLi2(\''+thisURL+'\','+eval(n-1)+'); window.scroll(0,0);" href="javascript:;">Prev</a> ';}
	else			{linkHTML += '';}
					linkHTML +='<div class="pageIndex">'
	for(i =0; i<(item.length/listMax); i++){
		if(i==n)	{linkHTML += '<span class="number">'+eval(i+1)+'</span>';}
		else		{linkHTML += '<a class="number" onClick="javascript:loadFileLi2(\''+thisURL+'\','+i+'); window.scroll(0,0);" href="javascript:;">'+eval(i+1)+'</a>';}
	}
					linkHTML +='</div>'
	if(n!=Math.floor(item.length/listMax)) 
					{linkHTML += '<a class="btn_r" onClick="javascript:loadFileLi2(\''+thisURL+'\','+eval(n+1)+'); window.scroll(0,0);" href="javascript:;">Next</a>';}
	else			{linkHTML += '';}
					linkHTML += '</div>';
	
    html = '<div id="listTop">';
	html +='<h2 id="categoryName">'+decodeURIComponent(midashiHTML)+'</h2>';
	html +='<div id="controlTop"><a class="btn_viewChange_detail" onClick="javascript:loadFile(\''+thisURL+'\');" href="javascript:;">Details</a>'+'<div class="btn_viewChange_sort_selected">Arphabetical</div>'+linkHTML+'</div>';
	html +='<div class="clear"></div>';
	html +='</div>';
	
	html +='<table id="listTable" cellpadding="0" cellspacing="0">'
	if(pagelang==1){
	html +='<tr class="head">'+
			'<td class="title"><span class="tableHead">タイトル</span></td>'+
			'<td class="length"><span class="tableHead">時間</span></td>'+
			'<td class="code"><span class="tableHead">コード</span></td>'+
			'<td class="lang"><span class="tableHead">言語</span></td>'+
			'<td class="play_btn" colspan="2"><span class="tableHead">詳細</span></td></tr>'
	}else{
	html +='<tr class="head">'+
			'<td class="title"><span class="tableHead">Title</span></td>'+
			'<td class="length"><span class="tableHead">Length</span></td>'+
			'<td class="code"><span class="tableHead">Code</span></td>'+
			'<td class="lang"><span class="tableHead">Language</span></td>'+
			'<td class="play_btn" colspan="2"><span class="tableHead">Details</span></td></tr>'	
	}
    
    //"item"タグが出てきた順に処理します
	var m =0;
	var backgroundClass = 'g';
    for( i = n*listMax ; i < itemMax ; i++ )
    {
		if((m%2)==1)	backgroundClass = 'w';
		else			backgroundClass = 'g';
		m++;
		
		 var sampleView = '';
		 var playIconHTML = ' &nbsp;';
		if(sortedIndex[i].getElementsByTagName("sample").length>0 && sortedIndex[i].getElementsByTagName("sample").item(0).childNodes.length>0 && sortedIndex[i].getElementsByTagName("images").length>0 && sortedIndex[i].getElementsByTagName("images").item(0).childNodes.length>0){
			//playIconHTML = '<a class="btnPlay" onClick="javascript:btnAction(this,'+i+')" href="javascript:;">再生</a>';
			playIconHTML = '<img src="../../images/icon_play.gif" width="14px" height="24px">';
			var timeLength = '0';
			if(sortedIndex[i].getElementsByTagName("sampleTime").length>0 && sortedIndex[i].getElementsByTagName("sampleTime").item(0).childNodes.length>0){
				timeLength = sortedIndex[i].getElementsByTagName("sampleTime").item(0).firstChild.nodeValue;
			}
			
			sampleView = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="240" height="204" class="sample" style="display:block">'
						+'<param name="movie" value="player.swf">'
						+'<param name="quality" value="high">'
						+'<PARAM name="flashvars" value="movieFile=flvs/'+ sortedIndex[i].getElementsByTagName("sample").item(0).firstChild.nodeValue 
						+'&amp;photoFile=images/'+ sortedIndex[i].getElementsByTagName("images").item(0).firstChild.nodeValue
						+'&amp;totalTime='+ timeLength +'">'
						+'<embed src="player.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="240" height="204"'
						+'FLASHVARS="movieFile=flvs/'+ sortedIndex[i].getElementsByTagName("sample").item(0).firstChild.nodeValue 
						+'&amp;photoFile=images/'+ sortedIndex[i].getElementsByTagName("images").item(0).firstChild.nodeValue
						+'&amp;totalTime='+ timeLength +'"></embed>'
						+'</object>'
		}else if(sortedIndex[i].getElementsByTagName("images").length>0 && sortedIndex[i].getElementsByTagName("images").item(0).childNodes.length>0){
			sampleView = '<img src="images/'+ sortedIndex[i].getElementsByTagName("images").item(0).firstChild.nodeValue +'"  alt="'+sortedIndex[i].getElementsByTagName("name").item(0).firstChild.nodeValue+'" class="sample" width="240px">'
		}
		else{
			sampleView = '<div class="view h180">'+ sampleView+'</div>';
		}
		
        //各要素内のfirstChildのデータだけを取り出す
		//html += '<tr class="'+backgroundClass+'"><td class="title">'+backgroundClass+'['+i+']'+ sortedIndex[i].getElementsByTagName("name").item(0).firstChild.nodeValue +
		html += '<tr class="'+backgroundClass+'"><td class="title"><a class="openDetailTitle" onClick="javascript:btnAction(this,'+i+')" href="javascript:;">'+sortedIndex[i].getElementsByTagName("name").item(0).firstChild.nodeValue+'</a>' + iconNewHTML[sortedIndex[i].getElementsByTagName("new").item(0).firstChild.nodeValue]+
				'</td>'+
				'<td class="length">'
		if(sortedIndex[i].getElementsByTagName("length").length>0 && sortedIndex[i].getElementsByTagName("length").item(0).childNodes.length>0){
			html += sortedIndex[i].getElementsByTagName("length").item(0).firstChild.nodeValue;
		}
		html += '</td>';
		html += '<td class="code">'
		if(sortedIndex[i].getElementsByTagName("code").length>0 && sortedIndex[i].getElementsByTagName("code").item(0).childNodes.length>0){
			html += sortedIndex[i].getElementsByTagName("code").item(0).firstChild.nodeValue
		}
		html +='</td>'
		html +=	'<td class="lang">'
		if(sortedIndex[i].getElementsByTagName("lang").length>0 && sortedIndex[i].getElementsByTagName("lang").item(0).childNodes.length>0){
			html += sortedIndex[i].getElementsByTagName("lang").item(0).firstChild.nodeValue;
		}
		html +='</td>'+
				'<td class="play">'+playIconHTML+'</td>'+
				'<td class="btn"><a class="openDetail" onClick="javascript:btnAction(this,'+i+')" href="javascript:;">[詳細]</a></td></tr>';
		html += '<tr class="'+backgroundClass+'_des"><td colspan="6">'
		html += '<div class="description">'
		html += '<div class="view">'
		html += sampleView;
		html += '</div>'
		html += '<p class="info">'
		if(sortedIndex[i].getElementsByTagName("info").length>0 && sortedIndex[i].getElementsByTagName("info").item(0).childNodes.length>0){
			html += parseBrake(sortedIndex[i].getElementsByTagName("info").item(0).firstChild.nodeValue);
		}
		html +='</p>'
		html +='<div class="clear"></div>'
		html += '</div>';
		
		html +='</td></tr>'
				
    }
    
	html += '</table>'
	
	//リンクテキスト
	html +='<div id="controlBottom"><a class="btn_viewChange_detail" onClick="javascript:loadFile(\''+thisURL+'\'); window.scroll(0,0);" href="javascript:;">詳細表示</a>'+'<div class="btn_viewChange_sort_selected">五十音順表示</div>'+linkHTML+'</div>';
	html +='<div class="clear"></div>';
	html +='</div>';
	
	//出力
	document.getElementById("itemList").innerHTML=html;
	
  }
  
  
  //よみがなでソート
  function sortnameKana(target){
	  s = new Array();
	  for (q=target.length ; q >= 0; q--){ 
		for (p=0 ; p < q-1; p++ ) { 
			if(target[p].getElementsByTagName("kana").item(0).firstChild.nodeValue > target[p+1].getElementsByTagName("kana").item(0).firstChild.nodeValue){ 
				s[0] = target[p+1]; 
				target[p+1] = target[p]; 
				target[p] = s[0];
			} 
		} 
	} 
	isSortedByKana = true;
  }
  
  //ボタンアクション
  function btnAction(x,n){
	  if(x.className=='openDetail' || x.className=='openDetailTitle') {
		//trace(x.parentNode.parentNode.nextSibling.firstChild.firstChild.firstChild.childNodes[3].nodeName);
		x.parentNode.parentNode.nextSibling.firstChild.firstChild.style.display = 'block';
		trace(x.parentNode.parentNode.nextSibling.firstChild.firstChild.nodeName);
		
		var sampleView = '';
		if(sortedIndex[n].getElementsByTagName("sample").length>0 && sortedIndex[n].getElementsByTagName("sample").item(0).childNodes.length>0 && sortedIndex[n].getElementsByTagName("images").length>0 && sortedIndex[n].getElementsByTagName("images").item(0).childNodes.length>0){
			
			var timeLength = '0';
			if(sortedIndex[n].getElementsByTagName("sampleTime").item(0).childNodes.length>0){
				timeLength = sortedIndex[n].getElementsByTagName("sampleTime").item(0).firstChild.nodeValue;
			}
			
			playNow = 0;
			if(x.className=='btnPlay') playNow = 1;
			sampleView = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="240" height="204" class="sample">'
						+'<param name="movie" value="player.swf">'
						+'<param name="quality" value="high">'
						+'<PARAM name="flashvars" value="movieFile=flvs/'+ sortedIndex[n].getElementsByTagName("sample").item(0).firstChild.nodeValue 
						+'&amp;photoFile=images/'+ sortedIndex[n].getElementsByTagName("images").item(0).firstChild.nodeValue
						+'&amp;totalTime='+ timeLength +'&amp;playNow='+ playNow +'">'
						+'<embed src="player.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="240" height="204"'
						+'FLASHVARS="movieFile=flvs/'+ sortedIndex[n].getElementsByTagName("sample").item(0).firstChild.nodeValue 
						+'&amp;photoFile=images/'+ sortedIndex[n].getElementsByTagName("images").item(0).firstChild.nodeValue
						+'&amp;totalTime='+ timeLength +'&amp;playNow='+ playNow +'"></embed>'
						+'</object>'
			
		}else if(sortedIndex[n].getElementsByTagName("images").length>0 && sortedIndex[n].getElementsByTagName("images").item(0).childNodes.length>0){
			sampleView = '<img src="images/'+ sortedIndex[n].getElementsByTagName("images").item(0).firstChild.nodeValue +'"  alt="'+sortedIndex[n].getElementsByTagName("name").item(0).firstChild.nodeValue+'" class="sample" width="240px">'
		}
		
		dumpImg(sampleView);
		dumpClear();		
		
		var html = '';
		
		html += '<div class="view" style="margin-right:4px;">'
		html += sampleView;
		html += '</div>'
		html += '<p class="info">'
		if(sortedIndex[n].getElementsByTagName("info").length>0 && sortedIndex[n].getElementsByTagName("info").item(0).childNodes.length>0){
			html += parseBrake(sortedIndex[n].getElementsByTagName("info").item(0).firstChild.nodeValue);
		}
		html +='</p>'
		html +='<div class="clear"></div>'
		
		html += makeEpisode(n,1);
		


		x.parentNode.parentNode.nextSibling.firstChild.firstChild.innerHTML = html;
		//x.parentNode.parentNode.nextSibling.firstChild.firstChild.firstChild.childNodes[3].style.height = '250';
		
		x.parentNode.parentNode.childNodes[5].innerHTML = '<a class="closeDetail" onClick="javascript:btnAction(this,'+n+')" href="javascript:;">[閉る]</a>' ; 
		if(x.className=='openDetailTitle'){
			x.className='closeDetailTitle'
		}
		//trace(x.parentNode.parentNode.childNodes[5].nodeName);
		//if(x.className=='btnPlay'){
		//	x.parentNode.parentNode.childNodes[1].innerHTML = '<a class="btnStop" onClick="javascript:btnAction(this,'+n+')" href="javascript:;">停止</a>' ; 
		//}
		
	  }
	  else if(x.className=='closeDetail'|| x.className=='closeDetailTitle') {
		x.parentNode.parentNode.nextSibling.firstChild.firstChild.style.display = 'none';
		if(sortedIndex[n].getElementsByTagName("sample").item(0).childNodes.length>0 && sortedIndex[n].getElementsByTagName("sample").item(0).childNodes.length>0){
		//x.parentNode.parentNode.childNodes[1].innerHTML = '<a class="btnPlay" onClick="javascript:btnAction(this,'+n+')" href="javascript:;">再生</a>' ; 
		}
		x.parentNode.parentNode.childNodes[5].innerHTML = '<a class="openDetail" onClick="javascript:btnAction(this,'+n+')" href="javascript:;">[詳細]</a>' ; 
		
		if(x.className=='closeDetailTitle'){
			x.className='openDetailTitle'
		}
		
	  }
	  else if(x.className=='btnStop' ) {
		x.parentNode.parentNode.nextSibling.firstChild.firstChild.style.display = 'none';
		x.parentNode.parentNode.childNodes[5].innerHTML = '<a class="openDetail" onClick="javascript:btnAction(this,'+n+')" href="javascript:;">[詳細]</a>' ; 
		//x.parentNode.parentNode.childNodes[1].innerHTML = '<a class="btnPlay" onClick="javascript:btnAction(this,'+n+')" href="javascript:;">再生</a>' ; 
//		trace(x.parentNode.parentNode.childNodes[1].innerHTML);
	  }
		  
  }
  
  function trace(x){
	 // document.getElementById("consol").innerHTML +='<br>'+x;
  }
  
  function dumpImg(x){
	  document.getElementById("dump").innerHTML +=x;
  }
  function dumpClear(){
	  document.getElementById("dump").innerHTML ="";
  }
  
  function printState(x){
	  document.getElementById("status").innerHTML =x;
  }