// DisplayObjects - Steuert die Ergebnisliste und Kartenansicht der Hauptseite

// Questim-taugliche Marker für die Google-API:
// Ein Images-Array wird übergeben, damit bei Thumbnail-Ansicht die Bilder als Slideshow abgespielt werden können

function QuestimMarker(location,images) {
	this.location_ = location;
	this.images_ = images;
	this.imageCounter_ = 0;
	this.map_ = null;
	this.markerChar = null;
	this.thumbnailMode = 0;
	this.listenerElements = [];
	this.gotoExposee = 0;
	this.link = "#";
	this.visible_ = true;
}
QuestimMarker.prototype = new GOverlay();

QuestimMarker.prototype.initialize = function(map) {
	var frameDiv=document.createElement("div");		// Frame für Thumbnail-Ansicht (Beinhaltet Schatten)
	var imageDiv=document.createElement("a");			// Image für Thumbnail-Ansicht (als a-tag, was direktes Verlinken ermöglicht)
	var pinDiv=document.createElement("a");			// Image für Pin-Ansicht
	var pinShadowDiv=document.createElement("div");	// Schatten für Pin-Ansicht

	// Link-Hrefs auf Pin/Thumbnail setzen:

	$(imageDiv).setProperty("href",this.link);
	$(pinDiv).setProperty("href",this.link);

	this.map_ = map;
	frameDiv.className = "imageFramePin";
	imageDiv.className = "imagePin";
	pinDiv.className = "mapPin";
	pinShadowDiv.className = "mapPinShadow";

	// Thumbnail-Pins mit Bild versehen:

	if (this.images_.length>0) {
		imageDiv.style.backgroundImage = "url("+this.images_[0].pin+")";
	} else {
		//alert ("assigning no image!");
		imageDiv.style.backgroundImage = "url(/img/no_image_pin.png)";
	}

	// Pin-Grafiken an Google-Layer befestigen:

	this.map_.getPane(G_MAP_MARKER_SHADOW_PANE).appendChild(pinShadowDiv);
	this.map_.getPane(G_MAP_MARKER_PANE).appendChild(pinDiv);
	this.map_.getPane(G_MAP_MARKER_PANE).appendChild(frameDiv);
	this.map_.getPane(G_MAP_MARKER_PANE).appendChild(imageDiv);

	this.fDiv_ = frameDiv;
	this.iDiv_ = imageDiv;
	this.pDiv_ = pinDiv;
	this.psDiv_ = pinShadowDiv;

	// by default ist die pin-Ansicht aktiviert (Thumbnail-Pins werden versteckt)

	this.fDiv_.style.visibility="hidden";
	this.iDiv_.style.visibility="hidden";

	// Mouse-Events an Pins anhängen:

	this.addListeners(this.pDiv_);
}


// Legt Mouse-Aktionen für ein Pin-Element fest:

QuestimMarker.prototype.addListeners = function(element) {
	var that = this;
	this.listenerElements.push(element);

	// Mouse-Events werden weitergeleitet an die trigger-Funktion der Google-Api

	GEvent.addDomListener(element, "click", function() {
		GEvent.trigger(that, "click");
		GEvent.trigger(that.map_, "click", null, that);
	});
	GEvent.addDomListener(element, "mouseover", function() {
		GEvent.trigger(that, "mouseover");
		GEvent.trigger(that.map_, "mouseover", null, that);
	});
	GEvent.addDomListener(element, "mouseout", function() {
		GEvent.trigger(that, "mouseout");
		GEvent.trigger(that.map_, "mouseout", null, that);
	});
}


// Löscht alle Mouse-Aktionen des Questim-Markers

QuestimMarker.prototype.clearListeners = function() {
	this.listenerElements.each(function(listenerElement) {
		([/* 'click' ,*/'mouseover','out']).each(function(event){
			GEvent.clearListeners(listenerElement,event);
		});
	});
}

// Obsolet: Versteckt den kompletten Marker

QuestimMarker.prototype.setVisible = function(visible) {
	if (!visible) {
		this.visible_ = visible;
		$(this.fDiv_).setStyle("display","none");
		$(this.iDiv_).setStyle("display","none");
		$(this.pDiv_).setStyle("display","none");
		$(this.psDiv_).setStyle("display","none");
	}
}


// Setzt href-Links auf den Marker:

QuestimMarker.prototype.setLink = function(link) {
	this.link = link;
	this.pDiv_.setProperty("href",link);
	this.iDiv_.setProperty("href",link);
}


// Setzt den Buchstaben des Pins:

QuestimMarker.prototype.setMarkerChar = function(markerChar) {
	if (!this.visible_) return;
	this.markerChar = markerChar;
	if (markerChar != null) {

		// Markerchar angegeben => Pin wird in den Vordergrund geholt
		// Und Buchstaben-Grafik geladen

		this.pDiv_.style.backgroundImage = "url(/img/pin"+markerChar+".png)";
		this.fDiv_.style.zIndex = 2;
		this.iDiv_.style.zIndex = 2;
		this.pDiv_.style.zIndex = 2;
	} else {

		// Markerchar ist null, blasser Pin wird angezeigt, pin in den
		// Hintergrund gestellt

		this.pDiv_.style.backgroundImage = "url(/img/pin_blass.png)";
		this.fDiv_.style.zIndex = 1;
		this.iDiv_.style.zIndex = 1;
		this.pDiv_.style.zIndex = 1;
	}
}


// Marker wird in den Thumbnail- (=1) oder Pin-(=0) - Modus geschaltet:

QuestimMarker.prototype.enableThumbnail = function(state) {
	if (!this.visible_) return;

	// Frame und Image divs ein oder ausblenden, je nach state:

	this.fDiv_.style.visibility=(state) ? "visible" : "hidden";
	this.iDiv_.style.visibility=(state) ? "visible" : "hidden";
	if (state) {
		this.pDiv_.style.backgroundImage="url(/img/pin_blackframe.png)";

		// Im Thumbnailmodus Mouseevents über Thumbnail-Rahmen statt Pin einfangen

		this.clearListeners();
		this.addListeners(this.fDiv_);
		this.addListeners(this.iDiv_);
		this.pDiv_.style.zIndex = 1;
	}
	this.thumbnailMode = (state) ? 2 : 1;
}


// Beginnt Thumbnail-Slideshow

QuestimMarker.prototype.startCycleImages = function() {
	if (!this.visible_) return;

	// Nur wenn Bilder vorhanden: Zähler auf null setzen und mit dem nächsten Bild beginnen

	if (this.images_ != undefined) {
		if (this.images_.length>1) {
			this.imageCounter_ = 0;
			this.cycleNextImage();
		}
	}
}


// Zeigt das nächste Bild der Thumbnail-Slideshow und setzt den Timeout schon für das nächste Bild:

