function Marker(map, lat, lng, icon) {
	this.initialize(map, lat, lng, icon);
}

Marker.prototype = {
	initialize: function(map, lat, lng, icon){
		this.id = -1;
		this.map = map;
	
		this.point = new GLatLng(lat,lng);

		if (icon == null)
			icon = this.getDefaultIcon();
	
		//this.marker = new GMarker(this.point,{draggable: true, icon:icon});
		this.marker = new GMarker(this.point,{icon:icon});
		
		this.address = "";
		
		this.getDefaultCallBacks();
		
		this.infoTabs = new Array();
		this.selectedTab = 0;
		
		this.additionalInfos = new Array();
	},
	
	/*****************************************************/
	/** Defaults */
	debug: function (){
		return "(" + this.marker.getPoint().lat() + "," + this.marker.getPoint().lng() + ")";
	},
	
	getLatLng: function (lat, lng) {
	},
	
	getCoordinates: function () {
		return this.marker.getPoint().toString();
	},
	
	getDefaultIcon: function() {
		var icon = new GIcon(G_DEFAULT_ICON);
		icon.image = "images/coldmarker.png";
		return icon;
	},
	
	getDefaultCallBacks: function () {
		/*var callbackMouseOver =  GEvent.callbackArgs(this, this.changeIcon, "images/marker.png");
        this.addListener ("mouseover", callbackMouseOver);
        
		var callbackMouseOut =  GEvent.callbackArgs(this, this.changeIcon, "images/coldmarker.png");
        this.addListener ("mouseout", callbackMouseOut);*/
	
        /*var callbackDragStart = GEvent.callbackArgs(this, this.getCoordinates);
        this.addListener ("dragstart", callbackDragStart);
        
        var callbackDragEnd = GEvent.callbackArgs(this, this.getCoordinates);
        this.addListener ("dragend", callbackDragEnd);
        
        var callbackBdlClick = GEvent.callbackArgs(this.map, Map.prototype.removeMarker, this);
        this.addListener("dblclick", callbackBdlClick);*/
        
        var callbackClick = GEvent.callbackArgs(this.map, Map.prototype.setCenter, this.marker.getPoint().lat(), this.marker.getPoint().lng());
        this.addListener("click", callbackClick);
	},
	
	/*****************************************************/
	/** Methods */
	addListener: function (event, callback) {
		GEvent.addListener(this.marker, event, callback);
	},
	
	getAddress: function () {
		return this.address;
	},
	
	addInfoWindowTabsHtml: function (tabs, mode, options) {
		this.editable = false;
		if (options != null && options["selectedTab"] != "null"){
			this.selectedTab = options["selectedTab"];
		}
		if (options != null && options["editable"] != "null"){
			this.editable = options["editable"];
		}
	
		var tabIndex=0;
		for (var label in tabs){
			if (this.editable)
				var tabContent = this._createEditableInfoTabHtmlContent(tabIndex, label, tabs[label]);
			else var tabContent = this._createInfoTabHtmlContent(tabIndex, label, tabs[label]);
			this.infoTabs.push(new GInfoWindowTab(label, tabContent));
			tabIndex++;
		};
		switch(mode){
			case 1 : 
				this.marker.bindInfoWindowTabsHtml(this.infoTabs, options);
			break;
			case 2 : 
				this.marker.bindInfoWindowTabsHtml(this.infoTabs, options);
				this.marker.openInfoWindowTabsHtml(this.infoTabs, options);
			break;
			default :
				this.marker.openInfoWindowTabsHtml(this.infoTabs, options);
			break;
		}
	},
	
	editInfoWindowTabsHtml: function(tabIndex, label, content) {
		var tabContent  = this._createEditableInfoTabHtmlContent(tabIndex, label, content, "edit");

		this.infoTabs[tabIndex] = new GInfoWindowTab(label, tabContent);
		this.marker.bindInfoWindowTabsHtml(this.infoTabs, { "selectedTab" : tabIndex });
		this.marker.openInfoWindowTabsHtml(this.infoTabs, { "selectedTab" : tabIndex });
	},
	
	saveInfoWindowTabsHtml: function(tabIndex, label, content) {
		var tabContent  = this._createEditableInfoTabHtmlContent(tabIndex, label, content);
		
		this.infoTabs[tabIndex] = new GInfoWindowTab(label, tabContent);
		this.marker.bindInfoWindowTabsHtml(this.infoTabs, { "selectedTab" : tabIndex });
		this.marker.openInfoWindowTabsHtml(this.infoTabs, { "selectedTab" : tabIndex });
	},
	
	_createEditableInfoTabHtmlContent: function (tabIndex, label, tabContent, mode) {
		var editableTabContent = "<script>";
		editableTabContent += "var map = getMap('" + this.map.containerId + "');";
		editableTabContent += "var marker = map.getMarker('" + this.id + "');";
		
		if (mode == "edit") {
			editableTabContent += "var scriptPath = \"scripts/FCKeditor/\";";
			editableTabContent += "var oFCKeditor = new FCKeditor('textarea-" + label + "');";
	        editableTabContent += "oFCKeditor.BasePath = scriptPath;";
	        
	        editableTabContent += "oFCKeditor.Config[\"CustomConfigurationsPath\"] = \"../GooglePart/google.config.js\";";
	        editableTabContent += "oFCKeditor.Width = 550;";
			editableTabContent += "oFCKeditor.Height = 400;";
			
	        editableTabContent += "oFCKeditor.ToolbarSet  = \"Google\";";
	        editableTabContent += "oFCKeditor.Height = 200;";
	        editableTabContent += "oFCKeditor.ReplaceTextarea();";
		}
		
		editableTabContent += "</script>";
		
		if (mode == "edit") {
			editableTabContent += "<textarea id=\"textarea-" + label + "\">" + tabContent.replace(/&/, "&amp;") + "</textarea><br/>";
		} else {
			editableTabContent += "<div id=\"div-" + label + "\">" + tabContent + "</div>";
		}
		
		editableTabContent += "<div>";
		if (mode == "edit") {
			editableTabContent += "<a href=\"#\" onclick=\"marker.saveInfoWindowTabsHtml(" + tabIndex + ",'" + label + "', FCKeditorAPI.GetInstance('textarea-" + label + "').GetXHTML(true));\">Enregistrer</a>";
		} else {
			editableTabContent += "<a \"href=#\" onclick=\"marker.editInfoWindowTabsHtml(" + tabIndex + ",'" + label + "',$('div-" + label + "').innerHTML);\">Modifier</a> ";
			editableTabContent += "<a \"href=#\" onclick=\"map.removeMarker(marker)\">Supprimer</a>";
		}
		editableTabContent += "</div>";
		
		return editableTabContent;
	},
	
	_createInfoTabHtmlContent: function (tabIndex, label, tabContent) {
		var editableTabContent = "";
		
		editableTabContent += "<div id=\"div-" + label + "\">" + tabContent + "</div>";
		
		return editableTabContent;
	},
	
	changeIcon: function (url){
		this.marker.setImage(url);
	},
	
	
	/** Additional Infos */
	addInfo: function (key, value){
		this.additionalInfos[key] = value;
	},
	
	getInfo: function (key) {
		return this.additionalInfos[key];
	}
}
