var map = null;
var geocoder = null;

function showAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(address);
            }
          }
        );
      }
    }


$(document).ready(
		function()
		{
			
			var loginDialog = $("#login").dialog({ 
			    modal: true, 
			    width : '580px',
					height : '320px',
					overlay: { 
			        opacity: 0.5, 
			        background: "black" 
			    } 
			});
			
			$("#login").load("/authentify",function (responseText, textStatus, XMLHttpRequest) {
			 $('.negative').click(function(e){
			   e.preventDefault();
				 $("#login").dialog('destroy');
			 });
			
		
			$("#loginform").submit(function(e){
				e.preventDefault();
				$.post($("#loginform")[0].action, $("#loginform").serializeArray(),function(data){
					document.location.reload();
				});
				
				$("#loginform").ajaxError(function(event, request, settings){
				  $('.error').remove() 
					$(this).append('<div class="error">Utilisateur non reconnu</div>');
				 });
				
			});
			
			});		
		
		var prev = "alt";
		
		$('#agenda tr').each(function(elt){
			if (prev == '' ){ $(this).addClass('alt'); prev = 'alt'}
			else { prev = '';}
			
		})
		
		
				$.localScroll();

		if (jQuery('#map')[0] && GBrowserIsCompatible() ) {
        map = new GMap2(jQuery('#map')[0]);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);
        geocoder = new GClientGeocoder();
        if (document.location.href == "http://www.altadev.com/en/contact-us/contact-1.html"){
					showAddress('100 Bush Street 94104 San Francisco, USA');
      	}
				else{
					showAddress('5, rue Kepler, 75016 Paris france');
				}
			}
			
		});
