/**
 * WooderdChiarie Javascript Inst (work with jQuery)
 * http://www.wooderdchiarie.com/
 *
 * Copyright (c) 2009 tokyointerstellartravel.org
 * http://www.tokyointerstellartravel.org/
 *
 *	Function junoScheduleCalender(_nodeID)
 *	@use
 *		Load this script (this code will exec automaticaty)
 */

(function junoLiveSchedule(_nodeID){
//	$.getJSON("/live/liveschedule.php", function(data){
//		json_handler(data)
//	});

$.ajax({
   type: "get",
   url: "/live/liveschedule.php",
   success: function(msg){
	msg = msg.replace( /<br.*?>/ig, '' ).replace( /&lt;.*?&gt;/ig, '' ).replace( /[ 　]+?\/[ 　]+?/ig, '<br />' );
    json_handler(eval( '('+msg+')' ))
   }
 });

		
	function json_handler(_response){
		var schedule    = $(_response.schedule);
		var ui          = $('#'+_nodeID);
		var ui_list     = $('<ul class="schedule">');
		var flag_recent = true;
		
		
		schedule.each(function(i,liveshow){
			if(wooderdchiarie.cur_year <= Number(liveshow.event_year)){
				if(wooderdchiarie.cur_month <= Number(liveshow.event_month)){
					
					if(!liveshow.event_day){ return; };
					if((wooderdchiarie.cur_month == Number(liveshow.event_month)) && Number(liveshow.event_day) < wooderdchiarie.cur_day){ return; };
					
					var ui_li = $('<li>');
					if(flag_recent){
						ui_li.attr('class', 'latest');
						var _html =   '<div><a href="'+ liveshow.permalink +'#contents">'
									+ '<span class="date">'+ liveshow.event_year +'-'+ liveshow.event_month +'-'+ liveshow.event_day +' '+ liveshow.event_week +'</span><br />'
									+ '<span class="location">'+ liveshow.event_at +'</span><br />'
									+ '<span class="eventtitle">'+ liveshow.event_title +'</span>'
									+ '</a></div>'
									+ '<div class="flyer"><img src="http://www.wooderdchiarie.com'+ liveshow.event_flyer +'" alt="" width="100" /></div>'
									+ '<div class="summary">'+ liveshow.event_info +'</div>';
						flag_recent = false;
					}else{
						var _html =   '<a href="'+ liveshow.permalink +'#contents">'
									+ '<span class="date">'+ liveshow.event_year +'-'+ liveshow.event_month +'-'+ liveshow.event_day +' '+ liveshow.event_week +'</span> '
									+ '<span class="location">'+ liveshow.event_title +'</span>'
									+ '</a></li>';
					};
					ui_li.html(_html);
					ui_list.append(ui_li);
					ui_li  = null; _html = null;
				};
			};
		});
		ui.prepend(ui_list);
	};
})('junoLiveSchedule');