var entriesPref = "10";
var autostartPref = "No";
var shufflePref = "Yes";
var q = location.href.split('?');
q = (q.length>1) ? q[1].split('&') : ['',''];
/*----------------------------------------
	1. Define
----------------------------------------*/
var ch_list = ch_id = ch_no = ch_title = 0;
var feed_list = [], feed_no = 0;
var entry_no = entry_len = 0;
var play_start = play_jd = menu_no = settimeid = xxsx= 0;
var sizeid = hidemenu = 1;
var ytitle = [], yurl = [], ydur = [], yvurl = [], ycontent = [], ypublished = [], yauthor = [], ycount = [], yrating = [];
var rurl = "./img/";
var tag_list = [
	["Pop", __MSG_XPOP__], 
	["Jazz", __MSG_XJAZZ__], 
	["Folk", __MSG_XFOLK__], 
	["Metal", __MSG_XMETAL__], 
	["Female Vocalists", __MSG_XVOCALISTS__], 
	["Indie", __MSG_XINDIE__], 
	["J-ROCK", __MSG_XJROCK__], 
	["J-POP", __MSG_XJPOP__]
];
feed_list[8] = [];
feed_list[9] = [];
for(var i=0; i<tag_list.length; i++) {
	feed_list[i] = [tag_list[i][0], tag_list[i][1]];
}
var feed80_list = [
	["Rock", listAudioscrobbler(), __MSG_XROCK__],
	["Japanese", listAudioscrobbler_ja(), __MSG_XJAPANESE__]
];

