//--------------------------------------------------------------------------
// The OberonMap class
//--------------------------------------------------------------------------
OMap.prototype._map;
OMap.prototype._type;
OMap.prototype._overlays;

function OMap(sType) {
	if (sType == '') {
		sType = generalMapType;
	}
	this._type = sType;
	this._overlays = new Array();
}

OMap.prototype.getType = function() {
	return this._type;
}

OMap.prototype.initMap = function(container_id){
	this[this._type+'_initMap'](container_id);
}

OMap.prototype.initCenter = function(latlng, zoom, maptype) {
	if (latlng == undefined){
		latlng = new OLatLng(51.455718,3.579826,this._type);
	}
	if (zoom == undefined){
		zoom = 5;
	}
	if (maptype == undefined){
		maptype = 'h';
	}
	this[this._type+"_initCenter"](latlng, zoom, maptype);
}

OMap.prototype.unLoadMap = function(){
	this[this._type+"_unLoadMap"]();
}


OMap.prototype.changeMap = function(type) {
	this[this._type+"_fillProperties"]();
	this[this._type+"_changeMap"]();
	this[this._type+"_setMapType"]();
}

OMap.prototype.setCenter = function(latlng) {
	this[this._type+"_setCenter"](latlng);
}

OMap.prototype.setCenterAndZoom = function(latlng, zoomlevel) {
	this[this._type+"_setCenterAndZoom"](latlng, zoomlevel);
}

OMap.prototype.getCenter = function(){
	return this[this._type+"_getCenter"]();
}

OMap.prototype.getBounds = function(){
	return this[this._type+"_getBounds"]();
}

OMap.prototype.setZoom = function(new_zoom){
	this[this._type+"_setZoom"](new_zoom);
}

OMap.prototype.setCenterAndZoomFromPoints = function(points, default_level){
	this[this._type+"_setCenterAndZoomFromPoints"](points, default_level);
}

OMap.prototype.getZoom = function(){
	return this[this._type+"_getZoom"]();
}

OMap.prototype.panTo = function(point){
	this[this._type+"_panTo"](point);
}

OMap.prototype.addOverlay = function(overlay){
	this._overlays.push(overlay);
	this[this._type+"_addOverlay"](overlay);
}

OMap.prototype.removeOverlay = function(overlay){
	for (var i=0; i<this._overlays.length; i++){
		if (overlay==this._overlays[i]){
			break;
		}
	}
	this._overlays.splice(i,1);
	this[this._type+"_removeOverlay"](overlay);
}

OLatLng.prototype._latlng;
OLatLng.prototype._type;

function OLatLng(lat, lng, sType){
	if (sType==undefined){
		this._type = generalMapType;
	} else {
		this._type = sType;
	}
	this._latlng = this[this._type+"_LatLng"](lat,lng);
}

OLatLng.prototype.lat = function(){
	return this[this._type+"_lat"]();
}

OLatLng.prototype.lng = function(){
	return this[this._type+"_lng"]();
}

OLatLngBounds.prototype._latlngbounds;
OLatLngBounds.prototype._type;

function OLatLngBounds(point1, point2, type){
	if (type==undefined){
		this._type = generalMapType;
	} else {
		this._type = sType;
	}
	this._latlngbounds = this[this._type+"_LatLngBounds"](point1,point2);
}

OPolygon.prototype._polygon;
OPolygon.prototype._type;

function OPolygon(points,type){
	if (type==undefined){
		this._type = generalMapType;
	} else {
		this._type = sType;
	}
	this._polygon = this[this._type+"_Polygon"](points);
}

OPolygon.prototype.setPoints = function(points,curmap){
	this[this._type+"_setPoints"](points,curmap);
}

OPolygon.prototype.show = function(){
	this[this._type+"_show"]();
}

OPolygon.prototype.hide = function(){
	this[this._type+"_hide"]();
}

OMarker.prototype._marker;
OMarker.prototype._type;
OMarker.prototype._title;
OMarker.prototype._description;
OMarker.prototype._image;
OMarker.prototype._linktitle;
OMarker.prototype._link;
OMarker.prototype._logo;
OMarker.prototype._icon;
OMarker.prototype._template;
OMarker.prototype._html;

function OMarker(point, icon, template, title, description, image, linktitle, link, type, logo){
	if (type==undefined){
		this._type = generalMapType;
	} else {
		this._type = type;
	}
	this._marker = this[this._type+"_Marker"](point, icon);
	this.setTitle(title);
	this.setDescription(description);
	this.setImage(image);
	this.setLinktitle(linktitle);
	this.setLink(link);
	this.setIcon(icon);
	this.setTemplate(template);
	this.setLogo(logo);
}

