$(document).ready(function() {

        if (GBrowserIsCompatible()) {


                // Default values make for easy debugging
                var lat = 38.7231111284713;
                var lng = -0.6746184825897217;

                // arrays to hold copies of the markers and html used by the side_bar
                // because the function closure trick doesnt work there
                var gmarkers = [];
                var htmls = [];

                // arrays to hold variants of the info window html with get direction forms open
                var to_htmls;
                var from_htmls;
                // Creates a marker at the given point with the given number label
                function createMarker(point,html) {
                        var marker = new GMarker(point);

                        GEvent.addListener(marker, "click", function() {
                                marker.openInfoWindowHtml(html);
                        });


                        return marker;

                }


                // create the map
                var map = new GMap2(document.getElementById("map"));
                map.addControl(new GLargeMapControl());
                map.addControl(new GMapTypeControl());
                map.setCenter(new GLatLng(38.7231111284713,-0.6746184825897217), 9);
                map.enableDoubleClickZoom();
                map.enableContinuousZoom();


                var point = new GLatLng(lat,lng);
                var ref = 1;
                var html = '<div id="direccion" style="height:190px;width:220px;"><strong>Sempere Puerto S.L.</strong><br/>Les Molines, 66-B 03450<br/> Banyeres de Mariola, Alicante - Spain<br/>Tel. + 00 34 96 65 68 440<br/> + 00 34 667 469 083<br/> Fax + 00 34 96 65 67 352 <br/>Email: info@semperepuerto.com<br/>';
                // The info window version with the "to here" form open
                to_html = '<div id="hasta_aqui_form"  style="display:none"><br/>Calcular ruta: <a class="fromhere" href="#" onclick="return false">Hasta Aquí</a> - <b>Desde Aquí</b>' +
                '<br/>Ir a:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
                '<input type="text" size=30 name="saddr" id="saddr" value="" /><br/>' +
                '<input value="Ver Ruta" type="submit" />' +
                '<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() +
                // "(" + name + ")" +
                '"/></form></div>';
                // The info window version with the "to here" form open
                from_html = '<div id="desde_aqui_form" style="display:none"><br/>Calcular ruta: <b>Hasta Aquí</b> - <a class="tohere" href="#" onclick="return false">Desde Aquí</a>' +
                '<br/>Salida desde:<form action="http://maps.google.com/maps" method="get"" target="_blank">' +
                '<input type="text" size=30 name="daddr" id="daddr" value="" /><br/>' +
                '<input value="Ver Ruta" type="submit" />' +
                '<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() +
                // "(" + name + ")" +
                '"/></form></div></div>';

                html = html + '<div id="cal_rutas"><br/>Ruta: <a class="tohere" href="#" onclick="return false">Desde Aquí</a> - <a class="fromhere" href="#" onclick="return false" >Hasta Aquí</a></div>';
                html = html + to_html + from_html;
                // The inactive version of the direction info
                var marker = createMarker(point,html);
                map.addOverlay(marker);
                //map.addOverlay(createMarker(point,html,icon,ref));
                marker.openInfoWindowHtml(html);

                // functions that open the directions forms
                $('.tohere').click(function() {
                        $('#cal_rutas').hide();
                        $('#desde_aqui_form').hide();
                        $('#hasta_aqui_form').show();
                        //marker.openInfoWindowHtml(to_htmls);

                });
                $('.fromhere').click(function() {
                        $('#cal_rutas').hide();
                        $('#hasta_aqui_form').hide();
                        $('#desde_aqui_form').show();
                        //markers.openInfoWindowHtml(from_htmls);

                });


        }

});