QuestimMarker.prototype.cycleNextImage = function() {
	if (!this.visible_) return;

	// Für die Slideshow wird jeweils das image-Div mit dem entspr. Thumbnail im this.images Array belegt

	this.iDiv_.style.backgroundImage = "url("+this.images_[this.imageCounter_].pin+")";
	this.imageCounter_++;

	// Wenn das letzte Bild erreicht wurde, wieder von vorne anfangen

	if (this.imageCounter_ >= this.images_.length) this.imageCounter_ = 0;
	var that = this;
	this.toId=setTimeout(function() {that.cycleNextImage();},1000);
}


// Stoppt die Thumbnail-Slideshow und setzt wieder das erste Bild ein:

QuestimMarker.prototype.stopCycleImages = function() {
	if (!this.visible_) return;
	if (this.images_!=undefined) {
		if (this.images_.length>1) {
			clearTimeout(this.toId);
			this.iDiv_.style.backgroundImage = "url("+this.images_[0].pin+")";
		}
	}
}


// Marker-Mouseover:

QuestimMarker.prototype.mouseOver = function() {
	if (!this.visible_) return;
	var that = this.parentObject;

	// Blasse Marker (kleine Karte) machen kein Mouseover

	if (this.markerChar==null && !that.mapExpanded) return;

	// Nur, wenn die Karte nicht verbreitert wurde, Pin UND Ergebnisliste highlighten:

	if (!that.mapExpanded) {

		// Photo-Slideshow in Ergebnisliste starten

		that.startCycleImages(this.object_id);

		// Mouseover in Ergebnislisste

		var elm = $('row'+this.object_id);

		elm.addClass('over');
		var markerElm = $('marker'+this.object_id);
		markerElm.style.backgroundImage = "url(/img/marker"+this.markerChar+"_over.png)";
	}

	if (this.thumbnailMode==1) {

		// Thumbnails nur bei Mouseover anzeigen

		this.pDiv_.style.backgroundImage="url(/img/pin_blackframe.png)";
		this.fDiv_.style.visibility = 'visible';
		this.iDiv_.style.visibility = 'visible';
		this.fDiv_.style.zIndex = 8;
		this.iDiv_.style.zIndex = 9;
		this.pDiv_.style.zIndex = 10;

		// Photo-Slideshow im Thumbnail

		this.startCycleImages();

	} else if (this.thumbnailMode==2) {

		// Bei Thumbnailansicht Rahmen Highlighten

		this.fDiv_.className="imageFramePinOver";

		this.fDiv_.style.zIndex = 9;
		this.iDiv_.style.zIndex = 10;
		this.pDiv_.style.zIndex = 8;

		// Photo-Slideshow im Thumbnail

		this.startCycleImages();

	} else {

		// Bei kleiner Karte entspr. Buchstaben-Pin highlighten

		this.pDiv_.style.backgroundImage="url(/img/pin"+this.markerChar+"_over.png)";
		this.pDiv_.style.zIndex = 10;
	}
}

QuestimMarker.prototype.mouseOut = function() {
	if (!this.visible_) return;
	var that = this.parentObject;

	// Blasse Marker (kleine Karte) machen kein Mouseover

	if (this.markerChar==null && !that.mapExpanded) return;

	if (!that.mapExpanded) {

		// Listen Mouseout bei kleiner Kartenansicht

		that.stopCycleImages(this.object_id);
		$('row'+this.object_id).removeClass('over');
		var markerElm = $('marker'+this.object_id);
		markerElm.style.backgroundImage = "url(/img/marker"+this.markerChar+".png)";
	}

	if (this.thumbnailMode==1) {

		// Thumbnails nur bei Mouseover anzeigen

		this.pDiv_.style.backgroundImage="url(/img/pin_none.png)";
		this.fDiv_.style.visibility = 'hidden';
		this.iDiv_.style.visibility = 'hidden';
		this.fDiv_.style.zIndex = 5;
		this.iDiv_.style.zIndex = 6;
		this.pDiv_.style.zIndex = 7;

		// Photo-Slideshow im Thumbnail

		this.stopCycleImages();

	} else if (this.thumbnailMode==2) {

		// Bei Thumbnailansicht Rahmen Highlighten

		this.fDiv_.className="imageFramePin";
		this.fDiv_.style.zIndex = 6;
		this.iDiv_.style.zIndex = 7;
		this.pDiv_.style.zIndex = 5;

		// Photo-Slideshow im Thumbnail

		this.stopCycleImages();

	} else {

		// Bei kleiner Karte Buchstaben-Pin highlighten

		this.pDiv_.style.backgroundImage="url(/img/pin"+this.markerChar+".png)";
		this.pDiv_.style.zIndex = 7;
	}
}


// Marker von Karte entfernen

QuestimMarker.prototype.remove = function() {
	this.fDiv_.parentNode.removeChild(this.fDiv_);
	this.pDiv_.parentNode.removeChild(this.pDiv_);
	this.iDiv_.parentNode.removeChild(this.iDiv_);
	this.psDiv_.parentNode.removeChild(this.psDiv_);
}

// Marker kopieren (std. Google Api funktion)

QuestimMarker.prototype.copy = function() {
	return new QuestimMarker(this.location_, this.images_);
}

// Marker auf Karte positionieren:

QuestimMarker.prototype.redraw = function(force) {
	if (!force) return;
	if (!this.visible_) return;
	var point = this.map_.fromLatLngToDivPixel(this.location_);
	this.fDiv_.style.left = (point.x-17)+"px";
	this.fDiv_.style.top = (point.y-71)+"px";
	this.iDiv_.style.left = (point.x-12)+"px";
	this.iDiv_.style.top = (point.y-65)+"px";
	this.pDiv_.style.left = (point.x-13)+"px";
	this.pDiv_.style.top = (point.y-35)+"px";
	this.psDiv_.style.left = (point.x-13)+"px";
	this.psDiv_.style.top = (point.y-35)+"px";
}

// Class pagestate
// Speichert den Zustand der momentanen Seitenansicht. Wird gespeichert und wiederhergestellt,
// wenn man zwischen Ergebnisliste und Exposee wechselt

function PageState() {

	// Default-Werte setzen

	INIT_pagenr = false;
	INIT_position = false;
	INIT_pageType = false;
	INIT_zoom = false;
	INIT_mapType = false;
	INIT_mapState = false;
	currentHash = window.location.hash;
}

// Speichert momentan angesehene Seite in der Ergebnisliste

PageState.prototype.setPage = function(page) {
	this.page = page;
}

// Speichert Map-Vergrößerungszustand (true = map verbreitert)

PageState.prototype.setMapState = function(mapState) {
	this.mapState = mapState;
}

// Positionierung der Karte (google location koordinaten)

PageState.prototype.setPosition = function(mapPosition) {
	this.position = mapPosition;
}

// Zoomstufe der Karte

