function init(){
	initAnnounceMenu();
	initData();
	new Menu(new TopMenuHandler(openPage)).initMenu();
}


function initAnnounceMenu(){

	
	
	var announceMenuTableBody = document.getElementById("announceMenuTable");
	while(announceMenuTableBody.firstChild){
		announceMenuTableBody.removeChild(announceMenuTableBody.firstChild);
	}
	var i;
	for(i = 0; i < announceMenu.length;i++){
		{
			var tr = createMenuItem(announceMenu[i]);
			tr.appendChild(createAnnounce(announceMenu[i]));
			announceMenuTableBody.appendChild(tr);
			tr.firstChild.firstChild.onclick = eval(announceMenu[i].handler);
			tr.firstChild.firstChild.className = "largeFont";
		}
	}
	var menu2TableBody = document.getElementById("menuTable2");
	while(menu2TableBody.firstChild){
		menu2TableBody.removeChild(menu2TableBody.firstChild);
	}
	var i;
	for(i = 0; i < menu2.length;i++){
		{
			var tr = createMenuItem(menu2[i]);
			tr.style.height="24px";
			menu2TableBody.appendChild(tr);
			tr.firstChild.firstChild.onclick = menuItemSelected;
		}
	}
	
	
	var menu3TableBody = document.getElementById("menuTable3");
	while(menu3TableBody.firstChild){
		menu3TableBody.removeChild(menu3TableBody.firstChild);
	}
	var i;
	for(i = 0; i < menu3.length;i++){
		{
			var tr = createMenuItem(menu3[i]);
			tr.style.height="24px";
			menu3TableBody.appendChild(tr);
			tr.firstChild.firstChild.onclick = menuItemSelectedToTopUrl;
		}
	}
}

function createAnnounce(menu){
	var td = document.createElement("td");
	if(menu.announceId){
		var img = document.createElement("img");
		img.src = "gui/announceOff2.gif";
		img.id = "announceImg" + menu.announceId;
		td.appendChild(img);
		img.style.verticalAlign="middle";
		var span = document.createElement("span");
		span.id = "announceText" + menu.announceId;
		span.appendChild(document.createTextNode("発令なし"));
		td.appendChild(span);
	}
	return td;
}


function menuItemSelected(){
	openPage(this.menuItem.link);
}
function menuItemSelectedToTopUrl(){
	openTopPage(this.menuItem.link);
}
function menuItemSelectedToFrameUrl(){
	openFramePage(this.menuItem.link);
}

function openPage(url){
	if(!(url.indexOf("http") > -1)){
		openFramePage(url);
	}else{
		openTopPage(url)
	}
}
function openTopPage(url){
	window.location.href = url;
}
function openFramePage(url){
	window.location.href = "frameset.html?" + url;
}



function createMenuItem(announceMenu){
	var tr = document.createElement("tr");
	tr.height = 16 ;
	var td2 = document.createElement("td");
	td2.className = "annoNam";
	var span1 = document.createElement("span");
	span1.className = "ancMen2";
	span1.title = announceMenu.title;
	var img = document.createElement("img");
	img.src = "gui/green.gif";
	img.border = "0";
	img.align = "absMiddle";
	span1.appendChild(img);
	span1.image = img;
	var text = document.createTextNode(announceMenu.caption);
	span1.className = "menu";
	span1.appendChild(text);
	span1.onmouseover = announceMenuMouseOver;
	span1.onmouseout = announceMenuMouseOut;
	span1.menuItem = announceMenu;


	tr.appendChild(td2);
	td2.appendChild(span1);
	return tr;
}



function announceMenuMouseOver(){
	this.image.src = "gui/red.gif";
	this.style.cursor = "pointer";
	this.style.color = "red";
	
}
function announceMenuMouseOut(){
	this.image.src = "gui/green.gif";
	this.style.cursor = "default";
	this.style.color = "black";
}



function initData(){
	var announce = "";
	for(i = 0; i < announceMenu.length;i++){
		{
			if(announceMenu[i].announceId){
				announce = announce + announceMenu[i].announceId + ",";
			}
		}
	}
    var loader = new xmlLoader("TopPage.do?target=" + target + "&announceId=" + announce ,new InitCallBack());
    loader.start();
}

function InitCallBack(){
    //XML通信CallBack2
    this.callback2 = function(txt){
    	if(true){
			var data = eval(txt);
			initGuiData(data);
    	}
    }
}
function initGuiData(data){
	initInformation(data);
	initAnnounce(data);

	///initAnnounceMap(data);
}
function initInformation(data){
	var infoContents = document.getElementById("informationContents");
	//infoContents.innerHTML = data[0].information.replaceAll("\r\n","<br/>");
	var sa = data[0].information.split("\r\n");
	var html = "";
	for(var i=0;i<sa.length;i++){
		html = html + sa[i] + "<br />"
	}
	infoContents.innerHTML = html;
}
function initAnnounce(data){
	for(i = 0; i < announceMenu.length;i++){
		if(announceMenu[i].announceId){
			changeAnnounceStatus(data,announceMenu[i].announceId);
		}
	}
}

function changeAnnounceStatus(data,announceId){
	var announceOffImg = document.getElementById("announceImg" + announceId);
	var announceOffText = document.getElementById("announceText" + announceId);
	if(data[0]["announce" + announceId] == "on"){
		announceOffImg.src = "gui/announceOn2.gif";
		announceOffText.style.fontWeight = "normal";
		announceOffText.style.color = "black";
		announceOffText.innerText = "発令あり";
	}else{
		announceOffImg.src = "gui/announceOff2.gif";
		announceOffText.style.fontWeight = "normal";
		announceOffText.style.color = "#646464";
		announceOffText.innerText = "発令なし";
	}
}




function initAnnounceMap(data){
	var announceMap = document.getElementById("announceMap");
	while(announceMap.firstChild){
		announceMap.removeChild(announceMap.firstChild);
	}
	var str = data[0].announceRegion.split(",");
	var i;
	for(i = 0; i < str.length;i++){
		if(str[i].length!=0){
			var img = document.createElement("img");
			img.src = "gui/region_" + str[i] + ".gif";
			img.style.position = "absolute";
			img.style.top = "0px";
			img.style.left = "0px";
			announceMap.appendChild(img);
		}
	}
}


