$(document).ready(function()
{
	$('body').bind('unload',GUnload);
	
	/*
	$('input').each(function(){
		if ($(this).attr('type')=='submit' && $(this).attr('class')=='fondo')
		{
			target=$(this);
		}
	});
    */
    temp = window.location.href.split('&');
	if (temp.length>1 && temp[1].substr(0,10) == 'id_article' && $('div#portfolio').length>0)
	{   
		href_article = temp[1];
		if (GBrowserIsCompatible()) {
		   $('div#portfolio').before('<div id="map">carte google</div>');
		   var map = new GMap2(document.getElementById("map"));
	       map.setCenter(new GLatLng(-15.334076909372742,166.95098876953125), 8);
		   map.setMapType(G_SATELLITE_MAP); 
		   map.addControl(new GSmallMapControl());
		   map.addControl(new GMapTypeControl()); 
		   GEvent.addListener(map, "click", function(overlay,point) {	
			   map.clearOverlays();
			   map.addOverlay(new GMarker(point)); 
		   	   url = '/plugins/geoloc/pos.php?' + href_article + '&lat=' + point.lat() + '&lng=' + point.lng();
			   $.get(url);

	       });
		   url = '/plugins/geoloc/pos.php?' + href_article;
		   $.get(url,function(data){
			   temp = data.split('|');
			   if (temp[0]!=0)
			   {
			   		map.clearOverlays();
					point = new GLatLng(temp[0],temp[1]);
			   		map.addOverlay(new GMarker(point));
			        map.setCenter(point);
			   }
		   });
	    }
     } else {
	 	// FRONT
	    if ($('.geoloc_onemap').length>0 && GBrowserIsCompatible())
		{
			$('.geoloc_onemap').each(function(){

			var map = new GMap2(document.getElementById($(this).attr('id')));
		    map.setCenter(new GLatLng(-15.334076909372742,166.95098876953125), 11);
			map.setMapType(G_HYBRID_MAP); 
			map.addControl(new GSmallMapControl());
		   	url = '/plugins/geoloc/pos.php?id_article=' + $(this).attr('id').substr(3);
		    target = $(this);
			$.get(url,function(data){
				temp = data.split('|');
				if (temp[0]!=0)
				{
					map.clearOverlays();
					point = new GLatLng(temp[0],temp[1]);
					map.addOverlay(new GMarker(point));
					map.setCenter(point);
//					$(target).after('<p>gearth</p>');
				}
			});			
			});
		}
	 } 
});