PageState.prototype.setZoom = function(mapZoom) {
	this.zoom = mapZoom;
}

// Map-Art 0=G_NORMAL_MAP, 1=G_SATELLITE_MAP, 2=G_PHYSICAL_MAP

PageState.prototype.setMapType = function(mapType) {
	this.mapType = mapType;
}

// Art der Ergebnisansicht: "small" => 15 pro seite, alles andere: 8 pro Seite

PageState.prototype.setPageType = function(pageType) {
	this.pageType = pageType;
}

// Setzt Feld, nach dem die Ergebnisliste sortiert werden soll

PageState.prototype.setOrderField = function(orderField) {
	this.orderField = orderField;
}

// Setzt Richtung, in die Sortiert werden soll

PageState.prototype.setOrderDir = function(orderDir) {
	this.orderDir = orderDir;
}

// Speichert Seiten-Status in Cookie:

PageState.prototype.update = function() {
	var params = ['hash:'+escape(currentHash)];
	if (this.pageType!=undefined) params.push("pagetype:"+this.pageType);
	if (this.page!=undefined) params.push("page:"+this.page);
	if (this.position!=undefined) params.push("pos:"+this.position.lat()+","+this.position.lng());
	if (this.zoom!=undefined) params.push("zoom:"+this.zoom);
	if (this.mapType!=undefined) params.push("maptype:"+this.mapType);
	if (this.orderField!=undefined) params.push("orderfield:"+this.orderField);
	if (this.orderDir!=undefined) params.push("orderdir:"+this.orderDir);
	if (this.mapState!=undefined) params.push("mapstate:"+this.mapState);
	var cString = params.join("|");
	Cookie.set('pageState',cString,{duration:999});
}

// Lädt Seiten-Status von Cookie:

PageState.prototype.load = function(newplace) {
	var cString = Cookie.get("pageState");
	if (cString) {
		var parts = cString.split("|");
		parts.each(function(part) {
			var tmp = part.split(":");
			var type = tmp[0];
			var value = tmp[1];
			switch(type) {
				case 'hash':
				/*
					var hash = unescape(value);
					if (hash!=window.location.hash) {
						Cookie.remove("pageState");
						return false;
					}
				*/
					break;
				case 'mapstate':
					value = (value=="false") ? false : true;
					this.mapState = value;
					INIT_mapState = value;
					break;
				case 'orderfield':
					this.orderfield = value;
					doObj.sortType = value;
					DO_sortType = value;
					break;
				case 'orderdir':
					this.orderdir = value;
					doObj.sortDirection = value;
					DO_sortDirection = value;
					break;
				case 'page':
					if (!newplace) {
						this.page = value;
						INIT_pagenr = Number(value);
					}
					break;
				case 'pos':
					if (!newplace) {
						var coords = value.split(",");
						this.position = new GLatLng(Number(coords[0]), Number(coords[1]));
						INIT_position = this.position;
					}
					break;
				case 'pagetype':
					this.pageType = value;
					INIT_pageType = value;
					break;
				case 'zoom':
					if (!newplace) {
						this.zoom = value;
						INIT_zoom = Number(value);
					}
					break;
				case 'maptype':
					this.mapType = value;
					INIT_mapType = value;
					break;
			}
		});
	}
}

// Class DisplayObjects
// Diese Klasse kümmert sich um die Ergebnisanzeige und steuerung der Google-Karte

function DisplayObjects(mode,objectContainer,mapContainer) {
	this.newPlace = false;						// Neue Location wurde eingegeben
	this.objectContainer = objectContainer;	// Container für Objektliste
	this.mapContainer = mapContainer;			// Container für Karte
	this.mode = mode;							// Obsolet: Manage oder View
	this.objectMarkers = {};					// Alle Questim-Marker
	this.objectImages = {};					// Objekt-Bilder
	this.idArray = [];							// ids aller Objekte
	this.oldPos = null;							// vorherige Kartenposition
	this.googleZoomLevels = [17,16,15,14,13,12,11,10,9];	// Zoomstufen
	this.googleZoomMin = 9;					// Minimale Zoomstufe
	this.googleZoomMax = 17;					// Maximale Zoomstufe
	this.mapTypes = [G_NORMAL_MAP,G_SATELLITE_MAP,G_PHYSICAL_MAP];	// Die verschiedenen Kartenansichten
	this.mapExpanded = false;					// Karte verberitert oder nicht
	this.blendDuration = 0;					// Dauer der Überblend-Effekte
	this.hardLimit = 100;						// Max Resultate, die geladen werden sollen
	this.displayMode = "full";					//
	this.perPage = 8;							// Objekte pro Seite
	this.pageRadius = 8;						// Radius für Pagination
	this.map=null;								// Google Map Objekt
	this.currentMapType = 0;					// momentane Kartenansicht
	this.thumbnailZoomThreshold = 12;			// Ab welcher Zoomstufe auf Thumbnail-Ansicht geschaltet wird (nur bei Mapexpanded)
	this.sortType = DO_sortType = 'location';	// Feld, nachdem sortiert wird (standardmäßig Location)
	this.exposee=null;							// Obsolet: Exposeeobjekt
	this.pageState = new PageState();			// Pagestate (s.o.)
	this.currentPage = 1;						// Aktuell angezeigte Seite
	DO_sortDirection = 'up';					// Aktuelle sortierrichtung

	this.firstTime = true;
}

// Startet Thumbnail-Slideshow im Objektansicht:

DisplayObjects.prototype.startCycleImages = function(id) {
	/*var str = "";
	for (key in this.objectImages) {
		str += key+" / ";
	}
	alert ("this is "+this+" Objectimages is "+str+" id is "+id);*/
	if (this.objectImages[id]!=undefined) {
		if (this.objectImages[id].length>1) {
			this.imageCounter = 0;
			this.currentId = id;
			this.cycleNextImage();
		}
	}
}

// Zeigt nächstes Bild in der Slideshow

DisplayObjects.prototype.cycleNextImage = function() {
	if (this.objectImages[this.currentId] == undefined) return;
	document.images["photo"+this.currentId].src = this.objectImages[this.currentId][this.imageCounter].thumb;

	this.imageCounter++;
	if (this.imageCounter >= this.objectImages[this.currentId].length) this.imageCounter = 0;
	var that = this;
	this.toId=setTimeout(function() {
		that.cycleNextImage();
	},1000);
}

// Stoppt Slideshow

DisplayObjects.prototype.stopCycleImages = function(id) {
	if (this.objectImages[id]!=undefined && this.objectImages[id].length>1) {
		clearInterval(this.toId);
		this.toId = null;
		document.images["photo"+id].src = this.objectImages[id][0].thumb;
	}
}

// MouseOver über Objekt in Ergebnisliste