/*----------------------------------------
	2. Start
----------------------------------------*/
// Start
function startCh(jd) {
	if(jd!=1) {
		startInit();
	}else {
		play_start = 0;
		ch_id = -1;
	}
	_gel('main').innerHTML = showTopPage();
	fillChMenu();
	fillMenu();
	if(autostartPref=="Yes") {
		var t = ch_list[0].split('":"');
		if(t[2]=="Yes") {
			getCH(String(t[1]));
		}else {
			getCH(String(t[1]), '0');
		}
		return;
	}
}
// Start Init
function startInit() {
	ch_list = [
		feed80_list[0][0] + '":"80":"' + feed80_list[0][2],
		feed_list[0][0] + '":"70":"' + feed_list[0][1],
		feed_list[1][0] + '":"71":"' + feed_list[1][1],
		feed_list[2][0] + '":"72":"' + feed_list[2][1],
		feed_list[3][0] + '":"73":"' + feed_list[3][1],
		feed_list[4][0] + '":"74":"' + feed_list[4][1],
		feed_list[5][0] + '":"75":"' + feed_list[5][1],
		feed80_list[1][0] + '":"81":"' + feed80_list[1][2],
		feed_list[6][0] + '":"76":"' + feed_list[6][1],
		feed_list[7][0] + '":"77":"' + feed_list[7][1],
		__MSG_FAVORITES__ + '":"78":"' + __MSG_FAVORITES__,
		'":"79":"'
];
}
/*----------------------------------------
	3. Get Channel URL
----------------------------------------*/
// Get User Channel URL
function getCH(no, id, jd) {
	var z = returnFeedlist(no);
	ch_no = no;
	ch_id = z[0];
	feed_no = ((shufflePref!="Yes" && jd==1) || jd==2) ? 0 : ((!id) ? Math.floor(Math.random() * z[3].length) : id.replace(/"|'/g, ''));
	ch_title = _hesc(z[3][feed_no].replace(/\n|\t|\r/g, ''));
	var geturl = "http://gdata.youtube.com/feeds/api/videos/-/Music/?orderby=relevance&vq=" + encodeURIComponent(ch_title) + "&format=5&max-results=" + entriesPref + "&alt=json-in-script&callback=youtubecallback";
	getFeedUrls(geturl);
}
function getWord(word) {
	word = (word) ? word : _gel('wordid').value;
	if(!word) {
		alert("[Caution] No word.");
		return false;
	}
	var geturl = './xml/?id=1&name=' + encodeURIComponent(word.replace(/ /g, '+'));
	getFeedUrls(geturl);
}
function getEachTag(word, z2) {
	var geturl = './xml/?id=1&tag=' + encodeURIComponent(word.replace(/ /g, '+')) + '&z=' + z2;
	getFeedUrls(geturl, z2);
}
/*----------------------------------------
	4. Get JSONP
----------------------------------------*/
// http://yusukebe.com/tech/archives/20070905/140422.html
function getFeedUrls(geturl, jd) {
	JavaScriptLoader(geturl, jd);
	return;
	var p = (jd==1) ? 'menu' : 'main';
	if(jd!=2) {
		_gel(p).innerHTML = '<p class="load">' + Img("load.gif", "load") + 'Loading...</p>';
	}
	var scriptPlus = document.createElement('script');
	scriptPlus.type = 'text/javascript';
	scriptPlus.src = geturl;
	var d = document.getElementsByTagName("head")[0];
	d.appendChild(scriptPlus);
	var sid = setTimeout(function() {
		clearTimeout(sid);
		if(play_start==0 && ch_id!=-1 && !jd) {
			d.removeChild(scriptPlus);
			setErrorMsg(1);
		}
	}, 10000);
}
/*
	function getFeedUrls(geturl, jd) {
		var p = (jd==1) ? 'menu' : 'main';
		if(jd!=2) {
			_gel(p).innerHTML = '<p class="load">' + Img("load.gif", "load") + 'Loading...</p>' + geturl;
		}
		var hObj = createXMLHttpRequest();
		if(hObj) {
			hObj.open("GET", geturl, true);
			hObj.onreadystatechange = function() { 
				setTimeout(function() {
  				if(hObj.readyState == 0 || hObj.readyState == 4) {
						return;
					}
					hObj.abort();
					setErrorMsg(1);
				}, 15000);
				if(hObj.readyState==4) {
					var t = hObj.responseText;
					if(!t) {
						setErrorMsg(1);
					}
					var data = eval("(" + t + ")");
					if(!data) {
						setErrorMsg(1);
					}
					youtubeEcho(t);
				}
			}
			hObj.send(null);
		}
	}
*/
function JavaScriptLoader(geturl, jd){
	var p = (jd==1) ? 'menu' : 'main';
	if(jd!=2) {
		_gel(p).innerHTML = '<p class="load">' + Img("load.gif", "load") + 'Loading...</p>';
	}
	var sc = document.createElement('script');
	sc.type = 'text/javascript';
	if(window.ActiveXObject) {
		sc.onreadystatechange = function(){
			if(sc.readyState!='complete' && sc.readyState!='loaded' && xxsx==0) {
				var sids = setTimeout(function() {
					clearTimeout(sids);
					JavaScriptLoader(geturl, jd);
				}, 5000);
			}else {
				xxsx = 1;
			}
		};
	}
	sc.src = geturl;
	document.body.appendChild(sc);
	var sid = setTimeout(function() {
		clearTimeout(sid);
		if(play_start==0 && ch_id!=-1 && !jd) {
			setErrorMsg(1);
		}
	}, 20000);
/*
			if(sc.readyState=='complete' || sc.readyState=='loaded') {
	document.getElementsByTagName("head")[0].appendChild(sc);

0（初期化されていない）uninitialized
1（読み込み中）loading
2（読み込み完了）loaded
3（操作可能）interactive
4（準備完了）complete

*/
}

// Audioscrobbler JSON
function Audioscrobblercallback(json) {
	if(json==null || typeof(json)!="object") {
		setErrorMsg(2);
		return;
	}
	feed_list[9] = _hesc(json.id).split(',');
	ch_list[11] = feed_list[9][0] + '":"79":"' + feed_list[9][0];
	getCH(11, '', 2);
}
// Audioscrobbler1 JSON
function Audioscrobblercallback1(json) {
	if(json==null || typeof(json)!="object") {
		return;
	}
	var a = _hesc(json.id).split(',');
	for(var i=0; i<tag_list.length; i++) {
		if(a[0].slice(1)==tag_list[i][0]) {
			feed_list[i] = a.slice(1);
			var p = (i<6) ? 1 : 2;
			if(a[0].slice(0, 1)==1) {
				fillEachChMenu(i+p);
			}else {
				getCH(i+p, '', 1);
			}
			break;
		}
	}
}
// YouTube JSON
function youtubeEcho(json) {
	if(json==null || typeof(json)!="object") {
		setErrorMsg(3);
		return;
	}
	var entries = json.feed.entry;
	if(!entries) {
		return;
	}
	entry_len = entries.length;
	if(shufflePref=="Yes") {
		var array = shuffle(entry_len);
	}
	for(var i=0; i<entries.length; ++i) {
		var ix = (shufflePref=="Yes") ? array[i] : i;
		ytitle[ix] = _hesc(entries[i].title.$t);
		ycontent[ix] = _hesc(entries[i].content.$t);
		ypublished[ix] = (entries[i].published) ? _hesc(entries[i].published.$t) : "";
		ycount[ix] = _hesc(entries[i].yt$statistics.viewCount);
		yrating[ix] = (entries[i].gd$rating) ? _hesc(entries[i].gd$rating.average) + " (" + numberFormat(entries[i].gd$rating.numRaters) + " ratings)" : "";
		for(var ic=0; ic<entries[i].media$group.media$content.length; ic++) {
			if(entries[i].media$group.media$content[ic].url.slice(0, 4)=="http") {
				yurl[ix] = _hesc(entries[i].media$group.media$content[ic].url);
				ydur[ix] = _hesc(entries[i].media$group.media$content[ic].duration);
			}
		}
		yvurl[ix] = _hesc(entries[i].media$group.media$player[0].url);
	}
	entry_no = 0;
	play_start = 1;
	playClip();
}
// YouTube JSON
function youtubecallback(json) {
	if(json==null || typeof(json)!="object") {
		setErrorMsg(3);
		return;
	}
	var entries = json.feed.entry;
	if(!entries) {
		return;
	}
	entry_len = entries.length;
	if(shufflePref=="Yes") {
		var array = shuffle(entry_len);
	}
	for(var i=0; i<entries.length; ++i) {
		var ix = (shufflePref=="Yes") ? array[i] : i;
		ytitle[ix] = _hesc(entries[i].title.$t);
		ycontent[ix] = _hesc(entries[i].content.$t);
		ypublished[ix] = (entries[i].published) ? _hesc(entries[i].published.$t) : "";
		ycount[ix] = _hesc(entries[i].yt$statistics.viewCount);
		yrating[ix] = (entries[i].gd$rating) ? _hesc(entries[i].gd$rating.average) + " (" + numberFormat(entries[i].gd$rating.numRaters) + " ratings)" : "";
		for(var ic=0; ic<entries[i].media$group.media$content.length; ic++) {
			if(entries[i].media$group.media$content[ic].url.slice(0, 4)=="http") {
				yurl[ix] = _hesc(entries[i].media$group.media$content[ic].url);
				ydur[ix] = _hesc(entries[i].media$group.media$content[ic].duration);
			}
		}
		yvurl[ix] = _hesc(entries[i].media$group.media$player[0].url);
	}
	entry_no = 0;
	play_start = 1;
	playClip();
}
/*----------------------------------------
	5. Video Player
----------------------------------------*/
// Video Player
function playClip(jd) {
	clearTimeout(settimeid);
	entry_no = (!jd) ? entry_no+1 : ((jd==2) ? entry_no : entry_no-1);
	if(entry_no<1) {
		entry_no = (!jd) ? entry_no-1 : ((jd==2) ? entry_no : entry_no+1);
		return;
	}else if(entry_no>entry_len) {
		if(shufflePref=="Yes") {
			return getCH(ch_no);
		}else {
			return getCH(ch_no, "'" + (feed_no+1) + "'");
		}
	}else if(!yurl[0]) {
		return showdiv('menu');
	}
	fillMenu();
	_gel('chname0').innerHTML = rChname0();
	_gel('chname1').innerHTML = rChname1();
	if(!(yurl[entry_no-1] || ydur[entry_no-1])) {
		_gel("main").innerHTML = "<p>we're sorry this video is no longer available</p>";
		settimeid = setTimeout('playClip()', 5000);
		return;
	}
/*
	writeFlashHTML(yurl[entry_no-1], size(sizeid));
*/
	writeFlashHTML(yurl[entry_no-1] + '&fmt=22', size(sizeid));
	play_jd = 1;
	fillVideoInfo(entry_no-1);
	var ctime= (parseInt(ydur[entry_no-1])+10)*1000;
	settimeid = setTimeout('playClip()', ctime);
}
// Stop Video
function stopPlayer() {
	if(play_start==0) {
		return;
	}
	clearTimeout(settimeid);
	play_jd = 0;
	_gel("main").innerHTML = [
'<h2 class="load">' + ytitle[entry_no-1] + ' (' + durChange(ydur[entry_no-1]) + ')</h2>',
'<input src="' + rurl + 'start.gif" onclick="playClip(2);" title="' + __MSG_PLAYINGTHISVIDEO__ + '" type="image" />',
'<p><a onclick="startCh(1);" href="javascript:void(0);">HOME</a></p>'
].join("");
}
// Shuffle Video
function shuffle(entry_len) {
	var array = [];
	for(var i=0; i<entry_len; i++) {
		array[i] = i;
	}
	return array.sort(function(a, b) {
		return Math.random()-0.5;
	});
}
// Jump Video
function jumpVideo(nr) {
	entry_no = parseInt(nr);
	playClip();
}
/*----------------------------------------
	6. Display
----------------------------------------*/
// Display Channel
function fillChMenu() {
	var menus = '<li><strong style="font-size: 120%;"> ' + __MSG_CHANNEL__ + '</strong></li>';
	for(var i=0; i<ch_list.length; i++) {
		var z = returnFeedlist(i);
		if(z[3].length>0) {
			var add = (i==ch_no && play_start) ? ['<strong>', '</strong>'] : ['', ''];
			var i89 = (z[0]=="78") ? Img('fav.gif') : ((z[0]=="79") ? Img('m7.png') : Img('m9.png'));
			var more = (z[3].length>0) ? '<span class="fright"> &raquo;<a onClick="fillEachJd(' + i + ');" href="javascript:void(0);" title="' + __MSG_SHOWSUBCH__ + '">' + __MSG_DETAILS__ + '</a></span>' : '';
			menus += [
'<li id="lists' + i + '" style="clear:right;">',
	more,
	i89,
	add[0],
	_hesc(z[5]),
	add[1],
	'<input src="' + rurl + 'm999.gif" onClick="fillChannelJd(' + i + ');" title="' + __MSG_PLAYINGTHISCH__ + '" type="image" onmouseover="chSelectBg(' + i + ');" onmouseout="chSelectBg(' + i + ', 1);" />',
'</li>'
].join("");
		}
	}
	var p = (play_start) ? '<div style="padding:10px 0; text-align:center;"><input id="wordid" value=""style="width:80%;" /><br /><input type="button" value="' + __MSG_SIMILAR__ + '" onClick="getWord();" maxlength="50" /></div>' + getSimilar(5) : '';
	_gel('menu').innerHTML = '<ul class="listdl">' + menus + '</ul>' + p + '<br />.';
	showdiv('menu');
}
// Display Playlist
function fillPlaylist() {
	var html = '<ul class="listdl">';
	for(var i=0; i<entry_len; i++) {
		var prr=[];
		if(entry_no!=i+1) {
			prr = ['<a title="' + __MSG_PLAYINGTHISVIDEO__ + '" onclick="jumpVideo(' + i + ')" href="javascript:void(0);" class="pimg">', '</a>'];
		}else {
			prr = ['<strong>', ' <a href="javascript:void(0);" onclick="fillVideoInfo(' + i + ');" title="' + __MSG_THISVIDEOINFORMATION__ + '"><img src="' + rurl + 'info.png" alt="Info" /></a></strong>'];
		}
		var ii = (i>8) ? i+1 : "&nbsp;" + (i+1);
		html += [
'<li>',
ii + '.&nbsp;',
prr[0],
ytitle[i],
" (" + durChange(ydur[i]) + " )",
prr[1],
'</li>'
].join("");
	}
	menu_no = 2;
	fillMenu();
	_gel('menu').innerHTML = [
html,
'<li><strong>' + __MSG_ARTIST__ + ':</strong> ' + ch_title + ' &nbsp; <input src="./img/add.gif" onclick="favoritesAdd(\'' + ch_title.replace(/'/g, "\\'") + '\');" title="' + __MSG_ARTISTSLISTADD__ + '" type="image" /></li>',
'</ul><br />.'
].join("");
	showdiv('menu');
}
// Display video info
function fillVideoInfo(id) {
	menu_no = 1;
	fillMenu();
	var d = (ypublished[id]) ? String(ypublished[id]).slice(0, 10) : "-";
	var y = ' (<a href="javascript:void(0);" onclick="showHide(\'ys\'); showHide(\'yr\');">';
	var c = (!ycontent[id]) ? '' : ((ycontent[id].length<100) ? ycontent[id] : '<span id="yr">' + ycontent[id].slice(0, 100) + y + 'more</a>)</span><span id="ys" style="display:none;">' + ycontent[id] + y + 'less</a>)</span>');
	var z = returnFeedlist(ch_no);
	_gel('menu').innerHTML = [
'<ul class="listdl">',
	'<li><strong style="font-size:120%;">' + ytitle[id] + '</strong></li>',
	'<li>' + c + '</li>',
	'<li><strong>' + __MSG_ARTIST__ + ':</strong> <a href="javascript:void(0);" onclick="fillPlaylist();" title="' + __MSG_SHOWPLAYLIST__ + '">' + ch_title + '</a> &nbsp; <input src="./img/add.gif" onclick="favoritesAdd(\'' + ch_title.replace(/'/g, "\\'") + '\');" title="' + __MSG_ARTISTSLISTADD__ + '" type="image" /></li>',
	'<li><strong>' + __MSG_CHANNEL__ + ':</strong> <a href="javascript:void(0);" onclick="ShowChannel(1, ' + ch_no + ');" title="' + __MSG_SHOWSUBCH__ + '">' + z[5] + '</a></li>',
	'<li><strong>' + __MSG_ADDED__ + ':</strong> ' + d + '</li>',
	'<li><strong>' + __MSG_TIME__ + ':</strong> ' + durChange(ydur[id]) + '</li>',
	'<li><strong>' + __MSG_VIEWS__ + ':</strong> ' + numberFormat(ycount[id]) + '</li>',
	'<li><strong>' + __MSG_RATE__ + ':</strong> ' + yrating[id] + '</li>',
	similarSelect("'" + ch_title + "'", z),
'</ul><br />.'
].join("");
	showdiv('menu');
}
// Display Menu
function fillMenu() {
	showdiv('menu');
	var qp = (q[0]=='mobile=1' || q[1]=='mobile=1') ? '' : ' class="fright"';
	var sm = ['<div id="sizetitle"' + qp + '>', '</div>'];
	var x = (play_start==0) ? sm[0] + sm[1] : sm[0] + fillSizeMenu() + sm[1];
	var st = (menu_no==0) ? ['<strong>', '</strong>'] : ['', ''];
	x += [
'<a onclick="ShowChannel();" href="javascript:void(0);" title="' + __MSG_SHOWCHANNEL__ + '">',
st[0] + 'HOME' + st[1],
'</a>&nbsp;&nbsp;'
].join("");
	var st1 = (menu_no==1) ? ['<strong>', '</strong>'] : ['<a onclick="fillVideoInfo(' + (entry_no-1) + ');" href="javascript:void(0);" title="' + __MSG_THISVIDEOINFORMATION__ + '">', '</a> '];
	var st2 = (menu_no==2) ? ['<strong>', '</strong>'] : ['<a onclick="fillPlaylist();" href="javascript:void(0);" title="' + __MSG_SHOWPLAYLIST__ + '">', '</a> '];
	var st3 = (menu_no==3) ? ['<strong>', '</strong>'] : ['<a onclick="fillHelp();" href="javascript:void(0);" title="' + __MSG_HELP__ + '">', '</a> '];
	var st4 = (menu_no==4) ? ['<strong>', '</strong>'] : ['<a onclick="ShowChannel(1, 10);" href="javascript:void(0);" title="' + __MSG_ARTISTSLIST__ + '">', '</a> '];
	x += (play_start==0) ? __MSG_INFO__ + '&nbsp;&nbsp;' + __MSG_PLAYLIST__ : [
st1[0],
__MSG_INFO__,
st1[1],
'&nbsp;&nbsp;',
st2[0],
__MSG_PLAYLIST__,
st2[1]
].join("");
	var lenf = feed_list[8].length;
	lenf = (lenf) ? '(' + lenf + ')' : '';
	x += [
'&nbsp;&nbsp;',
st4[0],
 Img("fav.gif") + __MSG_FAVORITES__ + lenf,
st4[1],
'&nbsp;&nbsp;',
st3[0] + __MSG_HELP__ + st3[1],
'&nbsp;&nbsp;',
'<input type="image" src="' + rurl + 'hideshow.png" onClick="hideShowMenu();" title="' + __MSG_HIDESHOWMENU__ + '" />'
].join("");
	var lang = (q[0]=='lan=ja') ? '&lan=ja' : '';
	var mob = (q[0]=='mobile=1' || q[1]=='mobile=1') ? '' : '<a href="./?mobile=1' + lang + '">' + __MSG_MOBILE__ + '</a>&nbsp;&nbsp;';
	_gel("header").innerHTML = '<nobr>' + mob + x + '</nobr>';
}
// Display Help
function fillHelp() {
	menu_no = 3;
	fillMenu();
	_gel('menu').innerHTML = [
'<dl class="listdl">',
'<dt>' + __MSG_DESCRIPT__ + '</dt>',
	'<dd>' + __MSG_DESCRIPTION2__ + __MSG_DESCRIPTION1__ + '</dd>',
'<dt>' + __MSG_SIMILAR__ + ' ' + Img("m7.png") + '</dt>',
	'<dd>' + __MSG_D_SEARCH__ + '</dd>',
'<dt>' + __MSG_FAVORITES__ + ' ' + Img("fav.gif") + '</dt>',
	'<dd>' + __MSG_D_ARTISTSLIST__ + '</dd>',
'<dt>' + __MSG_CHANGEARTIST__ + ' ' + Img("down.png") + '</dt>',
	'<dd>' + __MSG_D_CHANGEARTIST__ + '</dd>',
'<dt>' + __MSG_NEXTVIDEO__ + ' ' + Img("next.png") + '</dt>',
	'<dd>' + __MSG_D_VIDEOSKIP__ + '</dd>',
'<dt>' + __MSG_SHUFFLE__ + ' ' + Img("shuffle2.gif") + Img("shuffle1.gif") + '</dt>',
	'<dd>' + __MSG_D_SHUFFLE__ + '</dd>',
'<dt>' + __MSG_CHANGECAT__ + '</dt>',
	'<dd>' + Img("m9.png") + __MSG_STATICCHANNEL__ + '</dd>',
	'<dd>' + Img("fav.gif") + __MSG_FAVORITES__ + '</dd>',
	'<dd>' + Img("m7.png") + __MSG_SIMILAR__ + '</dd>',
'<dt>' + __MSG_CONTACTUS__ + '</dt>',
	'<dd><a href="http://ma-bank.com/" target="_blank">ma-bank.com</a></dd>',
	'<dd>(*<a href="&#109;&#97;i&#108;t&#111;&#58;in&#102;o&#64;ma&#45;&#98;&#97;&#110;k&#46;c&#111;&#109;">&#105;&#110;&#102;&#111;&#64;&#109;&#97;&#45;&#98;&#97;&#110;&#107;&#46;&#99;&#111;&#109;</a>)</dd>',
'<dt>Powered by</dt>',
	'<dd><a href="http://code.google.com/apis/youtube/" target="_blank">YouTube Data API</a></dd>',
	'<dd><a href="http://www.audioscrobbler.net/data/webservices/" target="_blank">Audioscrobbler Web Services</a></dd>',
'</dl>',
'<br />.'
].join("");
	showdiv('menu');
}
// Display Size Menu
function fillSizeMenu() {
	var t = '';
	var a = [180, 240, 360, 480, 600, 720];
	for(var i=0; i<a.length; i++) {
		t += (i==sizeid) ? '<strong>' + a[i] + '</strong> ' : '<a onclick="sizeChange(' + i + ');" href="javascript:void(0);">' + a[i] + '</a> ';
	}
	return Img("wide.png", "size") + __MSG_SIZE__ + ': ' + t;
}
// Display each Channel
function fillEachChMenu(iii) {
	var z = returnFeedlist(iii);
	var i89 = (z[0]=="78") ? Img('fav.gif') : ((z[0]=="79") ? Img('m7.png') : Img('m9.png'));
//	var lc = (z[3].length>0) ? ['<a onclick="getCH(\'' + iii + '\');" href="javascript:void(0);" title="' + __MSG_PLAYINGTHISCH__ + '" class="pimg">', '</a>'] : ['', ''];
	var lc = (z[3].length>0) ? '<input src="' + rurl + 'm999.gif" onClick="getCH(\'' + iii + '\');" title="' + __MSG_PLAYINGTHISCH__ + '" type="image" onmouseover="chSelectBg(\'a\');" onmouseout="chSelectBg(\'a\', 1);" />' : '';
	var menus = [
'<li id="listsa">',
	i89,
	'<strong style="font-size:120%;">' + _hesc(z[5]) + '</strong>' + lc,
'</li>'
].join("");
	for(var i=0; i<z[3].length; i++) {
		var name = _hesc(z[3][i]);
		var ii = (i>8) ? i+1 : "&nbsp;" + (i+1);
		var add = (i==feed_no && play_start && z[0]==ch_id) ? ['<strong>', '</strong>'] : ['<a onclick="getCH(\'' + iii + '\', \'' + i + '\');" href="javascript:void(0);" title="' + __MSG_PLAYINGTHISSUBCH__ + '" class="pimg">', '</a>'];
		var w = (iii==10) ? [i + '\', \'1', __MSG_ARTISTSLISTDEL__, 'del'] : [name.replace(/'/g, "\\'"), __MSG_ARTISTSLISTADD__, 'add'];
		menus += '<li>' + ii + '.&nbsp;' + add[0] + name + add[1] + ' &nbsp; <input src="./img/' + w[2] + '.gif" onclick="favoritesAdd(\'' + w[0] + '\');" title="' + w[1] + '" type="image"></li>';
	}
	menus = (z[3].length>0) ? menus : menus + "<li><p>" + __MSG_ARTISTSLISTNO__ + "</p>" + __MSG_D_ARTISTSLIST__ + "</li>";
	_gel('menu').innerHTML = '<ul class="listdl">' + menus + '</ul><br />.';
}
/*----------------------------------------
	8. Other Channel
----------------------------------------*/
// Channel Judge
function fillChannelJd(iii) {
	var z = returnFeedlist(iii);
	if(z[3].length>2) {
		getCH(iii, '', 1);
	}else {
		getEachTag(z[3][0], 2);
	}
}
// Each Channel Judge
function fillEachJd(iii) {
	var z = returnFeedlist(iii);
	if(iii==10) {
		menu_no = 4;
		fillMenu();
		fillEachChMenu(10);
	}else if(z[3].length>2) {
		fillEachChMenu(iii);
	}else {
		getEachTag(z[3][0], 1);
	}
}
// Get Similar Artists
function getSimilar(num) {
	var t = '';
	var id = (play_start==1) ? ch_no : ((!location.search) ? 0 : 7);
	var z = returnFeedlist(id);
	if(z[3].length>1) {
		var a = [];
		var array = shuffle(z[3].length);
		for(var i=0; i<z[3].length; i++) {
			var ix = array[i];
			if(z[3][i]!=ch_id) {
				a[ix] = '<a onclick="getWord(\'' + z[3][i].replace(/'/g, "\\'") + '\')" href="javascript:void(0);" class="pimg" title="' + __MSG_SIMILARSEARCH__ + '">' + Img("m7.png") + z[3][i] + '</a> &nbsp; ';
			}
		}
		t = a.slice(0, num).join('');
	}
	return t;
}
// Display Top page
function showTopPage(jd) {
	var a = (jd==1) ? '' : getSimilar(10);
	var id = (!location.search) ? 'en' : 'ja';
	return [
	'<h1>FmTube</h1>',
	'<h2>' + __MSG_DESCRIPTION__ + '</h2>',
	'<input id="wordid" value="" style="width:200px;" maxlength="50" /> ',
	'<input type="button" value="' + __MSG_SIMILAR__ + '" onClick="getWord();" />',
	'<div style="text-align:left; padding:30px;">' + a + '</div>',
	'* ' + __MSG_DESCRIPTION1__,
	'<hr style="border:1px dotted #ccc;" />',
	AddGoogle() + ' | <a href="http://gmodules.com/ig/creator?synd=open&url=http%3A//jun1969x.googlepages.com/fmtube.xml&hl=' + id + '" target="_blank">' + __MSG_BLOGPARTS__ + '</a> | <a href="./">English</a> | <a href="./?lan=ja">日本語</a><br />'
	].join("");
}
// Show Channel
function ShowChannel(jd, n) {
	if(!jd) {
		fillChMenu();
	}else {
		fillEachChMenu(n);
	}
	showdiv('menu');
	menu_no = (n!=10) ? 0 : 4;
	fillMenu();
}
// Check text byte
function cTextByte(newfeed) {
	var count = 0;
	for(i=0; i<newfeed.length; i++) {
		(escape(newfeed.charAt(i)).length<4) ? count++ : count+=2;
	}
	if(count>1500){
		alert("[Caution] Text byte over.");
		return false;
	}
}
/*----------------------------------------
	9. Other
----------------------------------------*/
// Return feed list
function returnFeedlist(no) {
	var t = ch_list[no].split('":"');
	var z = String(t[1]);
	var z1 = z.slice(0, 1);
	var z2 = parseInt(z.slice(1), 10);
	var zarray = (z1=="7") ? feed_list[z2] : feed80_list[z2][1].split(',');
	return [z, z1, z2, zarray, t, String(t[2])];
}
// Favorites list Add
function favoritesAdd(id, jd) {
	if(!jd) {
		if(cTextByte(feed_list[8].join('').length)==false) {
			return;
		}
		for(var i=0; i<feed_list[8].length; i++) {
			if(feed_list[8][i]==id) {
				return;
			}
		}
		feed_list[8].push(id);
	}else {
		feed_list[8].splice(id, 1);
		fillEachChMenu(10);
	}
	fillMenu();
}
// Similar Artist Select
function similarSelect(tid, z) {
	var a = [];
	var array = shuffle(z[3].length);
	for(var i=0; i<z[3].length; i++) {
		var ix = array[i];
		if(z[3][i]!=tid) {
			var ixs = (ix>8) ? ix+1 : '&nbsp;' + (ix+1);
			a[ix] = '<li>' + ixs + '.&nbsp;<a onclick="getCH(\'' + ch_no + '\', \'' + i + '\');" href="javascript:void(0);" title="' + __MSG_PLAYINGTHISSUBCH__ + '" class="pimg">' + z[3][i] + '</a> &nbsp; <input src="./img/add.gif" onclick="favoritesAdd(\'' + z[3][i].replace(/'/g, "\\'") + '\');" title="' + __MSG_ARTISTSLISTADD__ + '" type="image"></li>';
		}
	}
	var i89 = (z[0]=="78") ? 8 : ((z[0]=="79") ? 7 : 9);
	return '<li><strong>' + __MSG_SIMILARARTISTS__ + ':</strong></li>' + a.slice(0, 10).join('') + '<li>&nbsp;&raquo;<a href="javascript:void(0);" onclick="ShowChannel(1, ' + ch_no + ');" title="' + __MSG_SHOWSUBCH__ + '">more</a></li>';
}
// Display Size
function size(id) {
	switch(id) {
	case 0 :
		return 180;
	case 1 :
		return 240;
	case 3 :
		return 480;
	case 4 :
		return 600;
	case 5 :
		return 720;
	default :
		return 360;
	}
}
// Change Size
function sizeChange(id) {
	if(play_jd==0) {
		return;
	}
	sizeid = id;
	_gel('hflash').style.height = size(id) + 'px';
	_gel('hflash').style.width = (size(id)*16/9) + 'px';
	_gel('sizetitle').innerHTML = fillSizeMenu();
	_gel('sizetitle2').innerHTML = fillSizeMenu();
}
// Number format
function numberFormat(i) {
	return String(i).replace(/[0-9]+/gm, function(chr) {
		var k, cnt=0, n="";
		for(k=chr.length-1; k>=0; k--) {
			n = chr.charAt(k) + n;
			cnt++;
			if(!(cnt%3) && k) {
				n = "," + n;
			}
		}
		return n;
	});
}
// Duration Change
function durChange(dur) {
	dur = parseInt(dur);
	var a = (dur%60>9) ? dur%60 : "0" + (dur%60);
	return Math.floor(dur/60) + ":" + a;
}
function rChname0() {
	var gx = (shufflePref=="Yes") ? '' : ', \'' + (feed_no+1) + '\'';
	return '<input type="image" src="' + rurl + 'down.png" onClick="getCH(\'' + ch_no + '\'' + gx + ');" title="' + __MSG_CHANGEARTIST__ + '" /> ';
}
function rChname1() {
	var sx = (shufflePref=="Yes") ? 2 : 1;
	return [
'<input type="image" src="' + rurl + 'stop.png" onClick="stopPlayer();" title="' + __MSG_STOPPLAYING__ + '" /> ',
'<input type="image" src="' + rurl + 'next.png" onClick="playClip();" title="' + __MSG_NEXTVIDEO__ + '" /> ',
'<input type="image" src="' + rurl + 'shuffle' + sx + '.gif" onClick="changeShuffle();" title="' + __MSG_CHANGESHUFFLE__ + '" id="shuffleimg" /> ',
'*' + ytitle[entry_no-1] + ' (' + durChange(ydur[entry_no-1]) + ')'
].join("");
}
// Change Shuffle
function changeShuffle() {
	shufflePref = (shufflePref=="Yes") ? "No" : "Yes";
	var sx = (shufflePref=="Yes") ? 2 : 1;
	_gel("shuffleimg").src = rurl + 'shuffle' + sx + '.gif';
	_gel('chname0').innerHTML = rChname0();
}
// Selected Channel Bgcolor
function chSelectBg(id, jd) {
	_gel("lists" + id).style.backgroundColor = (!jd) ? 'yellow' : 'fffffe';
}
// Show Div
function showdiv(id) {
	_gel(id).style.display = 'block';
}
// ShowHide Div
function showHide(id) {
	var a = _gel(id).style;
	a.display = (a.display=='none') ? 'block' : 'none';
}
// ShowHide Menu Bar
function hideShowMenu() {
	var a = _gel("menu").style;
	var b = _gel("main").style;
	a.display = (a.display=='none') ? '' : 'none';
	b.marginLeft = (a.display=='none') ? '0' : '30%';
	hidemenu = (hidemenu) ? 0 : 1;
}
// Img 
function Img(id, icon) {
	icon = (icon) ? icon : 'icon';
	return '<img src="' + rurl + id + '" alt="' + icon + '" />';
}
// Error Msg
function setErrorMsg(id) {
	_gel("main").innerHTML = '<p>Invalid data. No response from YouTube.com (' + id + ')</p>' +	showTopPage();
	fillChMenu();
}
// document.getElementById
function _gel(tagId) {
	return document.getElementById(tagId);
}
// hesc
function _hesc(s) {
	if(!s) return;
	return String(s).replace(/([<>&"'])/gm, function(m0, m1) {
		return {'<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;', '\'': '&#039;'}[m1];
	});
}
// http://allabout.co.jp/internet/javascript/closeup/CU20050515A/
// XMLHttpRequestオブジェクト
function createXMLHttpRequest(){
	if(window.ActiveXObject){
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e2) {
				return null;
			}
		}
	}else if(window.XMLHttpRequest) {
		return new XMLHttpRequest();
	}else {
		return null;
	}
}

