// Class Parking
function Parking(id, lat, lon, name, sname, key, free) {
	this.id = id;
	this.name = name;
	this.sname = sname;
	this.key = key;
	if (isNaN(free)) {
		this.picname = free;
		this.free = free;
		if (free=='---') this.free = 'n/a';
	} else {
		this.picname = '00'+free;
		this.picname = this.picname.substring(this.picname.length-3);
		this.free = free;
	}
	this.active = true;
	var icon = new GIcon(this.baseIcon);
	icon.image = "/poi/icons/p_active/"+this.picname+".png";
	this.point = new GLatLng(lat, lon);
    this.marker = new PdMarker(this.point, icon);
	this.marker.setTooltip(this.getTooltipHtml());
	if ( this.sname != '' ) 
	{
		GEvent.bind(this.marker, "click", this, this.jumpToParking);
	}
	this.marker.setOpacity(80);
	GEvent.bind(this.marker, "mouseover", this, this.hover);
	GEvent.bind(this.marker, "mouseout", this, this.hoverout);
	this.map.addOverlay(this.marker);
	
}

	Parking.prototype.getTooltipHtml = function getTooltipHtml() {
		var width = 18;
		if ( this.key == "P+R" )
			width = 23;
			
		var result = "<table><tr class=\"head\"><td><nobr><img src=\"/poi/pics/p_"+this.key+".png\" height=\"15\" width=\""+width+"\"/>&nbsp;"+this.name+"</nobr></td></tr>";
		if (this.key == 'P09') {
			result += "<tr><td><nobr>Status: "+this.free+"</nobr></td></tr></table>";
		} else {
			result += "<tr><td><nobr>Frei: "+this.free+"</nobr></td></tr></table>";
		}
		return result;
	}
	
	Parking.prototype.activate = function activate() {
		if (!this.active) {
			this.marker.setImage("/poi/icons/p_active/"+this.picname+".png"); 
			this.active = true;
		}
	}
	
	Parking.prototype.deactivate = function deactivate() {
		if (this.active) {
			this.marker.setImage("/poi/icons/p_inactive/"+this.picname+".png"); 
			this.active = false;
		}
	}
	
	Parking.prototype.highlight = function highlight(action) {
		this.marker.blink(action, 500);
	}
	
	Parking.prototype.hover = function() {
		return;
	}
	
	Parking.prototype.hoverout = function() {
		return;
	}
	
	Parking.prototype.jumpToParking = function() {
		open('/parkhaus.asp?ph='+this.sname, '_self');
	}

// Class Poi
function Poi(poiId, lat, lon, pic, name, detailurl, activeParkings, inactiveParkings) {
	this.poiId = poiId;
	this.name = name;
	this.inactiveParkings = inactiveParkings;
	this.activeParkings = activeParkings;
	this.directurl = detailurl;
	this.lon = lon;
	this.lat = lat;
	var icon = new GIcon(this.baseIcon);
	icon.image = "/poi/icons/"+pic;
    this.marker = new PdMarker(new GLatLng(lat, lon), icon);
	GEvent.bind(this.marker, "mouseover", this, this.hover);
	GEvent.bind(this.marker, "mouseout", this, this.hoverout);
	
	this.marker.setTooltip(this.getTooltipHtml());
	this.isNew = true;
	
}

	Poi.prototype.show = function show() {
		if (this.isNew) {
			this.map.addOverlay(this.marker);
			this.isNew = false;
		}
		this.marker.display(true);
	}
	
	Poi.prototype.hide = function hide() {
		this.marker.display(false);
	}
	
	Poi.prototype.getTooltipHtml = function getTooltipHtml() {
		var result = "<table><tr class=\"head\"><td><img src=\"/pics/dot.gif\" width=\"100\" height=\"1\"/><br/>"+this.name+"</td></tr><tr><td>";
		if (this.directurl != '') {
			result += "<a href=\"http://"+this.directurl+"\" target=\"_blank\">"+this.directurl+"</a></td></tr><tr><td>";
		}
		for (var i = 0; i < this.activeParkings.length; ++i) {
			if ( this.parkings[this.activeParkings[i]].sname != '' ) 
			{
				result += '<img src=\"pics/p.png\" height=\"12\" width=\"12\" style=\"margin-bottom: -2px;\"/>&nbsp;<a href="/parkhaus.asp?ph='+this.parkings[this.activeParkings[i]].sname+'" onmouseover="toggleParkingHighlight(\''+this.activeParkings[i]+'\', true);" onmouseout="toggleParkingHighlight(\''+this.activeParkings[i]+'\', false);"><nobr>'+this.parkings[this.activeParkings[i]].name+'</nobr></a><br/>';
			}
			else 
			{
				result += '<img src=\"pics/p.png\" height=\"12\" width=\"12\"/>&nbsp;<nobr>'+this.parkings[this.activeParkings[i]].name+'</nobr><br/>';
			}
			
		}
		result += "</td></tr></table>";
		return result;
	}
	
	Poi.prototype.hover = function() {
		for (var i = 0; i < this.inactiveParkings.length; ++i) {
			this.parkings[this.inactiveParkings[i]].deactivate();
		}
		for (var i = 0; i < this.activeParkings.length; ++i) {
			this.parkings[this.activeParkings[i]].activate();
		}
	}
	
	Poi.prototype.hoverout = function() {
		var cmd = '';
		for (var i = 0; i < this.inactiveParkings.length; ++i) {
			cmd += 'activateParking(\''+this.parkings[this.inactiveParkings[i]].id+'\');';
		}
		window.setTimeout(cmd, 1500);
	}
	
// Class PoiList
function PoiCollection() {
	this.list = new Array();
}
	
	PoiCollection.prototype.addPoi = function addPoi(poi) {
		this.list.push(poi);
	}

	PoiCollection.prototype.show = function show(poiId) {
		for (var i = 0; i < this.list.length; ++i) {
			if (poiId==null || poiId == this.list[i].poiId) {
				this.list[i].show();
			}
		}
	}
	
	PoiCollection.prototype.hide = function hide() {
		for (var i = 0; i < this.list.length; ++i) {
			this.list[i].hide();
		}
	}