DisplayObjects.prototype.mouseOverRow = function(id) {
	if (this.objectMarkers[id]) {
		GEvent.trigger(this.objectMarkers[id],"mouseover");
		//map.panTo(this.objectMarkers[id].location_);
	} else {
		$('row'+id).style.backgroundColor="#d1e7fe";
		this.startCycleImages(id);
	}
	//this.map.panTo(this.location_);
}

// MouseOut über Objekt in Ergebnisliste

DisplayObjects.prototype.mouseOutRow = function(id) {
	if (this.objectMarkers[id]) {
		GEvent.trigger(this.objectMarkers[id],"mouseout");
	} else {
		$('row'+id).style.backgroundColor="#ffffff";
		this.stopCycleImages(id);
	}
}

// Wechselt in eine andere Objektansicht (15 oder 8 pro Seite, mode=>"small" oder "big")

DisplayObjects.prototype.setDisplayMode = function(mode) {
	this.perPage = (mode=='small') ? 15 : 8;
	this.displayMode = mode;
	this.page = 1;
	this.filterByView();
}

// Sortierfunktion für Objekte in der Ergebnisliste (liegt außerhalb der Klasse)

DisplayObjects_objectSortFunction = function(aObj, bObj) {
	var res=0;
	var aValue=0,bValue=0;
	switch (DO_sortType) {
		case 'location':
			aValue = aObj.location.distanceFrom(DO_centerLoc);
			bValue = bObj.location.distanceFrom(DO_centerLoc);
			break;
		case 'price':
			aValue = parseFloat(aObj.rPrice);
			bValue = parseFloat(bObj.rPrice);
			break;
		case 'size':
			aValue = parseFloat(aObj.rSize);
			bValue = parseFloat(bObj.rSize);
			break;
		case 'date':
			var aValue = aObj.date;
			var bValue = bObj.date;
			break;
	}
	if (aValue > bValue) res=1;
	else if (aValue < bValue) res=-1;
	return (DO_sortDirection=='down') ? -res : res;
}

// Wechselt Feld (type), nachdem die Ergebnisliste sortiert werden soll:

DisplayObjects.prototype.setSortOrder = function(type) {
	var parts = type.split("|");
	this.sortType = DO_sortType = parts[0];
	this.sortDirection = DO_sortDirection = parts[1];
	if (DO_sortType!="location") { // locationsort wird automatisch von filterByView gemacht
		DO_centerLoc = this.map.getCenter();
		this.objects.sort(DisplayObjects_objectSortFunction);
	}
	this.filterByView();
}

// Erzeugt html-String für Photo in der Ergebnisliste

DisplayObjects.prototype.getPhotoHtml = function(sub,id,obj) {
	var html = '';
	var src;
	try {
		src = '/object_thumb/'+sub+id+'/'+obj.getAttribute('field')+"/"+obj.getAttribute('file');
	} catch (e) {
		src = "/img/no_image_thumb.png";
	}
	html += '<img src="'+src+'" alt="" border="0" name="photo'+id+'" />';
	return html;
}

// Liest Attribute aus dem Objekt (obj als xml) und liefert ein Assoziatives Array zurück:

DisplayObjects.prototype.getAttributes = function(obj) {
	var infos = {extra:{}};
	for (i=0; i<obj.length && i<5; i++) {
		var type = obj[i].getAttribute('type');
		var value = getTextNode(obj[i]);//.firstChild.nodeValue;
		var label = obj[i].getAttribute('label');
		if (type != "") {
			if (type=="extra") {
				if (value=="1") {
					infos['extra'][label] = true;
				}
			} else {
				infos[type] = value;
			}
		}
	}
	return infos;
}

// Nicht genutzt: Zoomt auf ein spezielles Objekt

DisplayObjects.prototype.zoomToObject = function(id) {
	var marker = this.objectMarkers[id];
	this.map.setCenter(marker.location_, 15);
}

// Erzeugt einen Eintrag in der Objekt-Ergebnisliste (HTML):
// Obj = Objektdaten, odd = Einfärbung des Hintergrundes

DisplayObjects.prototype.createRow = function(obj,odd) {
	var id = obj.internal_id;
	var subfolders = obj.subfolders;
	var description = getTagContent(obj.elm,'description');
	var title = getTagContent(obj.elm,'title');
	var photoHtml = this.getPhotoHtml(subfolders,id,obj.elm.getElementsByTagName('photo')[0]);
	var qmprice = "";
	if (obj.size) qmprice += obj.size+' m&sup2';
	if (obj.price) {
		if (obj.size) qmprice += ", ";
		qmprice += obj.price+' &euro;';
		if (obj.pricePerQm) qmprice += '/m&sup2;';
	}
	if (this.displayMode=='full') {

		// Listenansicht: Voll (zweispaltig)

		var html =
			'<div id="row'+id+'" class="result_box'+((odd) ? ' odd' : '')+'" onMouseOver="doObj.mouseOverRow(\''+id+'\');" onMouseOut="doObj.mouseOutRow(\''+id+'\');" onClick="doObj.prepareExposee(\''+obj.qid+'\');">'+
			'<a class="relative" href="/'+obj.qid+'" style="display:block;">'+
				'<div class="photobox">'+photoHtml+'</div>'+
				'<div class="info qmprice">'+qmprice+'</div>'+
				'<div class="info title">'+title+'</div>'+
				'<div class="marker" id="marker'+id+'" style="background-image:url(/img/marker'+obj.markerChar+'.png);"></div>'+
				//'<div class="merken"><a href="#"><img src="/img/merken_button.gif" alt="" border="0" align="absmiddle" /> merken</a></div>'+
			'</a>'+
			'</div>';

	} else if (this.displayMode=='small') {

		// Listenansicht: Klein (5x3 Thumbnails)

		var photoLink = (this.mode=='manage') ? id : '#';
		var photoAdd = (this.mode=='manage') ? '' : '#';
		var html =
				'<div id="row'+id+'" class="resultbox_small'+((odd) ? ' odd' : '')+'" onMouseOver="doObj.mouseOverRow(\''+id+'\');" onMouseOut="doObj.mouseOutRow(\''+id+'\');" onClick="doObj.prepareExposee(\''+obj.qid+'\');">'+
					'<a class="relative" href="/'+obj.qid+'" style="display:block;">'+
						'<div class="blende"></div><div class="blende2"></div>'+
						'<div class="photobox" '+photoAdd+'>'+photoHtml+'</div>';
						html += '<div class="qm">'+qmprice+'</div>';
						html +=
						'<div class="marker" id="marker'+id+'" style="background-image:url(/img/marker'+obj.markerChar+'.png);"></div>'+
				'</a>'+
				'</div>';
	}
	return html;
}

// Rendert Sortierpfeil für Ergebnisliste

DisplayObjects.prototype.getSortArrow = function(type) {
	if (this.sortType==type) {
		return '<img src="/img/order_'+((this.sortDirection=='down') ? 'down' : 'up')+'.gif">';
	}
	return '';
}

