var Page = {
	_cache_request : {},
	_requesturl_current : undefined,
	_popup_now : false,
	init : function() {
		Page._create_popup();
		//
		var anchorList = $('content').getElementsByTagName('a');
		var anchors = $A(anchorList);
		anchors.each(function(a) {
			if (Element.hasClassName(a, 'word')) {
				var url_json = a.href.replace('.html', '.json');
				a.url_json = url_json;
				a.onmouseover = function() {
					Page._popup(true, this.url_json);
					};
				a.onmouseout = function() {
					Page._popup(false);
					};
			};
		});
	},
	_create_popup : function() {
		var popup_html = '<div id="popup"><div id="popup_title"></div><div id="popup_text"></div></div>';
		new Insertion.Bottom('page', popup_html);
		Event.observe(document.body, 'mousemove', Page._mousemoved, false);
	},
	_popup : function (bpop, url_json) {
		if(Page._popup_now == bpop) return;
		Page._popup_now = bpop;
		// clear
		$('popup_title').innerHTML = '読み込み中(Loading)...';
		$('popup_text').innerHTML = '';
		$('popup').style.display = bpop ? 'block' : 'none';
		
		// ajax request
		if(url_json) {
			if(Page._cache_request[url_json]) {
				Page._update_popup(Page._cache_request[url_json]);
				return;
			}
			var options = {
				method:'get',
				onComplete:Page._popuploaded,
				onException:Page._popuploadingexception
				};
			Page._requesturl_current = url_json;
			new Ajax.Request(url_json, options);
		}
	},
	_decodetext : function(text) {
		if(navigator.appVersion.indexOf('KHTML') > -1) {
			var text_esc = escape(text);
			if(text_esc.indexOf('%u') < 0 && text_esc.indexOf('%') > -1)
				text = decodeURIComponent(text_esc);
		}
		return text;
	},
	_popuploadingexception : function(req, e) {
		$('popup').style.display = 'none';
//		Page._update_popup({title:'Exception',text:e});
	},
	_popuploaded : function(res) {
		var data = eval(Page._decodetext(res.responseText));
		var hobj = $H(data[0]);
		Page._cache_request[Page._requesturl_current] = hobj;
		Page._update_popup(hobj);
	},
	_update_popup : function(hobj) {
		$('popup_title').innerHTML = hobj['title'];
		$('popup_text').innerHTML = hobj['excerpt'];
	},
	_mousemoved: function(e) {
		// setpos
		$('popup').style.left = Event.pointerX(e)+20 + 'px';
		$('popup').style.top = Event.pointerY(e)+20 + 'px';
	}
}
Event.observe(window, 'load', Page.init, false);

function PlayMovie(dir, name) {
	this.dir  = dir;
	this.name = name;
	this.loading();
}
PlayMovie.prototype.loading = function() {
	var vars = 'serverName=fms-jaxa.pod.tv&protocol=rtmp&port=1935&dir=' + this.dir + '&name=' + this.name;
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="320" height="260" id="videoPlayer" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="movie" value="http://edu.jaxa.jp/shared/swf/videoplayer.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="flashVars" value="' + vars + '" /><embed src="http://edu.jaxa.jp/shared/swf/videoplayer.swf" quality="high" bgcolor="#ffffff" width="320" height="260" name="videoPlayer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashVars="' + vars + '"/></object>');
}
