

function initialize() {
	
	var map, icon;
	
	var coordUser = $("#map_home").attr('class');
	var c = coordUser.split(' ');
	var latitude = c[1] != "" ? c[1] : null;
	var longitude = c[2] != "" ? c[2] : null;
	
	zoom = latitude ? 9 : 7;
	lat = latitude ? latitude : '50.6398882';
	lng = longitude ? longitude : '4.6735162';
	
	icon = new GIcon();
	icon.image = "/images/arrow_map.png";
	icon.iconSize = new GSize(54, 44);
	icon.iconAnchor = new GPoint(16, 44);
	
	map = new google.maps.Map2(document.getElementById("map_home"));
	map.setUIToDefault();
	
	map.setCenter(new google.maps.LatLng(lat, lng), zoom);

	$.getJSON("/user/getCoordinateSaler",function(data){
		$.each(data,function(i, n) {
			var point = new GLatLng(n.x, n.y);
			var marker = new GMarker(point, icon);
			map.addOverlay(marker);
			
			var html = '<div style="height:32px;padding-bottom:10px;margin-bottom:10px;border-bottom:1px solid #C6C6C6;"><img src="/uploads/avatars/thumbs/'+n.saler.id+'.jpg" style="display:block;float:left;" width="32" height="32" /><div style="padding-left:10px;float:left;"><h4 style="text-transform:uppercase;font-size:11px;">'+n.saler.eshop_name+'</h4><p style="font-size:11px;">Vendeur: <strong><a href="/user?id='+n.saler.id+'" style="text-decoration:none;">'+n.saler.username+'</a></strong></p></div></div>';
			html += '<div class="product" style="clear:both;overflow:hidden;width:218px;height:53px;overflow:hidden;"><div id="product-'+n.product[0].subcategoryId+'" style="width:48px;height:48px;float:left;"></div><div style="float:left;padding-left:10px;width:160px;font-size:11px;line-height:1.4em;"><h4>'+n.product[0].subcategoryName+'</h4><div>Quantité : <strong>'+n.product[0].quantityRemaining+' '+n.product[0].conditionning+'</strong><br />Prix : <strong>'+n.product[0].price+'&euro;/'+n.product[0].conditionning+'</strong></div></div></div>';
			if (n.product[1]) {
				html += '<div class="product" style="clear:both;overflow:hidden;margin-top:10px;width:218px;height:53px;overflow:hidden;"><div id="product-'+n.product[1].subcategoryId+'" style="width:48px;height:48px;float:left;"></div><div style="float:left;padding-left:10px;width:160px;font-size:11px;line-height:1.4em;"><h4>'+n.product[1].subcategoryName+'</h4><div>Quantité : <strong>'+n.product[1].quantityRemaining+' '+n.product[1].conditionning+'</strong><br />Prix : <strong>'+n.product[1].price+'&euro;/'+n.product[1].conditionning+'</strong></div></div></div>';
			}
			
			GEvent.addListener(marker,"click", function() {
				map.openInfoWindowHtml(marker.getLatLng(), html, {pixelOffset: new GSize(0,-28)});
			});
		});
	});
	
}

google.load("maps", "2.x");
google.setOnLoadCallback(initialize);