// Wechselt Sortierrichtung

DisplayObjects.prototype.changeSortOrder = function(value) {
	this.currentPage = 1;
	this.setSortOrder(value);
}

/* Erzeugt Tool-Leiste für Resultate bei Suche und Inseraten */

DisplayObjects.prototype.getViewHTML = function() {
	// Buttons für Listen- und Thumbnailansicht:
	if (this.displayMode=='full') {
			var html =
			'<ul id="examplenavi" class="full">'+
				'<li id="yo1"><a href="#"></a></li>'+
				'<li id="yo2"><a href="javascript:doObj.setDisplayMode(\'small\');"></a></li>'+
			'</ul>';
			}
		else {
			var html =
			'<ul id="examplenavi" class="small">'+
				'<li id="yo1"><a href="javascript:doObj.setDisplayMode(\'full\');"></a></li>'+
				'<li id="yo2"><a href="#"></a></li>'+

			'</ul>';
			}

	// Sortierdropdown:
	/*
	var orderFields = {
		location:'Geografisch',
		size:'Gr&ouml;&szlig;e',
		price:'Preis',
		date:'Datum'
	};
	*/
	var sortOptions = {
		'location|up':getText("search","sort_geographic"),
		'price|down':getText("search","sort_price_highest"),
		'price|up':getText("search","sort_price_lowest"),
		'size|down':getText("search","sort_size_biggest"),
		'size|up':getText("search","sort_size_smallest"),
		'date|down':getText("search","sort_date_newest"),
		'date|up':getText("search","sort_date_oldest")
	};
	html += '<div id="listsort"><select onChange="doObj.changeSortOrder(this.value);">';
	var currentMode = this.sortType+"|"+this.sortDirection;
	$each(sortOptions,function(str,idx){
		var sel = (idx==currentMode) ? "SELECTED" : "";
		html += '<option value="'+idx+'" '+sel+'>'+str+'</option>';
	});
	/*
	// Aufsteigend/Absteigend:
	if (this.sortType == undefined) {
		html+='<option value="">Sortieren</option>';
	} else {
		html+='<option value="'+this.sortType+'" SELECTED>'+orderFields[this.sortType]+", "+((this.sortDirection=='down') ? 'absteigend' : 'aufsteigend')+" </option>";
		html+='<option value="'+this.sortType+'" style="margin-bottom:10px;">'+orderFields[this.sortType]+', '+((this.sortDirection=='down') ? 'aufsteigend' : 'absteigend')+'</option>';
	}
	// Sortierfelder:
	var that=this;
	$each(orderFields,function(fieldName,field){
		if (that.sortType!=field) {
			html+='<option value="'+field+'">'+fieldName+"</option>";
		}
	});*/
	html += '</select></div>';

	// Zoom auf alle Inserate im Verwalten-Modus
	if (this.mode=='manage') {
		html += '<div id="extra"><a href="javascript:doObj.zoomToAll()">Zoom auf alle Inserate</a></div>';
	}

	return html;
}

// Erzeugt Pagination für Ergebnisliste:

DisplayObjects.prototype.createPagination = function(page) {
	//var addition = (this.overflowItems>0) ? " ("+this.overflowItems+" nicht angezeigt)" : "";
	var addition="";

	var html = '<div style="position:relative; height:31px;"><div id="resultnum">';
	if (this.items==1) html += '<table><tr><td class="num" id="resultnumvalue">'+this.items+'</td><td class="ergebnisse"> '+getText("search","resultinfo_1")+'</td></tr></table>';
		else if (this.items>1) html += '<table><tr><td class="num" id="resultnumvalue">'+this.items+'</td><td class="ergebnisse"> '+getText("search","resultinfo")+'</td></tr></table>';
		else html += '<table><tr><td class="num">0</td><td class="ergebnisse"> '+getText("search","resultinfo")+'</td></tr></table>';


	/*if (this.searchId != "") {
		html += '<div id="searchId">Search-ID:<span class="id">'+createSID(this.searchId)+'</span></div>';
	}*/

	html+='</div>';
	html+='<div id="pagination">';
	if (this.items>0) html += '<table><tr>';
	if (page>1) html+= '<td><img src="/img/miniarrow_back.gif" border="0"/></td><td><a href="#" class="pager" onclick="doObj.gotoPage('+(page-1)+')">'+getText("search","pagination_back")+'&nbsp;</a></td>';
	var i, j;
	var halfRadius = Math.floor(this.pageRadius/2);
	var start = page-halfRadius;
	if (start>this.pages-this.pageRadius+1) start=this.pages-this.pageRadius+1;
	if (start<1) start=1;
	for (i=start,j=0; i<= this.pages && j<this.pageRadius; i++, j++) {
		if (i>start) html+='<td><span class="balko">|</span></td>';
		if (page==i) {
			html += '<td class="currentpage">'+i+'</td> ';
		} else {
			html += '<td><a href="#" onclick="doObj.gotoPage('+i+')">'+i+'</a></td>';
		}
	}
	if (page < this.pages) html+= '<td><a href="#" class="pager" onclick="doObj.gotoPage('+(page+1)+')">&nbsp;'+getText("search","pagination_next")+'</a></td><td><img src="/img/miniarrow_forward.gif" border="0"/></td>';
	html += '</table></div></div>';
	return html;
}

// Springt auf eine Seite innerhalb der Ergebnisliste:

DisplayObjects.prototype.gotoPage = function(page) {

	if (this.mapExpanded) {
		var html ='<div style="position:relative; height:31px;">'+
			'<div id="resultnum">';
			if (this.items==1) html += '<table><tr><td class="num" id="resultnumvalue">'+this.items+'</td><td class="ergebnisse"> '+getText("search","resultinfo_1")+'</td></tr></table>';
			else if (this.items>1) html += '<table><tr><td class="num" id="resultnumvalue">'+this.items+'</td><td class="ergebnisse"> '+getText("search","resultinfo")+'</td></tr></table>';
			else html += '<table><tr><td class="num">0</td><td class="ergebnisse"> '+getText("search","resultinfo")+'</td></tr></table>';
			html += ' <a href="javascript:doObj.minimizeMap();" class="backtosmallmap">'+getText("search","backtosmallmap")+'</a></div></div>';
		$('resultnavi').innerHTML = html;
		return;
	}
	this.currentPage = page;
	var i;
	var start = this.perPage*(page-1);
	var end = start+(this.perPage-1);
	var objectHTML = '';
	for (i=0; i<this.items; i++) {
		var id = this.idArray[i];
		var marker = this.objectMarkers[id];
		if (i>=start && i<=end) {
			var markerChar = String.fromCharCode(65-start+i);
			var obj = this.visibleObjects[i];

			// Je nach Anz. der Spalten (bei "full" 2, bei "small" 3) Hintergrunddarstellung berechnen:

			var odd = (this.displayMode=='full') ? Math.floor(i/2)%2 ^ i%2 : !(Math.floor(i/5)%2) ^ (i%2);
			obj.markerChar = markerChar;
			objectHTML += this.createRow(obj,odd);
			marker.setMarkerChar(markerChar);
			marker.setLink("/"+obj.qid);
		} else {
			marker.setMarkerChar(null);
			marker.setLink("#");
		}
		marker.page = Math.floor(i/this.perPage)+1;
	}
	var navHtml = '';
	navHtml += this.createPagination(page);
	navHtml += this.getViewHTML();
	$('resultnavi').innerHTML = navHtml;
	$(this.objectContainer).innerHTML = objectHTML;
}