OMarker.prototype.setTitle = function(title){
	if (title==undefined){
		this._title = '';
	} else {
		this._title = title;
	}
	this[this._type+"_setTitle"](this._title);
	if (this._template!=undefined){
		this.setTemplate(this._template);
	}
}

OMarker.prototype.setDescription = function(description){
	if (description==undefined){
		this._descriptione = '';
	} else {
		this._description = description;
	}
	this[this._type+"_setDescription"](this._description);
	if (this._template!=undefined){
		this.setTemplate(this._template);
	}
}

OMarker.prototype.setImage = function(image){
	if (image==undefined){
		this._imagee = '';
	} else {
		this._image = image;
	}
	this[this._type+"_setImage"](this._image);
	if (this._template!=undefined){
		this.setTemplate(this._template);
	}
}

OMarker.prototype.setLinktitle = function(linktitle){
	if (linktitle==undefined){
		this._linktitle = '';
	} else {
		this._linktitle = linktitle;
	}
	this[this._type+"_setLinktitle"](this._linktitle);
	if (this._template!=undefined){
		this.setTemplate(this._template);
	}
}

OMarker.prototype.setLink = function(link){
	if (link==undefined){
		this._link = '';
	} else {
		this._link = link;
	}
	this[this._type+"_setLink"](this._link);
	if (this._template!=undefined){
		this.setTemplate(this._template);
	}
}

OMarker.prototype.setIcon = function(icon){
	if ((icon!=undefined) && (icon!=null)){
		this._icon = icon;
		this[this._type+"_setIcon"](this._icon);
	}
}

OMarker.prototype.setLogo = function(logo){
	if ((logo!=undefined) && (logo!=null)){
		this._logo = logo;
		this[this._type+"_setLogo"](this._logo);
	}
}
/**
 * setTemplate
 * Set the template used to create the contents of the balloon (only used with google). To use one of the
 * above mentioned properties use [!title!] for example. This function is automaticly called if you change
 * one of the properties and the template is defined. The function fills the _html property.
 *
 * @param    template    template to be used
 */

OMarker.prototype.setTemplate = function(template){
	if (template!=undefined){
		this._template = template;
		var chunks = template.split('!]');
		this._html = '';
		for (var i=0; i<chunks.length; i++){
			 if (i<chunks.length-1){
			 	var subchunks = chunks[i].split('[!');
			 	this._html += subchunks[0];
			 	switch(subchunks[1]){
			 		case 'title':
			 			this._html += this._title;
			 			break;
			 		case 'description':
			 			this._html += this._description;
			 			break;
			 		case 'image':
			 			this._html += this._image;
			 			break;
			 		case 'linktitle':
			 			this._html += this._linktitle;
			 			break;
			 		case 'link':
			 			this._html += this._link;
			 			break;
			 		case 'logo':
			 			this._html += this._logo;
			 			break;
			 	}
			} else {
				this._html += chunks[i];
			}
		}
		this[this._type+"_useHTML"](this._html);
	}
}

OMarker.prototype.getLatLng = function(){
	return this[this._type+"_getLatLng"]();
}

OMarker.prototype.setLatLng = function(point){
	this[this._type+"_setLatLng"](point);
}

OMarker.prototype.lat = function(){
	return this.getLatLng().lat();
}

OMarker.prototype.lng = function(){
	return this.getLatLng().lng();
}

OMarker.prototype.hide = function(){
	this[this._type+"_hide"]();
}

OMarker.prototype.show = function(){
	this[this._type+"_show"]();
}

OImageIcon.prototype._icon;
OImageIcon.prototype._type;

function OImageIcon(image, offsetX, offsetY, sizeX, sizeY, type, shadow){
	if (type==undefined){
		this._type = generalMapType;
	} else {
		this._type = type;
	}
	this._icon = this[this._type+"_ImageIcon"](image,offsetX,offsetY,sizeX,sizeY,shadow);
}

/**
 * OTextIcon
 * Not yet implemented because google maps does not support this feature. Nice for tag clouds.
 *
 * @param
 */

OTextIcon.prototype._icon;
OTextIcon.prototype._type;

function OTextIcon(){
}

function OEvent(){
}

OEvent.addEvent = function(trigger, event, handler, curmap){
	return this[generalMapType+"_addEvent"](trigger, event, handler, curmap);
}

OEvent.deleteEvent = function(trigger,event,handler){
	this[generalMapType+"_deleteEvent"](trigger, event, handler);
}

OGeocoder.prototype._type;
OGeocoder.prototype._geocoder;
OGeocoder.prototype._omap;

function OGeocoder(amap,type){
	if (type==undefined){
		this._type = generalMapType;
	} else {
		this._type = type;
	}
	this._geocoder = this[this._type+"_Geocoder"](amap);
}

OGeocoder.prototype.findLocation = function(address,handler){
	this[this._type+"_findLocation"](address,handler);
}