function initJMapFunctionnality()
{
	
	$.getScript("/lb/get_script.php?obj=system/google_map_api",function() {

		$('div.carte').css({
			background: '#fff',
			border: '2px solid #000'
		});
		$('a.show_map').click(function(e) {
			var tmp_id = $(this).attr('id');
			var map_id = 'map'+tmp_id.replace(/maplink/,'');
			var gps_id = 'gps'+tmp_id.replace(/maplink/,'');
			var ac_id = 'account'+tmp_id.replace(/maplink/,'');
			var gpsN = $('#'+gps_id+' span.gpsn').text();
			var gpsE = $('#'+gps_id+' span.gpse').text();
			var str_markerText = '<div class="jmap_marker_titre">'+$('#'+ac_id+' div.barre_titre').html()+'</div>';
			var address_html = $('#'+ac_id+' p.est_details').html();
			var address_txt = $('#'+ac_id+' p.est_details').text();
			str_markerText += '<div class="est_details">'+address_html.replace(/- Tel\.:/,'<br />Tel.:')+'</div>';
			$('<div class="right_panel"'
				+' style="width:0px; height:500px; float: right; overflow:hidden;">'
				+'<div class="direction_form" style="height: 56px;">'
					+'<button id="viewDirection" value="Go!" style="float: right">Go!</button>'
					+'<label for="fromAddress">D&eacute;part :</label>'
					+'<input type="text" name="fromAddress" id="fromAddress" /><br />'
					+'<label for="toAddress">Destination :</label>'
					+'<input type="text" name="toAddress" id="toAddress" value="'+address_txt.replace(/\.\s+- Tel\.:.*/,'')+'" />'
				+'</div>'
				+'<div class="txtDirection" id="txtDirection'+map_id+'" style="height: 442px; overflow: auto;">'
				+'<div class="waiting_action">'
				+'Veuillez indiquer une adresse de d&eacute;part ci-dessus pour calculer l\'itin&eacute;raire.</div></div>'
				+'</div>').insertAfter('#'+map_id+' div.map_toolbar');
			//$('#'+map_id).css('display','block').jmap('init', {mapCenter:[55.958858,-3.162302]});
			//alert(document.getElementById('guilayout').scrollHeight+' - '+document.getElementsByTagName('body')[0].scrollTop);
			var offset = $(this).offset();
			//alert(offset.top);
			var scHeight = document.getElementById('guilayout').scrollHeight;
			if((offset.top+500)>scHeight || (offset.top-250)>scHeight) $('#'+map_id).css('top',(scHeight-550)+'px');
			else $('#'+map_id).css('top',(offset.top-250)+'px')
			$('#'+map_id).css('display','block').css({marginLeft: '-250px'});
			//$('#'+map_id+' .map_toolbar').append('<a href="javascript:void(0)" class="maptype_switcher">M</a>');
			$('#'+map_id+' .map_toolbar').append('<a href="javascript:void(0);" class="viewDirectionPanel">'
				+'Calculer un itin&eacute;raire'
				+'</a>');
			$('#gmap'+tmp_id.replace(/maplink/,'')).width(500).height(500).css('float','left').jmap('init',
				{mapEnableType:true,mapCenter:[gpsN,gpsE],mapType:'hybrid',mapZoom: 12,mapShowjMapIcon:false},
				function(el, options){
					if($.jmap.GDir!=undefined || $.jmap.GDir!=null)
					{
						$.jmap.GDir.clear();
						$.jmap.GDir = undefined;
					}
					$(el).jmap('addMarker', {pointLatLng:[gpsN,gpsE],pointHTML: str_markerText});
					$('#'+map_id+' .right_panel button#viewDirection').click(function() {
						$('#'+map_id+' #txtDirection'+map_id).empty();
						$(el).jmap("searchDirections",{
							fromAddress: $('#'+map_id+' .direction_form input#fromAddress').val(),
							toAddress: $('#'+map_id+' .direction_form input#toAddress').val(),
							toGPSN: gpsN,
							toGPSE: gpsE,
							directionsPanel: 'txtDirection'+map_id
						});
					});
				}
			);
			$('#'+map_id+' .map_toolbar a.viewDirectionPanel').toggle(function() {
				var nwidth = '300px';
				if($.browser.msie && parseInt($.browser.version) == 6)
				{
					nwidth = '298px';
				}
				$(this).html('Fermer le calcul d\' itin&eacute;raire');
				var w = $('#'+map_id).width();
				var mL = $('#'+map_id).css('margin-left');
				mL=parseInt(mL.replace(/px/,''));
				$('#'+map_id).animate({
					marginLeft: (mL-250)+'px',
					width: (w+300)+'px'
				},1000,'easein', function() {
					$('#'+map_id+' div.right_panel').animate({width: nwidth},1000,'easein');
				});
			},function() {
				$(this).html('Calculer un itin&eacute;raire');
				var w = $('#'+map_id).width();
				var mL = $('#'+map_id).css('margin-left');
				$('#'+map_id+' div.right_panel').animate({width: '0px'},{duration:1000,queue:false},'easein');
				mL=parseInt(mL.replace(/px/,''));
				$('#'+map_id).animate({
					marginLeft: (mL+250)+'px',
					width: (w-300)+'px'
				},1000,'easein');
			});
			
			$('#'+map_id+' .map_titlebar a').click(function() {
				var mL = $('#'+map_id).css('margin-left');
				var w = $('#'+map_id).width();
				mL=parseInt(mL.replace(/px/,''));
				$('#gmap'+tmp_id.replace(/maplink/,'')).empty();
				$('#'+map_id+' .map_toolbar').empty();
				$('#'+map_id+' .right_panel').empty().remove();
				$('#'+map_id).css(
					'margin-left',(mL+250)+'px').width(w-300);
				$('#'+map_id).css('display','none');
			});
		});
	});
}



$(document).ready(
	function () {
		initJMapFunctionnality();
	}
);