// Helferfunktion für gotoPage

function gotoPageDelayed() {
	doObj.gotoPage(doObj.pageToGo);
}

// Erzeugt Questim Marker auf der Karte

DisplayObjects.prototype.insertObjectMarker = function(obj,markerChar) {

	// Nur Marker mit gültiger Position werden platziert:

	if (obj.location.lat()!=0 && obj.location.lng()!=0) {
		var location = obj.location;
		var images = new Array();
		var photosDOM = obj.elm.getElementsByTagName('photo');
		var j;

		// Image-Array für Thumbnail-Slideshow erzeugen

		for (j=0; j<photosDOM.length; j++) {
			var field = photosDOM[j].getAttribute('field');
			var file = photosDOM[j].getAttribute('file');
			images.push({
				pin:'/object_pin/'+obj.subfolders+obj.internal_id+'/'+field+'/'+file,
				thumb:'/object_thumb/'+obj.subfolders+obj.internal_id+'/'+field+'/'+file
			});
		}

		// Questim-Marker erzeugen

		var marker = new QuestimMarker(location, images);
		this.map.addOverlay(marker);

		// Marker sichtbar machen, jenachdem, ob "publish address" gesetzt ist und ab entspr. Zoomlevel

		marker.setVisible(!(obj.publish_address=="0" && this.map.getZoom() >= obfuscation_level));
		if (this.mapExpanded) {
			marker.enableThumbnail(this.map.getZoom() >= this.thumbnailZoomThreshold);
			marker.setLink("/"+obj.qid);
		}
		marker.object_id = obj.internal_id;
		var that = this;
		marker.parentObject = that;

		// Mausaktionen für Marker festlegen:

		GEvent.addListener(marker,"click",function() {
			if (this.page != that.currentPage && !that.mapExpanded) {
				doObj.pageToGo = this.page;
				setTimeout(gotoPageDelayed,100);
			} else {
				that.prepareExposee(obj.qid);
			}
		});
		GEvent.addListener(marker,"mouseover",function() {this.mouseOver();});
		GEvent.addListener(marker,"mouseout",function() {this.mouseOut();});

		// Interne Arrays updaten

		this.objectImages[obj.internal_id] = images;
		this.objectMarkers[obj.internal_id] = marker;
		this.idArray.push(obj.internal_id);
	}
}

// Zoomt Karte so, dass das Gebiet innerhalb von bounds zu sehen ist

DisplayObjects.prototype.realBoundsZoom = function(bounds) {
	this.map.setZoom(this.map.getBoundsZoomLevel(bounds));
	var NE = this.map.fromLatLngToDivPixel(bounds.getNorthEast());
	var SW = this.map.fromLatLngToDivPixel(bounds.getSouthWest());
	NE.y -= 72;
	SW.y += 16;
	NE.x += 5;
	SW.x -= 50;
	bounds.extend(this.map.fromDivPixelToLatLng(NE));
	bounds.extend(this.map.fromDivPixelToLatLng(SW));
	this.map.setCenter(bounds.getCenter());
	this.map.setZoom(this.map.getBoundsZoomLevel(bounds));
}

// Erzeugt Ergebnisliste und dazugehörige Marker:

DisplayObjects.prototype.createMapAndList = function(bounds) {
	var i;
	var viewbounds = new GLatLngBounds();
	var extended = false;
	this.objectMarkers = {};
	this.objectImages = {};
	this.idArray = [];
	this.map.clearOverlays();
	this.items = 0;
	this.overflowItems = 0;
	this.visibleObjects = [];
	var startPage = 1;

	// Lässt Marker erzeugen und fügt sie in die Liste der "Sichtbarn Marker" ein, wenn sie im
	// sichbaren Bereich der Karte liegen

	for (i=0; i<this.objects.length; i++) {
		if (bounds==null || (bounds.containsLatLng(this.objects[i].location)) ) {
			if (this.items < this.hardLimit) {
				if (bounds==null) {
					viewbounds.extend(this.objects[i].location);
					extended = true;
				}
				this.insertObjectMarker(this.objects[i]);
				this.visibleObjects.push(this.objects[i]);
				this.items++;
			} else {
				this.overflowItems++;
			}
		}
	}

	// Berechnet Seitenanzahl anhand der sichtbaren Objekte

	this.pages = Math.ceil(this.items/this.perPage);

	// Falls keine Objekte im Sichtbaren Bereich liegen "No Results" Seite anzeigen:

	if (this.visibleObjects.length==0) {
		//var html = '<div align="center">Leider keine Ergebnisse in diesem Abschnitt gefunden.<br/><br/>';
		//if (extended || bounds!=null) html+='<a href="javascript:doObj.createMapAndList(null);">Auf alle gefundene Objekte zoomen</a>';
		//html += '</div>';
		var newHTML = $('noresultsfound').innerHTML;
		$('results').innerHTML = newHTML;
		$('zoomoption').setStyle("display", (extended || bounds!=null && this.objects.length>0) ? 'block' : 'none');
		var resultsNum = $('resultnumvalue');
		if (resultsNum) {
			resultsNum.innerHTML="0";
		}
		var pgElm = $('pagination');
		if (pgElm!=null) pgElm.setHTML("");
	} else {
		if (bounds==null) {
			if (extended) {
				this.gotoPage(startPage);
				this.realBoundsZoom(viewbounds);
			} else {
				this.map.setCenter(this.searchCenter,12);
			}
		} else {
			if (this.currentPage > this.pages)
				this.currentPage = this.pages;
			else if (this.currentPage < 1)
				this.currentPage = 1;
			this.gotoPage(this.currentPage);
		}
	}
	this.updateZoomBar();
	this.updateMapType();
}

// Erzeugt Kartenausschnitt vom Mittelpunkt des Suchergebnisses aus

