function pRestoMap(div)
	{
	this.icon=null;
	this.div = document.getElementById(div);
	this.map=null;
	this.gPoints=[];
	this.params=null;
	this.init=function()
		{
		if(GBrowserIsCompatible())
			{
			if(this.div)
				{
				try
					{
					this.div.style.display='block';
					this.map = new GMap2(this.div);
					this.map.addControl(new GLargeMapControl());
					this.map.addControl(new GMapTypeControl());
					var geoCoder = new GClientGeocoder();
					this.params=this.div.getAttribute('title').split('|');
					this.initIcons();
					this.div.setAttribute('title','');
					geoCoder.getLatLng(this.params[0], this.handler(this, this.setAnchor));
					}
				catch(e)
					{
					this.div.style.display='none';
					}
				}
			}
		};

	this.initIcons=function()
		{
		var domain='cdn.planete-chr.com';//this.params[1].replace(new RegExp('http://(.+)/(.*)'),'$1','i');
		this.iconhoteresto = new GIcon();
		this.iconhoteresto.image = 'http://'+domain+'/images/icons/gmap.png';
		this.iconhoteresto.shadow = 'http://'+domain+'/images/icons/gmap_shadow.png';
		this.iconhoteresto.iconSize = new GSize(40, 64);
		this.iconhoteresto.shadowSize = new GSize(64, 64);
		this.iconhoteresto.iconAnchor = new GPoint(0, 64);
		this.iconhotel = new GIcon();
		this.iconhotel.image = 'http://'+domain+'/images/icons/gmap_hotel.png';
		this.iconhotel.shadow = 'http://'+domain+'/images/icons/gmap_shadow.png';
		this.iconhotel.iconSize = new GSize(40, 64);
		this.iconhotel.shadowSize = new GSize(64, 64);
		this.iconhotel.iconAnchor = new GPoint(0, 64);
		this.iconresto = new GIcon();
		this.iconresto.image = 'http://'+domain+'/images/icons/gmap_restaurant.png';
		this.iconresto.shadow = 'http://'+domain+'/images/icons/gmap_shadow.png';
		this.iconresto.iconSize = new GSize(40, 64);
		this.iconresto.shadowSize = new GSize(64, 64);
		this.iconresto.iconAnchor = new GPoint(0, 64);
		};

	this.setAnchor=function (point)
		{
		if(point)
			{
			try
				{
				this.map.setCenter(point, 13);
				place_points=this.handler(this, this.placePoints);
				for(var i=1; i<this.params.length; i++)
					{
					var script=document.createElement('script');
					script.setAttribute('src',this.params[i]);
					document.body.appendChild(script);
					}
				}
			catch(e)
				{
				this.div.style.display='none';
				}
			}
		else
			{
			this.div.style.display='none';
			}
		};

	this.placePoints=function(points)
		{
		if(points.entries&&points.entries.entry)
			{
			for(var i=0; points.entries.entry[i]; i++)
				{
				if(points.entries.entry[i].lng!=0&&points.entries.entry[i].lat!=0)
					{
					var point=new GLatLng(points.entries.entry[i].lat, points.entries.entry[i].lng);
					if(points.entries.entry[i].restaurant&&points.entries.entry[i].hotel)
						var marker=new GMarker(point, this.iconhoteresto);
					else if(points.entries.entry[i].hotel)
						var marker=new GMarker(point, this.iconhotel);
					else if(points.entries.entry[i].restaurant)
						var marker=new GMarker(point, this.iconresto);
					marker.hotrestoinfo=points.entries.entry[i];
					marker.prm=this;
					marker.hotrestofunction=function()
						{
						this.prm.map.openInfoWindowHtml(this.getPoint(),'<strong>'+(charset=='UTF-8'?this.hotrestoinfo.name:utf8_decode(this.hotrestoinfo.name))+'</strong><br />'+this.hotrestoinfo.postal+' '+(charset=='UTF-8'?this.hotrestoinfo.city:utf8_decode(this.hotrestoinfo.city))+'<br />Tel.:&nbsp;'+this.hotrestoinfo.phone+'<br /><a href="'+this.hotrestoinfo.link+'" title="Lire notre fiche d&#233;taill&#233;e">Plus d\'infos</a>');
						};
					GEvent.addListener(marker, "click", marker.hotrestofunction);
					this.map.addOverlay(marker);
					this.gPoints.push(point);
					}
				}
			this.fitMap(this.gPoints);
			}
		};


	this.handler=function(obj,method)
		{
		var fx = method;
		return function () { return fx.apply(obj, arguments); }
		};

	this.uninit=function()
		{
		this.div=null;
		this.map=null;
		geoCoder=null;
		try
			{
			GUnload();
			}
		catch(e)
			{ }
		};

	this.fitMap=function(points)
		{
		var bounds = new GLatLngBounds();
		for (var i=0; i< points.length; i++)
			{
			bounds.extend(points[i]);
			}
		this.map.setZoom(this.map.getBoundsZoomLevel(bounds));
		this.map.setCenter(bounds.getCenter());
		}
	}

function utf8_decode(utftext)
	{
	if(utftext)
		{
		var string = "";
		var i = 0; var c = 0; var c2 = 0; var c3 = 0;
		while ( i < utftext.length )
			{
			c = utftext.charCodeAt(i);
			if (c < 128)
				{
				string += String.fromCharCode(c);
				i++;
				}
			else if((c > 191) && (c < 224))
				{
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
				}
			else
				{
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
				}
			}
			return string;
		}
	else
		return "";
	}

var charset=(window.charset||window.document.charset||window.document.characterSet).toUpperCase();
var prm=new pRestoMap('map');
if(window.addEventListener)
	{
	window.addEventListener('load', prm.handler(prm, prm.init), false);
	window.addEventListener('unload', prm.handler(prm, prm.uninit), false);
	}
else if(window.attachEvent)
	{
	window.attachEvent('onload', prm.handler(prm, prm.init), false);
	window.attachEvent('onunload', prm.handler(prm, prm.uninit), false);
	}
