﻿dojo.require("dojo.widget.ContentPane");
dojo.require("dojo.widget.LayoutContainer");
dojo.require("dojo.widget.LinkPane");
dojo.require("dojo.widget.HtmlWidget");
dojo.require("dojo.widget.html.ComboBox");
dojo.require("dojo.widget.TitlePane");
dojo.require("dojo.widget.TabContainer");
dojo.require("dojo.widget.Button");
dojo.require("dojo.widget.TaskBar");
dojo.require("dojo.io.*");
dojo.hostenv.writeIncludes();

var MaxEpisode = 138;
var MaxHistory = 15;
var noEpisode = 'まだ、そのエピソードは、表示できません。'

var TopicsName = { 'content1' : '話数別目次', 'content2' : '作曲者別目次', 'content3' : '劇場別目次', 'about' : 'このサイトについて', 'link' : 'リンクについて', 'sitemap' : 'サイトマップ',  'update' : '更新履歴', 'news' : 'ニュース', 'index' : 'トップページ' };
var revTopicsName = {'話数別' : 'content1', '作曲者別' : 'content2', '劇場別' : 'content3', 'About This Site' : 'about', 'About Link' : 'link', 'Update' : 'update', 'Sitemap' : 'sitemap'};
var count=0; var _udt=new Date(); var _uu=Math.round(Math.random()*2157483647); var _ust=Math.round(_udt.getTime()/1200); var uid='id'+_uu+_ust; var hstr = new Array; var encode64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var re1 = new RegExp("[\\\\\/]episode([^\\\\\/]+)\.html$", ""); var re2 = new RegExp("[\\\\\/]([^\\\\\/]+)\.html$", ""); var name = getURLPathName(document.location.pathname);
dojo.addOnLoad(init);
function getURLPathName(str) { if (str.match(re1)) { return RegExp.$1; } else if (str.match(re2)) { return RegExp.$1; } return "index"; }
function init() { if (name == 'index') { addhistory(name); }  else { moveTopics(name); }}
function _loadinit() { return; }
/* ヒストリー処理 */
function getmain() { return dojo.widget.byId('main'); }
function addhistory(topics) { addhistory2(topics, TopicsName[topics]); }
function addhistory2(topics, str) { if (hstr.length >= MaxHistory) { hstr.shift(); } var work = '<a href="javascript:moveTopics(' + "'" + topics + "'" + ')">' + str + '</a>'; if (hstr[hstr.length-1] == work) {return ;} hstr.push(work); hstr.reverse(); var buff = hstr.join("<br />"); dojo.widget.byId('history').setContent(buff); hstr.reverse();moblog(topics); }
function moblog(topics) { var argsurl = encode64(topics+'+'+uid+'+'+count+'+end'); count++; var logurl = "http://niki.ring.jp/info.html?code=" + argsurl;	dojo.io.bind ({url: logurl, mimetype: "text/plain",	load: function(type, data, evt){} });}
function addhistory3(obj) { var str = revTopicsName[obj.label]; if (typeof(str) != 'undefined') { addhistory(str); }}
/* ヒストリー処理 */

/* 移動 */
function moveTopics(topics) {
if (topics == "content1") {	getmain().addOnLoad(function(){moveTab(topics);}); getmain().setUrl('src/content.html');
} else if (topics == "content2") { getmain().addOnLoad(function(){moveTab(topics);}); getmain().setUrl('src/content.html');
} else if (topics == "content3") { getmain().addOnLoad(function(){moveTab(topics);}); getmain().setUrl('src/content.html');
} else if (topics == "about") { getmain().addOnLoad(function(){moveTab(topics);}); getmain().setUrl('src/other.html');
} else if (topics == "link") { getmain().addOnLoad(function(){moveTab(topics);}); getmain().setUrl('src/other.html');
} else if (topics == "update") { getmain().addOnLoad(function(){moveTab(topics);}); getmain().setUrl('src/other.html');
} else if (topics == "sitemap") { getmain().addOnLoad(function(){moveTab(topics);}); getmain().setUrl('src/other.html');
} else if (topics == "news") { getmain().setUrl('src/news.html');
} else if (topics == "index") { getmain().setUrl('src/index.html');
} else { moveEpisode(topics); return ; }
addhistory(topics);
}
function moveEpisode(no) { 
	if (MaxEpisode-no >= 0) { getmain().setUrl('episode/episode' + no + '.html'); addhistory2(no, '第' + no + '話'); return ; }
	alert(noEpisode);
}
function moveTab(topics) { dojo.widget.byId('mainTabContainer').selectTab(dojo.widget.byId(topics)); }
/* 移動 */
function encode64(str) {
var out, i, len, c1, c2, c3; len = str.length; i = 0; out = "";
while(i < len) {
	c1 = str.charCodeAt(i++) & 0xff; if(i == len) { out += encode64Chars.charAt(c1 >> 2); out += encode64Chars.charAt((c1 & 0x3) << 4); out += "=="; break; }
	c2 = str.charCodeAt(i++); if(i == len) { out += encode64Chars.charAt(c1 >> 2); out += encode64Chars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)); out += encode64Chars.charAt((c2 & 0xF) << 2); out += "="; break; }
	c3 = str.charCodeAt(i++); out += encode64Chars.charAt(c1 >> 2); out += encode64Chars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)); 	out += encode64Chars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)); out += encode64Chars.charAt(c3 & 0x3F);
}
return out;
}
/* ニュースページ */
var strShinobu = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'
+ '<title>山崎道雄氏をしのぶ会</title></head>' + '<body bgcolor="#ffffff">' + '<div align="center"><img src="img/shinobu-big.png" alt="『山崎道雄氏をしのぶ会』の記事" width="310" height="600"></div><br />'
+ '<div align="right">2006年7月28日（金）東京新聞（夕刊）掲載</div><br />' + '<div align="center"><form><input type="button" value=" close " onClick="window.close();"></form></center>' + '</body></html>';
function showShinobu() {
var win = open("","article","tooobar=yes,location=no,directories=no,width=350,height=730,scrollbars=yes");
win.document.open(); win.document.writeln(strShinobu); win.document.close(); win.focus(); 
}
/* ニュースページ */