/*
 * home-performance.js
 * 
 * Copyright (c) 2009 MonkeyWorks Corporation
 *
 * Since:     2010-01-08
 * Modified:  2010-01-08
 *
 * jQuery 1.3.1
 * 
*/

(function($){
	$(function(){
		
		// ------------------------------------------------------------------------
		// 設定
		// ------------------------------------------------------------------------
		
		// XMLのURL
		var url = "event/performance/performance.xml";
		
		// 変数
		var date = new Object();
		
		// 今年
		date["thisyear"] =  new DateFormat("yyyy").format(new Date());
		
		// 今月
		date["thismonth"] = new DateFormat("MM").format(new Date());
		
		
		// ------------------------------------------------------------------------
		// 処理
		// ------------------------------------------------------------------------
		
		// 変数
		var flag = false;
		
		// ajax
		$.ajax({
			url: url,
			type: "GET",
			dataType: "xml",
			timeout: 10000,
			cache: false,
			error: function(){
				// 読み込めなかった場合
				//alert("データの取得に失敗しました。");
				
				$("#performance-content").text("データの読み込みに失敗しました。");
				
			},
			success: function(xml){
				// 読め込めた場合
				//alert("データの取得に成功しました。");
				
				if ($(xml).find("entry").length > 0) {
					// データあり
					$(xml).find("entry").each(function(){
						
						// 今月のデータを取得
						if ($(this).find("execution").text() == date["thisyear"] + "年" + date["thismonth"] + "月") {
							
							// 変数
							var result = new Object();
							
							// 劇団名
							if ($(this).find("title").text() != "") {
								result["title"] = $(this).find("title").text();
							} else {
								result["title"] = "-";
							}
							
							// 公演期間
							if ($(this).find("period").text() != "") {
								result["period"] = $(this).find("period").text();
							} else {
								result["title"] = "-";
							}
							
							// 画像
							if ($(this).find("image").text() != "") {
								$("#performance-image").attr("src", $(this).find("image").text());
							}
							
							// 内容を表示
							$("#performance-content").html(result["title"] + "<br />お芝居・歌謡ショー<br />" + result["period"]);
							
							// flag
							flag = true;
							
						}
						
					});
					
				} else {
					
					// データなし
					$("#performance-content").text("イベントの予定はありません。");
					
				}
				
				// 今月のデータが見つからなかった場合
				if (flag == false) {
					$("#performance-content").text("イベントの予定はありません。");
				}
				
			}
		});
		
	});
})(jQuery);
