//==============================================================
//	検索
//==============================================================
var Search = {

	//--------------------------------------------------------------
	//	<summary>
	//		初期化
	//--------------------------------------------------------------
	initialize: function () {

		Event.add($("search"), "click", Search.search, false);
		Event.add($("keyword"), "keydown", Search.keydown, false);
	},

	//--------------------------------------------------------------
	//	<summary>
	//		キーワード
	//--------------------------------------------------------------
	keydown: function (event) {

		// [Enter]
		if(event.keyCode == 13)
		{
			$("search").focus();
		}
	},

	//--------------------------------------------------------------
	//	<summary>
	//		キーワード検索
	//--------------------------------------------------------------
	search: function () {

		var keyword	= $("keyword").value.encode();
		var url		= "http://www.google.com/search?hl=ja&inlang=ja&q=";

		if(keyword.length > 0)
		{
			window.location = url + keyword + " site:http://trivia.air-be.net/".encode();
		}
	}
}

Event.add(window, "load", Search.initialize, false);

//==============================================================
//	トピック
//==============================================================
var Topic = {

	timerId: null,

	//--------------------------------------------------------------
	//	<summary>
	//		初期化
	//--------------------------------------------------------------
	initialize: function () {

		if($("topic"))
		{
			Topic.timerId = setInterval(function() {Topic.onTimer();}, 5000);
		}
	},

	//--------------------------------------------------------------
	// <summary>
	//		タイマーイベント
	//--------------------------------------------------------------
	onTimer: function () {

		if(Topic.timerId) {
			clearInterval(Topic.timerId);
			Topic.timerId = null;
		}

		var effect = Effect.fadeOut($("topic"), 0, 1000, 10, Topic.onFadeOutComplete);
	},

	//--------------------------------------------------------------
	// <summary>
	//		タイマーイベント
	//--------------------------------------------------------------
	onFadeOutComplete: function () {

		Element.setOpacity($("topic"), 0);

		var params			= new AjaxRequestParameter();
		params.url			= "index.php?to=" + (new Date()).getTime();
		params.method		= "GET";
		params.onSuccess	= Topic.onComplete;

		AjaxRequest.create().send(params);
	},

	//--------------------------------------------------------------
	// <summary>
	//		タイマーイベント
	//--------------------------------------------------------------
	onComplete: function (request) {

		$("topic").innerHTML = decodeURIComponent(request.responseText);
		Element.setOpacity($("topic"), 0);

		var effect = Effect.fadeIn($("topic"), 100, 1000, 10, Topic.onFadeInComplete);
	},

	//--------------------------------------------------------------
	// <summary>
	//		タイマーイベント
	//--------------------------------------------------------------
	onFadeInComplete: function () {

		Topic.initialize();
	}
}

Event.add(window, "load", Topic.initialize, false);
