//<script type="text/javascript">
    //<![CDATA[

	// Google Map v3 Code. Converted from the v2 code by Mojeeb
	
	
    var mapSearch, box;
    var draggable = false, resizable = false;
    var mouseX, mouseY, drawnX, drawnY, diffX, diffY;
    
    window.onload = function() {

        // Make the variable box global
        box = document.getElementById("drag");
        // Register mouse move listener
        document.onmousemove = watchMouse;
        // Load a map initially
        //loadMap(54.78333, 9.43333, 'Flensburg');
    }


    window.onunload = function() {

        // Make sure that GUnload() is called when necessary on unload
        // // if (box.style.visibility == "visible")
            // // GUnload();
    }


    // Mouse move listener
    function watchMouse(e) {

        // Include possible scroll values
        var sx = window.scrollX || document.documentElement.scrollLeft || 0;
        var sy = window.scrollY || document.documentElement.scrollTop || 0;

        if (!e) e = window.event; // IEs event definition
        mouseX = e.clientX + sx;
        mouseY = e.clientY + sy;

        /* Direction of mouse movement
        *  deltaX: -1 for left, 1 for right
        *  deltaY: -1 for up, 1 for down
        */
        var deltaX = mouseX - diffX;
        var deltaY = mouseY - diffY;
        // Store difference in global variables
        diffX = mouseX;
        diffY = mouseY;

        if (draggable) { // The box is being dragged
            box.style.left = (mouseX - drawnX) + "px";
            box.style.top = (mouseY - drawnY) + "px";
        }
        return false;
    }


    function dragstart(e) { // Calculate mouse position for dragging

        draggable = true;
        drawnX = mouseX - parseInt(box.style.left);
        drawnY = mouseY - parseInt(box.style.top);

        /* Avoid selecting the content
        * of the box while dragging
        */
        if (e.cancelable) { e.preventDefault(); }
        if (window.event) { window.event.returnValue = false; }

        // The box is being dropped
        box.onmouseup = function() { draggable = false; }
    }


    function loadMap(lat, lng, name) {

            var point = new google.maps.LatLng(lat, lng); 
			
			var myMapOptions = {
                                zoom: 12,
                                center: point,
                                mapTypeId: google.maps.MapTypeId.ROADMAP,
                                zoomControl: true,
                                zoomControlOptions: {
                                    style: google.maps.ZoomControlStyle.LARGE
                                }

                            };
			mapSearch = new google.maps.Map(document.getElementById("map"), myMapOptions);
            
			var marker = new google.maps.Marker({
                                        position: point,
                                        map: mapSearch,
                                        title: name
                                    });
									
			var infowindow = new google.maps.InfoWindow();
            
			google.maps.event.addListener(marker, 'click', function () {
                infowindow.setContent(name);
				infowindow.open(myMap, this);
            });
            
            box.style.visibility = "visible";
    }

    function getCords(address, companyName) {
			
			var myMapOptions = {
                                zoom: 15,
								
                                mapTypeId: google.maps.MapTypeId.ROADMAP
                            };
			mapSearch = new google.maps.Map(document.getElementById("map"), myMapOptions);

            showAddress(address, companyName);
    }

    function showAddress(address, companyName) {
        var geocoder = new google.maps.Geocoder();
		if (address != "") {
                geocoder.geocode({ 'address': address }, function (results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
					
						var point = new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng()); 
					
						
						mapSearch.setCenter(point);
						var marker = new google.maps.Marker({
                                        position: point,
                                        map: mapSearch,
                                        title: companyName
                                    });
						
						var infowindow = new google.maps.InfoWindow();
						google.maps.event.addListener(marker, 'click', function () {
							infowindow.setContent("<b>" + companyName + "</b><br/><br/>" +  "<i>Bes&ouml;ksadress</i>" + "<br/>" + address);
							infowindow.open(mapSearch, this);
						});
						infowindow.open(mapSearch);
						
						box.style.visibility = "visible";
                    } else {
						alert(address + " inte hittad");        
                    }
                });
            }
    } 

    function hideMap() {

        box.style.visibility = "hidden";
        ////GUnload();
    }


    //]]>
    //</Script>