DisplayObjects.prototype.filterByView = function() {
	var centerLoc = this.map.getCenter();
	if (this.mode != "manage") {
		var distance = centerLoc.distanceFrom(this.searchCenter);
	} else {
		var distance = 0;
	}

	if (distance > 20000) {
		startSearchCoordinates(centerLoc,true);
	} else {
		var viewBounds = this.map.getBounds();
		var NE = this.map.fromLatLngToDivPixel(viewBounds.getNorthEast());
		var SW = this.map.fromLatLngToDivPixel(viewBounds.getSouthWest());
		NE.y += 10;
		SW.y += 42;
		NE.x += 12;
		SW.x += 10;
		viewBounds.extend(this.map.fromDivPixelToLatLng(NE));
		viewBounds.extend(this.map.fromDivPixelToLatLng(SW));
		if (this.sortType=='location') {
			DO_centerLoc = centerLoc;
			this.objects.sort(DisplayObjects_objectSortFunction);
		}
		this.createMapAndList(viewBounds);
	}
}

// Zoomt den Kartenausschnitt auf alle Objekte der aktuellen Seite

DisplayObjects.prototype.zoomToSelection = function() {
	var bounds = new GLatLngBounds();
	var i;
	for (i=0; i<this.idArray.length; i++) {
		var obj = this.objectMarkers[this.idArray[i]];
		if (obj.page == this.currentPage) {
			bounds.extend(obj.location_);
		}
	}
	this.realBoundsZoom(bounds);
}

// Zoomt den Kartenausschnitt auf alle Objekte

DisplayObjects.prototype.zoomToAll = function() {
	var bounds = new GLatLngBounds();
	this.objects.each(function(obj){
		bounds.extend(obj.location);
	});
	this.realBoundsZoom(bounds);
}

// Liest wichtigste Attribute und befestigt diese am selben Objekt
// obj: Objekt als XML-Struktur
// Aus obj wird ein neues Objekt:
// attInfo: Alle Attribute als key=>value Paar
// elm: Das ehemalige objekt.

DisplayObjects.prototype.getBasicAttributes = function(obj) {
	var objAtt = obj.getElementsByTagName('attribute');
	var newObj = {
		attInfo:{},
		elm:obj
	};
	newObj.qid = createQID(Number(obj.getAttribute('realid')));
	newObj.internal_id = obj.getAttribute('id');
	newObj.subfolders = obj.getAttribute('subfolders');
	newObj.realid = obj.getAttribute('realid');
	newObj.date = obj.getAttribute('date');
	var price = obj.getAttribute('price');
	var size = obj.getAttribute('size');
	var rooms = obj.getAttribute('rooms');
	newObj.publish_address = obj.getAttribute('publish_address');
	newObj.rPrice = price;
	newObj.rSize = size;
	newObj.rRooms = rooms;
	newObj.price = decimalToStr(price);
	newObj.size = decimalToStr(size);
	newObj.rooms = decimalToStr(rooms,1);
	newObj.pricePerQm = (obj.getAttribute('price_per_qm')=='1');
	newObj.location = new GLatLng(parseFloat(obj.getAttribute('lat')),parseFloat(obj.getAttribute('lng')));
	return newObj;
}

// Bewegt die Karte um xdir,ydir Einheiten (für Scrollbuttons neben der Karte)

DisplayObjects.prototype.startScroll = function(xdir,ydir) {
	this.map.panDirection(-xdir,-ydir);
}

// Zoomt die Karte auf den entspr. Level

DisplayObjects.prototype.zoomTo = function(level) {
	this.map.setZoom(this.googleZoomLevels[level]);
}

// Updated die Grafik des Zoom-Reglers

DisplayObjects.prototype.updateZoomBar = function() {
	var level=8;
	var googleLevel = this.map.getZoom();
	var i;
	for (i=0;i<this.googleZoomLevels.length;i++) {
		if (googleLevel == this.googleZoomLevels[i]) level = i;
	}
	if (googleLevel < this.googleZoomMin) level = 8;
	if (googleLevel > this.googleZoomMax) level = 0;
	$('mapzoomlevels').src = "/img/mapIcon_zoom"+level+".gif";
}

// Updated die aktuelle Kartenansicht im Pulldown

DisplayObjects.prototype.updateMapType = function() {
	$('maptypes').selectedIndex = this.mapTypes.indexOf(this.map.getCurrentMapType());
}

// Wechselt die Kartenansicht

DisplayObjects.prototype.setMapType = function(typeNr) {
	var mapType = this.mapTypes[typeNr];
	this.currentMapType = typeNr;
	this.map.setMapType(mapType);
	this.updateMapType();
}

// Verbreitert die Karte mit einer weichen Animation. ist "fast" angegeben, passiert dies ohne Animation,
// z.B. wenn diese Kartenansicht durch den PageState wieder hergestellt wurde.

DisplayObjects.prototype.maximizeMap = function(fast) {

	// Ist die Karte schon erweitert, wird sie minimiert:

	if (this.mapExpanded) {
		this.minimizeMap();
		return;
	}
	GEvent.clearListeners(this.map, 'moveend');
	this.mapExpanded = true;
	$('mapmaximize').innerHTML="min";
	$('map').style.zIndex=5;
	var that=this;
	this.oldCenter = this.map.getCenter();

	// Kartenfenster wird vergrößert, im Anschluss Google-Maps darüber benachrichtigt:

	var tOptions = {
		duration:1000, wait:false, transition:Fx.Transitions.Cubic.easeOut, fps:30
	};
	if (fast) tOptions.duration=0;
	var mapFx = new Fx.Styles($('map'), $merge(tOptions,{
		onComplete:function() {
			that.reInitMap(fast);
		}
	}));

	// Alle Scrollbuttons werden an die neuen Kartengröße angepasst:

	$('results').setStyle('visibility','hidden');
	var mslFx = new Fx.Styles($('mapScrollLeft'), tOptions);
	var msuFx = new Fx.Styles($('mapScrollUp'), tOptions);
	var msdFx = new Fx.Styles($('mapScrollDown'), tOptions);
	mapFx.start({'left':7,	'width':959});
	mslFx.start({'left':6});
	msuFx.start({'left':465});
	msdFx.start({'left':465});
}

// Karte wird minimiert:

DisplayObjects.prototype.minimizeMap = function() {
	var that = this;
	$('mapmaximize').innerHTML="max";
	GEvent.clearListeners(this.map, 'moveend');
	this.mapExpanded = false;
	this.oldCenter = this.map.getCenter();
	var tOptions = {
		duration:1000, wait:false, transition:Fx.Transitions.Cubic.easeOut, fps:30
	};
	var mapFx = new Fx.Styles($('map'), $merge(tOptions,{onComplete:function() {
		that.reInitMap();

	}}));
	$('results').setStyle('visibility','visible');
	var mslFx = new Fx.Styles($('mapScrollLeft'), tOptions);
	var msuFx = new Fx.Styles($('mapScrollUp'), tOptions);
	var msdFx = new Fx.Styles($('mapScrollDown'), tOptions);
	mapFx.start({'left':668, 'width': 298});
	mslFx.start({'left':668});
	msuFx.start({'left':800});
	msdFx.start({'left':800});
}

