﻿jQuery(document).ready(function () {
    // Handler for .ready() called.

    jQuery('.ShowOnMap').toggle(function () {

        // change the 'show' button to say 'hide'
        jQuery(".ShowOnMap").html('Hide Map');

        // show the map container and at the end: load the new map
        jQuery(".MapRow").show(0, function () {

            loadMapAndAddMarkers();

        });

    }, function () {

        // change back the button to 'show'
        jQuery(".ShowOnMap").html('Show On Map');

        // hide the map container
        jQuery(".MapRow").hide(600);

    });
});


var map;
var directionDisplay;
var directionsService = new google.maps.DirectionsService();

function loadMap(mapDiv, lat, long, zoom) {
    var center = new google.maps.LatLng(lat, long);
    var options = {
        zoom: zoom,
        center: center,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    map = new google.maps.Map(document.getElementById(mapDiv), options);

}


function addMarker(image, lat, long, contentString) {

    var propLocation = new google.maps.LatLng(lat, long);
    var marker = new google.maps.Marker({
        position: propLocation,
        map: map,
        icon: image
    });

    var infowindow = new google.maps.InfoWindow({
        content: contentString
    });

    google.maps.event.addListener(marker, 'click', function () {
        infowindow.open(map, marker);
    });

}

function getSearchResultMarkerContent(url, imageurl, name, s1, s2, s3, s4, s5, suburb, postcode, state, phoneno, ratingtype, rating, baseurl) {

    var html = '<div style="overflow:visible; font-size:8pt; white-space:wrap; vertical-align:top; height:120px; width:280px">';
    if (imageurl && imageurl != '') {
        html += '<div style="float:left; margin-right: 5px"><img src="' + imageurl + '" alt="" style="height: 80px; " /></div>';
    }
    html += '<div><b>' + name + '</b><br/><br/>';
    html += s1 + '<br>';
    if (s2 && s2 != '')
        html += s2 + '<br>';
    if (s3 && s3 != '')
        html += s3 + '<br>';
    if (s4 && s4 != '')
        html += s4 + '<br>';
    if (s5 && s5 != '')
        html += s5 + '<br>';

    html += suburb + ' ' + postcode + ' ' + state + '<br>';
    if (phoneno && phoneno != '')
        html += 'Phone ' + phoneno + '<br>';


    if (rating && rating != '')
    {
    var x = 0;
        for (x = 0; x < Math.floor(rating); x++) {

                if (ratingtype == 'Stars') {
                    html += '<img src="' + baseurl + 'StarSmall.gif" />';
                }
                else {
                    html += '<img src="' + baseurl + 'SelfSmall.gif" />';
                }
        }

        if (rating % 1 != 0) {
            if (ratingtype == 'Stars') {
                html += '<img src="' + baseurl + 'StarSmallHalf.gif" />';
            }
            else {
                html += '<img src="' + baseurl + 'SelfSmallHalf.gif" />';
            }
        } 
    }

    html += '</div>';

    if (url && url != '') {
        html += '<div style="text-align: right; width:250px"><a href="' + url + '">Book Now</a></div>';
    }

    html += '</div>';
    return html;
}
