var httpObj = getHttpObject();
var tb = 0;
var n_val;
var kk = "k_fe";

function ch_tab(e){
	var tmp = getid(e).substring(1,2);
	if(tb==tmp) return 0;
	document.getElementById("n" + tb).className = "";
	sub_ch(tmp);
	document.getElementById("n" + tmp).className = "sel";
	tb = tmp;
}
function sub_ch(tmp){
	var val = n_val.getElementsByTagName("newsval").item(tmp).firstChild.nodeValue;
	if(val.length == 1){
		val = n_val.getElementsByTagName("newsval").item(tmp).childNodes[1].nodeValue;
	}
	document.getElementById("news").innerHTML = val;
}

function showksin(e){
	var tgt = getid(e);
	if(kk == tgt) return 0;
	var elm = document.getElementById("newmd");
	if(tgt == "k_fe"){
		httpObj.open("GET","http://www.felix-mendelssohn.info/adm/piece/newmd",false);
		httpObj.send(null);
		elm.innerHTML = httpObj.responseText;
	}else if(tgt == "k_fa"){
		httpObj.open("GET","http://www.felix-mendelssohn.info/source/updatemidi.xml", false);
		httpObj.send(null);
		var fny = httpObj.responseXML.getElementsByTagName("item").item(0);
		var fnyval = fny.firstChild.nodeValue;
		if(fnyval.length < 5){
			fnyval = fny.childNodes[1].nodeValue;
		}
		elm.innerHTML = fnyval;
	}else{
		return 0;
	}
	document.getElementById(kk).className = "";
	document.getElementById(tgt).className = "ksel";
	kk = tgt;
}

function setListeners(){
	var strHtml;
	httpObj.open("GET","http://www.felix-mendelssohn.info/adm/piece/newmd",false);
	httpObj.send(null);
	strHtml = httpObj.responseText;
	document.getElementById("newmd").innerHTML = strHtml;
	httpObj.open("GET","http://www.felix-mendelssohn.info/adm/piece/dlrnk?kind=1&a=5",false);
	httpObj.send(null);
	strHtml = httpObj.responseText;
if(strHtml == "") strHtml = "今月のデータはありません";
	document.getElementById("dlrnk").innerHTML = strHtml;
	var eSrc = document.getElementById("newsnv");
	addListener(eSrc, "mouseup", ch_tab, false);
	httpObj.open("GET","http://www.felix-mendelssohn.info/source/news.xml", false);
	httpObj.send(null);
	n_val = httpObj.responseXML;
	sub_ch(0);

	aws();

	var eSrc2 = document.getElementById("ksin");
	addListener(eSrc2,"mouseover", showksin, false);
}

function aws(){
var ary = new Array("4882741687","4896421590","4378028417","4488013023","4276130379","4286056147",
			"B00005FJ8O","B00005Q7R4","B00009KMDY","B00005HID2","B0000ZP4RO",
			"B00005FLTI","B00005N75D","B000JVREKO","B00005HHAM","B000028B2B",
			"B0000267G6","B00006BGQW","B0000BABW4","B000ICMA7Q","B0009N2VFA");
var myRnd;
var tmp = new Array(6);
var lscnt = 4;
var itm = "";
var result = "<p style='{width:100%;padding:3px 0;font-size:14px;font-weight:bold;text-align:center;font-family:Arial;background:#444;color:#fff;}'>Amazon</p>";
	for(i = 0;i<lscnt+2;i++){
		myRnd = Math.floor(Math.random()*ary.length);
		var flg = true;
		for(k = 0;k<lscnt+2;k++){
			if(myRnd == tmp[k]){
				flg == false;
				break;
			}
		}
		if(flg){
			itm += ary[myRnd];
			if(i < lscnt + 1){
				itm += ",";
				tmp[i]=myRnd;
			}
		}else{
			i--;
		}
	}

	httpObj.open("GET","http://www.felix-mendelssohn.info/websvc/awstop?prm=" + itm,true);

	httpObj.onreadystatechange = function(){
		if(httpObj.readyState == 4){
			if(httpObj.status == 200){

				var xmldc = httpObj.responseXML.getElementsByTagName("Item");
				lscnt = xmldc.length;
				if(lscnt > 4) lscnt = 4;
				for(i = 0;i<lscnt;i++){
					var node = xmldc.item(i).getElementsByTagName("SmallImage");
					var gazo = "./pic/noimage.gif";
					if(node.length > 0){
						gazo = node.item(0).getElementsByTagName("URL").item(0).firstChild.nodeValue;
					}
					result += "<p class='con'><img src='" + gazo + "' />";
					var auth = "";
					var bind = "";

					if(xmldc.item(i).getElementsByTagName("Author").length > 0){
						auth = xmldc.item(i).getElementsByTagName("Author").item(0).firstChild.nodeValue;
						bind = "単行本";
					}else if(xmldc.item(i).getElementsByTagName("Artist").length > 0){
						auth = xmldc.item(i).getElementsByTagName("Artist").item(0).firstChild.nodeValue;
						bind = "CD";
					}
					result += "<a href='" + xmldc.item(i).getElementsByTagName("DetailPageURL").item(0).firstChild.nodeValue + "' target='_brank'>" + xmldc.item(i).getElementsByTagName("Title").item(0).firstChild.nodeValue + "</a><br/>[" + bind + "] " + auth;
					node = xmldc.item(i).getElementsByTagName("ListPrice");
					if(node.item(0).getElementsByTagName("FormattedPrice").length > 0){
						result += "<br/><span id='pr'>" + node.item(0).getElementsByTagName("FormattedPrice").item(0).firstChild.nodeValue + "</span>";
					}
				}
				document.getElementById("adv").innerHTML = result + "</p>";
			}
		}
	}
	httpObj.send(null);
}

addListener(window, "load", setListeners, false);



