
    function CreasensoControl() {
    }
    CreasensoControl.prototype = new GControl();

    CreasensoControl.prototype.initialize = function(map) {
      var container = document.createElement("div");
      
      var printDiv = document.createElement("div");
      this.setButtonStyle_(printDiv,'p1');
      container.appendChild(printDiv);
      printDiv.appendChild(document.createTextNode("Print"));
      GEvent.addDomListener(printDiv, "click", function() {
     var newadr = $('search').getProperty('value');
     if(newadr=='Tapez ici votre lieu de départ'){newadr='';}
     window.open('http://maps.google.com/maps?f=d&hl=fr&geocode=&saddr='+newadr+'&daddr=21,+Rue+de+Tr%C3%A9vise,+75009+9%C3%A8me+Arrondissement,+Paris,+France','mywindow');
      });
      
      var fromDiv = document.createElement("div");
      this.setButtonStyle_(fromDiv,'p2');
      container.appendChild(fromDiv);
      printDiv.appendChild(document.createTextNode("Location"));
       GEvent.addDomListener(fromDiv, "click", function() {
      enlargeSearch();
      });
      
      var bigDiv = document.createElement("div");
      bigDiv.id="slide";
      this.setButtonStyle_(bigDiv,'p3');
      container.appendChild(bigDiv);
      printDiv.appendChild(document.createTextNode("Big"));
      GEvent.addDomListener(bigDiv, "click", function() {
      enlargeMap();
      });
      
      var zoomInDiv = document.createElement("div");
      this.setButtonStyle_(zoomInDiv,'s1');
      container.appendChild(zoomInDiv);
      zoomInDiv.appendChild(document.createTextNode("Zoom In"));
      GEvent.addDomListener(zoomInDiv, "click", function() {
        map.zoomIn();
      });

      var zoomOutDiv = document.createElement("div");
      this.setButtonStyle_(zoomOutDiv,'s2');
      container.appendChild(zoomOutDiv);
      zoomOutDiv.appendChild(document.createTextNode("Zoom Out"));
      GEvent.addDomListener(zoomOutDiv, "click", function() {
        map.zoomOut();
      });

      map.getContainer().appendChild(container);
      return container;
    }

    // By default, the control will appear in the top left corner of the
    // map with 7 pixels of padding.
    CreasensoControl.prototype.getDefaultPosition = function() {
      return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5, 5));
    }
//maps.google.com/maps?f=q&hl=en&geocode=&q=21+rue+de+trevise+paris&jsv=107&sll=48.828226,2.326806&sspn=0.007077,0.017681&ie=UTF8&ll=48.873804,2.345302&spn=0.007071,0.017681&z=16
    // Sets the proper CSS for the given button element.
    CreasensoControl.prototype.setButtonStyle_ = function(button,s) {

      button.style.textDecoration = "underline";
      button.style.color = "#0000cc";
      button.style.backgroundColor = "white";
      button.style.font = "small Arial";
      button.style.border = "0px solid black";
      button.style.padding = "0px";
      button.style.marginBottom = "0px";
      button.style.textAlign = "center";
      button.style.cursor = "pointer";
      button.style.textIndent = "-7777px";
      button.style.marginBottom = "3px";
      if(s=='s1'){
      button.style.width = "41px";
      button.style.height = "39px";
      button.style.background = "transparent url(../layout/img/map_plus.png) top left no-repeat";
      }
      if(s=='s2'){
      button.style.width = "41px";
      button.style.height = "39px";
      button.style.background = "transparent url(../layout/img/map_minus.png) top left no-repeat";
      }
      if(s=='p1'){
      button.style.width = "41px";
      button.style.height = "39px";
      button.style.background = "transparent url(../layout/img/map_print.png) top left no-repeat";
      }
      if(s=='p2'){
      button.style.width = "41px";
      button.style.height = "39px";
      button.style.background = "transparent url(../layout/img/map_from.png) top left no-repeat";
      button.style.display = "block";
      button.style.position = "relative";
      button.style.zIndex = "8888";
      }
      if(s=='p3'){
      button.style.width = "41px";
      button.style.height = "39px";
      button.style.background = "transparent url(../layout/img/map_big.png) top left no-repeat";
      }

    }
    
   function setDirections(fromAddress) {
      gdir.load("from: " + fromAddress + " to: " +"21 Rue de Trevise, Paris France",
                { "locale": "fr" });
    }
    function onGDirectionsLoad(){ 
    }
    
    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses.");
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed.");
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("Please type your start location.");

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");
	   
	}
	
    var map ;
    function initialize() {
    	
    	//defaul to hidden
    	$('searchbar').setStyles({'visibility':'hidden','width':'0px'});
      
    	if (GBrowserIsCompatible()) {

        map = new GMap2(document.getElementById("gMap"));
        
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
        
         
        var creaIcon = new GIcon();
        map.setCenter(new GLatLng(48.873945,2.34529), 2,G_PHYSICAL_MAP);
        map.addControl(new CreasensoControl());
        creaIcon.iconSize = new GSize(175,72);
        creaIcon.iconAnchor = new GPoint(87, 72);
        creaIcon.image = "http://creasenso.fr/layout/img/map_logo.png";
        markerOptions = { icon:creaIcon };
        latlng = new GLatLng(48.873945,2.34529);
        map.addOverlay(new GMarker(latlng, markerOptions));
      }
      
          $('search').addEvent('focus',function(){
		if($(this).getProperty('value')=='Tapez ici votre lieu de départ'){
			$(this).setProperty('value','');
		}
	});
	
	$('search').addEvent('blur',function(){
		if($(this).getProperty('value')==''){
			$(this).setProperty('value','Tapez ici votre lieu de départ');
		}
	});
	
    }
         
         var enlarge_toggle='0';
         var enlarge_search='0';
         
          function enlargeMap(){
          	enlarge = new Fx.Styles($('gMap'),{duration:400, wait:false,onComplete:function(){if(enlarge_toggle=='0') { $('headline-subline').setStyle('display','block');}else {$('contacts-box').setStyle('visibility','hidden');}map.checkResize();map.panTo(new GLatLng(48.873945,2.34529));}});
          	if(enlarge_toggle=='0') 
          	{
          		$('slide').setStyle('background','transparent url(../layout/img/map_small.png) no-repeat scroll left top');
          		enlarge.start({'height': ['218px','408px']});
          		enlarge_toggle='1';
          		$('headline-subline').setStyle('display','none');
          		
          	}
          	else
          	{	$('contacts-box').setStyle('visibility','visible');
          		$('slide').setStyle('background','transparent url(../layout/img/map_big.png) no-repeat scroll left top');
          		enlarge.start({'height': ['408px','218px']});
          		enlarge_toggle='0';
          	}
          	
      }
      
      function  enlargeSearch(){
      	enlarge = new Fx.Styles($('searchbar'),{duration:400, wait:false,onComplete:function(){if(enlarge_search=='0') {$('searchbar').setStyle('visibility','hidden');}else{$('subm').setStyle('display','block');}}});
      	if(enlarge_search=='0') 
          	{	
          		enlarge.start({'width': ['0px','248px']});enlarge_search='1';
          		$('searchbar').setStyle('visibility','visible');
          	}
          	else
          	{
          		$('subm').setStyle('display','none');
          		enlarge.start({'width': ['248px','0px']});enlarge_search='0';
          		
          		
          	}
          	
      }

