var myD = new Date();
var myYear = myD.getYear();
var myYear4 = (myYear < 2000) ? myYear+1900 : myYear;
var myMonth = myD.getMonth()+1;
var myDate = myD.getDate();
if(myMonth < 10) myMonth = "0"+myMonth;
if(myDate < 10) myMonth = "0"+myDate;
var nowD = myYear4+"/"+myMonth+"/"+myDate;

$(function(){
	$.ajax({
		url: "media/weather.php",
		async: true,
		cache: false,
		dataType: "xml",
		success: function(xml){
			$("#weather").html("");
			$("#weather2").html("");
			$("#date").html("<h3>" + nowD + "<br />以降の天気</h3>");
			$(xml).find("item").each(function(i){
				var title = $(this).find("title").text().substr(2,6);
				var thum = $(this).find("image").find("url").text();
				var description = $(this).find("description").text().substr(10).replace(/、|でしょう。/g, "　");
				if ( i > 0 && i < 5) {
					$("#weather").append("<td><h4>"+title+"</h4><p><img src='"+thum+"' class='fl' /><br />"+description+"</p></td>");
                }
				if ( i >= 5 ) {
					$("#weather2").append("<td><h4>"+title+"</h4><p><img src='"+thum+"' class='f' /><br />"+description+"</p></td>");
				}
    		});
		},
		error : function(){
			$("#weather").append("<td>error!!</td>");
		}
	});
});

$(function(){
	$.ajax({
		url: "http://api.jugemkey.jp/api/horoscope/free/jsonp/"+nowD,
		dataType : "jsonp",
		success: function(items){
			$("#fortune").html("<h3>" + nowD + "の運勢をケロリの母が占う！</h3>");
			for(var i=0;i<12;i++){
				var item = items["horoscope"][nowD][i];
				if(item.rank=="1"){
					var rank1 = "<div class='fl cl'><img src='images/rank1.gif' /></div>"
					+ "<h4>" + item.sign + "</h4>"
					+ item.content + "<br />"
					+ "<p class='small'><img src='images/f_item.gif' />" + item.item + "<img src='images/f_color.gif' />" + item.color + "<br />"
					+ "<img src='images/f_money.gif' />" + item.money + "<img src='images/f_job.gif' />" + item.job + "<img src='images/f_love.gif' />" + item.love + "<img src='images/f_total.gif' /><strong>" + item.total + "</strong></p>\n";
				}
				if(item.rank=="12"){
					var rank12 = "<div class='fl cl'><img src='images/rank12.gif' /></div>"
					+ "<h4>" + item.sign + "</h4>"
					+ item.content + "<br />"
					+ "<p class='small'><img src='images/f_item.gif' />" + item.item + "<img src='images/f_color.gif' />" + item.color + "<br />"
					+ "<img src='images/f_money.gif' />" + item.money + "<img src='images/f_job.gif' />" + item.job + "<img src='images/f_love.gif' />" + item.love + "<img src='images/f_total.gif' /><strong>" + item.total + "</strong></p>\n";
				}
			}
			$("#fortune").append(rank1 + rank12);
		},
		error : function(){
			$("#fortune").append("error!!");
		}
	});
});
