
d6Sort = "all"; // 試合リストのソート形式
scoreStatus = "hidden"; // スコアボードの表示・非表示
movieType = "h"; // h: 高画質、 n: 標準画質

/**
 * ASXファイルから動画を再生します
 */
function playMovie() {
	var query = window.location.search.substring(1);
	if (query.length) {
	
		var asxfile = getAsxPath(query);
		// document.write("<span style=\"color:#fff\">" + asxfile + "</span>");
	
		document.write("<object id=\"Player\" width=\"480\" height=\"425\" classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" type=\"application/x-oleobjec\">");
		document.write("<param name=\"URL\" value=\"" + asxfile + "\" />");
		document.write("<param name=\"AutoStart\" value=\"true\" />");
		document.write("<param name=\"uiMode\" value=\"full\" />");
		document.write("<embed type=\"application/x-mplayer2\" src=\"" + asxfile + "\" name=\"Player\" ShowStatusBar=\"1\" AutoStart=\"1\" width=\"480\" height=\"425\"></embed>");
		document.write("</object>");
		
		var movie_type = query.substring(query.length - 1);
		if (movie_type == "h" || movie_type == "n") {
			top.movieType = movie_type;
		}
	
	} else {
		document.write("<span style=\"text-align:center; color:#fff; font-size:smaller\">［エラー］アドレスが指定されていません</span>");
	}
}

/**
 * ウィンドウを閉じて、親にフォーカスを当てます
 */
function closeWindow() {
	window.close();
	window.opener.focus();
}

/**
 * ASXファイルの完全パスを取得します
 */
function getAsxPath(id) {
	// return "http://centauri.4cast.co.jp/meta/k/1800/" + id + ".asx";
	return "asx/" + id + ".asx";
}

/**
 * 大学IDで大学名を取得します
 */
function getD6Name(id) {
	switch (id) {
		case "tokyo":
			return "東京大学";
			break;
		case "waseda":
			return "早稲田大学";
			break;
		case "rikkio":
			return "立教大学";
			break;
		case "hosei":
			return "法政大学";
			break;
		case "keio":
			return "慶応大学";
			break;
		case "meiji":
			return "明治大学";
			break;
	}
}

/**
 * Playerインラインフレームを表示します。
 * 引数に再生するASXのIDをとります。
 *
 * 親ページのURLクエリは、
 * 「高画質ASX,標準画質ASX」である必要があります。
 */
function setPlayer() {
	var query = window.location.search.substring(1);
	if (query.length) {
		document.write("<iframe id=\"fPlayer\" name=\"fPlayer\" width=\"480\" height=\"425\" marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\" scrolling=\"no\" src=\"select.html?" + query + "\">");
		document.write("東京六大学野球を動画で視聴頂くにはフレーム対応のブラウザでご覧下さい。</iframe>");
	} else {
		document.write("<p style=\"color:#fff; text-align:center; line-height:425px;\">ASX IDが確認できません</p>");
	}
}

/**
 * プレイヤに渡すURLを取得します。
 */
function getPlayerUrl() {
	if (window.location.search.substring(1).length) {
		var query = window.location.search.substring(2);
		var player = "player.html";
		
		document.write("<div id=\"high\">");
		document.write("<a href=\"" + player + "?" + query + "_h\">高画質再生</a></div>");
		document.write("<div id=\"low\">");
		document.write("<a href=\"" + player + "?" + query + "_n\">標準画質再生</a></div>");
	}
}

/**
 * 試合リストをセットします
 */
function setD6List(d6List, asxId) {
	var url = asxId;
	var week = "第" + d6List.week + "週";
	var day = d6List.day;
	var game = "第" + d6List.game + "試合";
	var team1 = "<img src=\"movie_item/logo/" + d6List.team1 + "_s.gif\" alt=\"" + getD6Name(d6List.team1) + "\" width=\"42\" height=\"23\" />";
	var team2 = "<img src=\"movie_item/logo/" + d6List.team2 + "_s.gif\" alt=\"" + getD6Name(d6List.team2) + "\" width=\"42\" height=\"23\" />";
	var src = "<li id=\"" + asxId + "\"><a href=\"movie.html?" + asxId + "\" target=\"_self\">" + week + "&nbsp;" + day + "&nbsp;" + game + "&nbsp;" + team1 + "&nbsp;<img src=\"movie_item/mark/list_vs.gif\" alt=\"VS\" width=\"20\" height=\"20\" />&nbsp;" + team2 + "</a></li>";
	return src;
}

/**
 * 試合名をセットします
 */
function setMatchTitle(match) {
	var week = "第" + match.week + "週";
	var day = match.day;
	var game = "第" + match.game + "試合";
	var src = week + "　" + day + "　" + game;
	return src;
}

/**
 * 大学名とロゴを表示します
 */
function setUniversity(match, position) {
	var src = "";
	switch (position) {
		case "left":
			src += getD6Name(match.team1);
			src += "<img src=\"movie_item/logo/" + match.team1 + "_m.gif\" alt=\"" + match.team1.toUpperCase() + "\" width=\"60\" height=\"33\" class=\"logo\" />";
			break;
		case "right":
			src += "<img src=\"movie_item/logo/" + match.team2 + "_m.gif\" alt=\"" + match.team2.toUpperCase() + "\" width=\"60\" height=\"33\" class=\"logo\" />";
			src += getD6Name(match.team2);
			break;
	}
	return src;
}

/**
 * 数字を２桁の文字列にします
 */
function sn(num) {
	if (num < 10) {
		return "0" + num;
	} else {
		return num;
	}
}
