//	dynamic js map
//	dependance: prototype.js
//	© mountain multi media (www.gomedia.ch)
//	v1.0 4.12.2006/mh

//try{
	RoomMap={
		
		gt_people:" "+GOS.gt("Personen","","","","people"),
	
		base:function(id){
			this.container=document.createElement("DIV");
			this.container.id=id;
			this.container.lang=document.getElementsByTagName("html")[0].lang?document.getElementsByTagName("html")[0].lang:"de";
			this.linkList=document.createElement("UL");
			this.linkList.className="linkList nm nl";
		},

		Room:function(room){
			this.id=RoomMap.xmlData.get(room,"id");
			this.listitem=RoomMap.ListItem(room);
			this.img=RoomMap.Image(room);
			return this;
		},

		ListItem:function(room){
			var myListItem=document.createElement("LI");
			var myLink=document.createElement("A");
			myLink.id="a_"+RoomMap.xmlData.get(room,"id");
			myLink.href="#";
			myLink.appendChild(document.createTextNode(RoomMap.xmlData.get(room,"label")));
			myLink.onmouseover=function(){Element.show($(this.id.replace("a_","i_")));}
			myLink.onmouseout=function(){Element.hide($(this.id.replace("a_","i_")));}
			myLink.onclick=function(){this.blur();RoomMap.ShowTable(room);return false;}
			myListItem.appendChild(myLink);
			return myListItem;
		},
		
		Image:function(room){
			var img=document.createElement("IMG");
			img.style.position="absolute";
			img.style.top="0px";
			img.style.left="0px";
			img.style.width="345px";
			img.style.height="420px";
			img.src=RoomMap.xmlData.get(room,"image");
			img.id="i_"+RoomMap.xmlData.get(room,"id");
			img.alt=RoomMap.xmlData.get(room,"label");
			return img;
		},
		
		parseXML:function(req){
			RoomMap.xmlData=new XMLParser(req.responseXML);
		},

		ShowTable:function(room){
			if(!RoomMap.Table){
				RoomMap.Table=document.createElement("TABLE");
				Element.addClassName(RoomMap.Table,"seminarraeume")
				RoomMap.tCaption=document.createElement("CAPTION");
				RoomMap.Table.appendChild(RoomMap.tCaption);
				RoomMap.tBody=document.createElement("TBODY");
				RoomMap.Table.appendChild(RoomMap.tBody);
			}

			if(RoomMap.tCaption.firstChild){RoomMap.tCaption.removeChild(RoomMap.tCaption.firstChild);}
			RoomMap.tCaption.appendChild(document.createTextNode(RoomMap.xmlData.get(room,"label")));
			$A(RoomMap.xmlData.list("kapazitaet",room)).each(function(capacity){
				k_type=capacity.getAttribute("type");
				if(!RoomMap[k_type]){
					RoomMap[k_type]=RoomMap.MakeTableRow(capacity);
					RoomMap.tBody.appendChild(RoomMap[k_type]);
				}
				
				var label_temp=capacity.getAttribute("type");
				var value_temp=parseInt(capacity.getAttribute("people"),10);

				if((value_temp!=0)&&(value_temp!="NaN")){
					value_temp+=RoomMap.gt_people;
				}else{
					value_temp="-";
				}
				Element.show($(RoomMap[k_type]));
				if(!RoomMap[k_type]["datavalue"].firstChild){RoomMap[k_type]["datalabel"].appendChild(document.createTextNode(label_temp));}
				if(RoomMap[k_type]["datavalue"].firstChild){RoomMap[k_type]["datavalue"].removeChild(RoomMap[k_type]["datavalue"].firstChild);}
				RoomMap[k_type]["datavalue"].appendChild(document.createTextNode(value_temp));
	
			});

			$("text").appendChild(RoomMap.Table);
		},
		
		TableClearValue:function(cell){
			if(cell&&cell.firstChild){cell.removeChild(cell.firstChild);}
		},

		MakeTableRow:function(datarow){
			var type=datarow.getAttribute("type");
			if(!RoomMap[type]){
				RoomMap[type]=document.createElement("TR");
				RoomMap[type]["datalabel"]=document.createElement("TD");
				Element.addClassName(RoomMap[type]["datalabel"],"col1");
				RoomMap[type].appendChild(RoomMap[type]["datalabel"]);
				RoomMap[type]["datavalue"]=document.createElement("TD");
				Element.addClassName(RoomMap[type]["datavalue"],"col2");
				RoomMap[type].appendChild(RoomMap[type]["datavalue"]);
			}
			return RoomMap[type];
		},
		
		MakeRooms:function(){
			$A(RoomMap.xmlData.list("item")).each(function(room){
				thisRoom=RoomMap.Room(room);
				RoomMap.container.appendChild(thisRoom.img);
				Element.hide(thisRoom.img);
				RoomMap.linkList.appendChild(thisRoom.listitem);
			});
			$("text").appendChild(RoomMap.linkList);	//	text links
			$("extra").appendChild(RoomMap.container);
			if(window.attachEvent){correctPNG();}
			Element.hide($("srImg"));
		}
	}
	
	RoomMap.base("seminarraeume");

	new Ajax.Request("/data/rooms.gos",{
		method:"get",
		onSuccess:function(req){RoomMap.parseXML(req);RoomMap.MakeRooms();}
	});

//}catch(e){}