// Passt Karte an das Kartencontainer-Element an, mit Animatioin (wenn fast=false):

DisplayObjects.prototype.reInitMap = function(fast) {
	var that = this;
	this.map.checkResize();
	if (fast) {
		this.map.setCenter(this.oldCenter);
	} else {
		this.map.panTo(this.oldCenter);
	}
	GEvent.addListener(this.map, 'moveend', function() {that.filterByView();});
	this.filterByView();
}

// Bereitet die Anzeige eines Exposees vor:

DisplayObjects.prototype.prepareExposee = function(id) {
	var that = this;
	that.visibleObjects.each(function(obj,i){
		if (obj.qid==id) {

			// Liste aller Objekte in Ergebnisliste und Position des übergebenen Objektes
			// Werden ermittelt und in einen Cookie geschrieben (damit man auf der Exposee-Seite
			// darüber blättern kann)

			var objToShow = obj;
			var realId = objToShow.elm.getAttribute('realid');
			var Qid = createQID(realId);
			var objIds = [];
			var position = 0;
			that.visibleObjects.each(function(ob,idx){
				objIds.push(createQID(ob.elm.getAttribute('realid')));
				if (ob==obj) position = idx;
			});
			var cString = position+","+objIds.join(",");
			Cookie.set("objlist",cString);
		}
	});
	return true;
}

// Initialisiert Google-Map und alle Mouse-Events:

DisplayObjects.prototype.initGoogleMap = function() {
	if (this.map==null) {
		var that = this;

		// Karte mit entspr. Kartenansichten:

		this.map = new GMap2($('map'),{mapTypes:this.mapTypes});
		this.map.enableContinuousZoom();	// Flüssiges Zoomen aktivieren

		// Zoomstufe und Mittelpunkt einstellen:

		if (this.searchCenter) {
			center = this.searchCenter;
		} else {
			this.searchCenter = center = new GLatLng(53.56, 9.95);
		}
		if (this.initZoomLevel) zoom = this.initZoomLevel;
			else zoom = 15;
		this.map.setCenter(center, zoom);

		// Handler, die nach dem Zoomvorgang aufgerufen werden:

		GEvent.addListener(this.map, 'moveend', function() {that.filterByView();});
		GEvent.addListener(this.map, 'zoomend', function() {that.filterByView();});

		// Scrollbuttons belegen:

		GEvent.addDomListener($('mapScrollUp'), "click", function() {that.startScroll(0,-1);});
		GEvent.addDomListener($('mapScrollDown'), "click", function() {that.startScroll(0,1);});
		GEvent.addDomListener($('mapScrollLeft'), "click", function() {that.startScroll(-1,0);});
		GEvent.addDomListener($('mapScrollRight'), "click", function() {that.startScroll(1,0);});

		// Zoombuttons belegen:

		GEvent.addDomListener($('mapzoomin'),"click", function() {that.map.zoomIn();});
		GEvent.addDomListener($('mapzoomout'),"click", function() {that.map.zoomOut();});

		if ($('mapmaximize')!=null) {
			GEvent.addDomListener($('mapmaximize'),"click", function() {that.maximizeMap();});
		}
	}
}

// Die eigentliche Einstiegsfunktion der Klasse.
// Sobald die Suchfunktion XML zurückliefert, wird diese Funktion aufgerufen:

DisplayObjects.prototype.parseXML = function(XML, dontRelocate) {
	if (this.exposee!=null && this.exposee.active) {

		// Obsolet: Exposee-Ansicht beenden

		this.exposee.clear(this.unHibernate);
	} else if (GBrowserIsCompatible()) {

		// wenn diese Funktion das erste mal (nach Laden der Seite) aufgerufen wird,
		// wird der Seitenstatus durch pageState wiederhergestellt.

		if (this.firstTime) {
			this.pageState.load(this.newPlace);
			this.firstTime = false;
		}

		// Alle Werte aus dem evlt. geladenen PageState werden umgesetzt:

		this.newPlace = false;
		if (INIT_zoom) {
			//this.map.setZoom(INIT_zoom);
			this.initZoomLevel = INIT_zoom;
			INIT_zoom = false;
		}
		if (INIT_pageType) {
			this.displayMode = INIT_pageType;
			this.perPage = (INIT_pageType=='small') ? 15 : 8;
		}
		if (INIT_position) {
			this.searchCenter=INIT_position;
			INIT_position = false;
		}

		// Google Maps initialisieren

		this.initGoogleMap();
		DO_centerLoc = this.map.getCenter();

		// Search-ID aus XML entnehmen:

		this.searchId = XML.getElementsByTagName('objects')[0].getAttribute('searchid');

		var objects_tmp = XML.getElementsByTagName("object");
		this.objects = new Array();
		var i;

		// Objekte in sortierbares Array umwandeln:

		for (i=0; i<objects_tmp.length; i++) {
			var newObj = this.getBasicAttributes(objects_tmp[i]);
			this.objects.push(newObj);
		}
		if (DO_sortType) {
			this.objects.sort(DisplayObjects_objectSortFunction);
		}
		if (INIT_pagenr) {
			this.currentPage = INIT_pagenr;
			INIT_pagenr = false;
		}
		if (!dontRelocate) {

			if (this.initZoomLevel) zoom = this.initZoomLevel;
				else zoom = 15;

			// Wenn mehr als 100 Objekte gefunden wurden,
			// in die Karte hineinzoomen:
			if (objects_tmp.length > 100) {
				zoom = zoom+1;
			}
			// Wenn weniger als 2 Objekte gefunden wurden,
			// in die Karte hineinzoomen:
			if (objects_tmp.length < 2) {
				zoom = zoom-1;
			}

			this.currentPage = 1;
			this.map.setCenter(this.searchCenter, zoom);
			this.filterByView();
			//alert("relocated!");
		}
		if (INIT_mapType) {
			this.setMapType(INIT_mapType);
			INIT_mapType = false;
		}
		if (INIT_mapState) {
			this.maximizeMap(true);
			INIT_mapState=false;
		}
		var that = this;

		// Beim Verlassen der Seite sollen vorher alle eigenschaften dieser Ansicht in den Pagestate
		// gesichert werden:

		addUnloadEvent(function(){
			that.pageState.setZoom(that.map.getZoom());
			that.pageState.setPosition(that.map.getCenter());
			that.pageState.setMapType(that.currentMapType);
			that.pageState.setPage(that.currentPage);
			that.pageState.setOrderField(DO_sortType);
			that.pageState.setOrderDir(DO_sortDirection);
			that.pageState.setPageType(that.displayMode);
			that.pageState.setMapState(that.mapExpanded);
			that.pageState.update();
		});
		addUnloadEvent(GUnload);
	}
}
