document.write('<script src="map/logoswitch.js"></script>');

var xml0 = "map/galaxy/";
var html0 = "galaxy.html";
var bez0 = "Milky Way Galaxy";
var wid0 = 1348;
var hei0 = 1350;
var z0 = 3;
var xml1 = "map/localspace/";
var html1 = "localspace.html";
var bez1 = "Local Space";
var wid1 = 1348;
var hei1 = 1350;
var z1 = 3;
var xml2 = "map/ufpmain/";
var html2 = "ufpmain.html";
var bez2 = "UFP Main Core";
var wid2 = 13229;
var hei2 = 9355;
var z2 = 6;
var xml3 = "map/entmap/";
var html3 = "entmap.html";
var bez3 = "22nd Century (Enterprise)";
var wid3 = 3800;
var hei3 = 2600;
var z3 = 4;
var xml4 = "map/gamma/";
var html4 = "gamma.html";
var bez4 = "Gamma Quadrant";
var wid4 = 3800;
var hei4 = 2600;
var z4 = 4;

xmldaten = new Array(xml0, xml1, xml2, xml3, xml4);
bezdaten = new Array(bez0, bez1, bez2, bez3, bez4);
htmldt = new Array (html0, html1, html2, html3, html4);
widdt = new Array (wid0, wid1, wid2, wid3, wid4);
heidt = new Array (hei0, hei1, hei2, hei3, hei4);
zdt = new Array (z0, z1, z2, z3, z4);

function globalsearch() {
document.getElementById(resultsbox).innerHTML="";
for (g=0;g<5;g++) {
var resultshere = document.getElementById(resultsbox);
var schrift = document.createElement("h2");
var beztxt = document.createTextNode(bezdaten[g]);
resultshere.appendChild(schrift);
schrift.appendChild(beztxt);
loadIndex(xmldaten[g]+"locations.xml");
searchIndex();
}
}

function setCenter(x, y) {
            map.zoomTo(zoomlevels);
			var lonlat = new OpenLayers.LonLat(x, y);
            map.panTo(lonlat);
			}

function newloc()
{
map.destroy();
randominfo.innerHTML="";
randomloc();
}

var map, zoomify;

function randomloc() {

selection = Math.round(Math.random()*2)+2;
var zoomify_width = widdt[selection];
var zoomify_height = heidt[selection];
var zoomify_url = xmldaten[selection];
zoomlevels = zdt[selection]-1;
pfad = htmldt[selection];
xmlquelle = zoomify_url + "locations.xml";

	       /* First we initialize the zoomify pyramid (to get number of tiers) */
	        var zoomify = new OpenLayers.Layer.Zoomify( "Zoomify", zoomify_url, 
		  		new OpenLayers.Size( zoomify_width, zoomify_height ) );

	       /* Map with raster coordinates (pixels) from Zoomify image */
	        var options = {
	            controls: [],
	            maxExtent: new OpenLayers.Bounds(0, 0, zoomify_width, zoomify_height),
	            restrictedExtent: new OpenLayers.Bounds(0, 0, zoomify_width, zoomify_height),
				maxResolution: Math.pow(2, zoomify.numberOfTiers-1 ),
				numZoomLevels: zoomify.numberOfTiers,
	            units: 'pixels'
	        };

	        map = new OpenLayers.Map("map", options);
	        map.addLayer(zoomify);
            map.setBaseLayer(zoomify);
			map.zoomToMaxExtent();

if (document.implementation && document.implementation.createDocument) {
	var xmlhttp = new window.XMLHttpRequest();
	xmlhttp.open("GET", xmlquelle, false);
	xmlhttp.send(null);
	xmlDoc = xmlhttp.responseXML.documentElement;
	}
// MSIE uses ActiveX
	else if (window.ActiveXObject) {
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async = "false";
		xmlDoc.load(xmlquelle);
	}

allitems = xmlDoc.getElementsByTagName("item");
maxwert = allitems.length-1;
selection2 = Math.round(Math.random()*maxwert);
Location = allitems[selection2].lastChild.nodeValue;
loccord2 = allitems[selection2].getAttribute('Cord');
loccord = loccord2.split(",");

setCenter(loccord[0], loccord[1]);

randominfo = document.getElementById("randomloc");

var info = Location.replace(/[\[/\]\(\)\’\'\ ]/g,"")
var xmlsrc2 = "map/locinfo.xml"

if (document.implementation && document.implementation.createDocument) {
	var xmlhttp = new window.XMLHttpRequest();
	xmlhttp.open("GET", xmlsrc2, false);
	xmlhttp.send(null);
	xmlDoc = xmlhttp.responseXML.documentElement;
	}
// MSIE uses ActiveX
	else if (window.ActiveXObject) {
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async = "false";
		xmlDoc.load(xmlsrc2);
	}

var allitems2 = xmlDoc.getElementsByTagName("item");
results = new Array;

for (var i=0;i<allitems2.length;i++) {
// see if the XML entry matches the search term,
// and (if so) store it in an array
			var str =  allitems2[i].lastChild.nodeValue;
			var name8 = str.replace(/[\[/\]\(\)\’\'\ ]/g,"");
			var name5 = name8.toUpperCase()
			var exp = new RegExp(info,"i");

if (name5 != info) {
  } else {
    results.push(allitems2[i]);
  }			
}

var locinfoname = results[0].lastChild.nodeValue;
var tabelle = document.createElement("table");
tabelle.setAttribute("width", "100%");
var reihe1 = document.createElement("tr");
var zelle1 = document.createElement("td");
var zelle2 = document.createElement("td");
zelle2.setAttribute("valign", "middle");
var name = document.createTextNode(locinfoname);
var headline = document.createElement("h4");

var loclink = pfad + "?cord=" + loccord2;
document.getElementById("explobt").href = loclink;

if (results.length > 0) {

var affiltxt = document.createTextNode("Affiliation:");
var affiltest = results[0].getAttribute('entaffil');


if (zoomify_url != "map/entmap/") {
var affilor = "affil";
var status2 = "status";
} else {
if (affiltest != null) {
var affilor = "entaffil";
var status2 = "ent-status";
} else {
var affilor = "affil";
var status2 = "status";
} }

var affilor2 = results[0].getAttribute(affilor);
var affil = document.createTextNode(affilor2);
var stattxt = document.createTextNode("Status:");
var status = document.createTextNode(results[0].getAttribute(status2));
var bruch = document.createElement("br");
var logo = document.createElement("img");
logo.setAttribute("style", "float:right");

logoswitch (zoomify_url, affilor2);

logo.setAttribute("src", logosrc);

randominfo.appendChild(tabelle);
tabelle.appendChild(reihe1);
reihe1.appendChild(zelle1);
zelle1.appendChild(headline);
headline.appendChild(name);
zelle1.appendChild(affil);
zelle1.appendChild(bruch);
zelle1.appendChild(status);
reihe1.appendChild(zelle2);

if (logosrc != "") {
zelle2.appendChild(logo);
}

} else {
randominfo.appendChild(headline);
headline.appendChild(name);
var nix = document.createTextNode("No information available");
randominfo.appendChild(nix);
}
}
