﻿function getIconName( str ){
	switch( str )
	{
		case '鎧':
			return "ico_armor.gif";	
		case '盾':
			return "ico_shield.gif";
		case '剣':
			return "ico_saber.gif";	
		case '銃':
			return "ico_gun.gif";	
		case '杖':
			return "ico_cane.gif";	
		case 'ユニット':
			return "ico_unit.gif";	
		case 'アイテム':
			return "ico_item.gif";	
		default:
			return "";
	}
}

$(document).ready( function (){
	$.ajax({
		url: 'akabako100.xml',
		type: 'GET',
		dataType: 'xml',
		timeout: 5000,
		//ロード失敗
		error: function(){
			$('h4#tableOutput').after( '<div id="errorBox">アイテムリストの読み込みに失敗しました。</div>' );
			$('div#informationLoadBox').hide();
		},
		//ロード完了
		success: function(xml){
			var flag = true;
			var tree = '<table class="itemTable"><tr><th class="Ico">種類</th><th class="item">アイテム名</th>'
					+ '<th class="Star">レアリティ</th><th class="date">ドロップ日時</th><th class="party">パーティー名</th></tr>';
			var newclass = '';
			
			$(xml).find('rare-item').each( function(){
				if( $(this).attr('new') == "true" ) {
					newclass = ' class="new"'
				}
				else {
					newclass = '';
				}
				if( $(this).attr('dropped') == "true" ){
					tree += '<tr' + newclass + '><td class="Ico"><img src="dropanouncement/drop_list/' + getIconName( $(this).attr('kind') ) + '" alt="" width="25" height="25" /></td>'
						+ '<td>' + $(this).attr('name') + '</td>'
						+ '<td class="Star">' + $(this).attr('rarity') + '</td>'
						+ '<td class="date">' + $(this).attr('date') + '</td>'
						+ '<td>' + $(this).attr('partyname').replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;') + '</td></tr>';
				}
				else {
					tree += '<tr' + newclass + '><td class="Ico"><img src="dropanouncement/drop_list/' + getIconName( $(this).attr('kind') ) + '" alt="" width="25" height="25" /></td>'
						+ '<td>' + $(this).attr('name') + '</td>'
						+ '<td class="Star">' + $(this).attr('rarity') + '</td>'
						+ '<td class="date">-</td>'
						+ '<td>-</td></tr>';
				}
			} );
			
			tree += '</table>';
			
			//反映
			$('h4#tableOutput').after( tree );
			$('div#informationLoadBox').hide();
		}
	});
} );
