function displayProvider(_providerId, _clinicId, _rpos, _proAccount, thislink) {
    reva_showSplash('Loading Brochure');

    if (reva_treatmentText != "") {
        //alert(reva_treatmentText);
        $(thislink).attr("href", $(thislink).attr("href") + "/" + reva_treatmentText);
        //alert($(thislink).attr("href"));
    }
    return;
}


function initGoogleMap() {

    var mapDiv = document.getElementById('googleMap');

    map = new GMap2(mapDiv);
    map.addControl(new GLargeMapControl());
    //map.setCenter(new GLatLng(53.2780535 ,-6.1635892), 10);
    map.setCenter(new GLatLng(_curLat, _curLng), _curZoom);

    if (_isLocationDisplay) {
        $("#map_view .search_intro").html("Click the pins to see more clinics in that area.");
        processAreas();
    }
    else {
        processSuppliers();
    }
}

function initGoogleMap2() {

    var mapDiv = document.getElementById('googleMap');
    //alert(document.body.offsetHeight + " - " + document.body.offsetWidth);
    //alert(window.innerHeight + " - " + window.innerWidth);
    //mapDiv.style.height = window.innerHeight < 350 ? "350px" : window.innerHeight+"px" ;
    //mapDiv.style.width = window.innerWidth < 500 ? "500px" : window.innerWidth+"px";    

    mapDiv.style.height = document.documentElement.clientHeight < 350 ? "350px" : document.documentElement.clientHeight + "px";
    mapDiv.style.width = document.documentElement.clientWidth < 500 ? "500px" : document.documentElement.clientWidth + "px";

    //alert(mapDiv.style.height + " - " + mapDiv.style.width);
    map = new GMap2(mapDiv);
    map.addControl(new GSmallMapControl());
    //map.setCenter(new GLatLng(53.2780535 ,-6.1635892), 10);
    map.setCenter(new GLatLng(_curLat, _curLng), _curZoom);

    if (_isLocationDisplay) {        
        processAreas();
    }
    else {
        processSuppliers();
    }
}


function processAreas() {

    // Create our "tiny" marker icon
    map.closeInfoWindow();
    //if(_marker!= null)
    //map.removeOverlay(_marker);
    var iconLoc = new GIcon();
    iconLoc.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
    iconLoc.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    iconLoc.iconSize = new GSize(32, 54);
    iconLoc.shadowSize = new GSize(32, 54);
    iconLoc.iconAnchor = new GPoint(12, 40);
    iconLoc.infoWindowAnchor = new GPoint(5, 1);

    var iconSupplier = new GIcon();
    iconSupplier.image = "http://labs.google.com/ridefinder/images/mm_20_blue.png";
    iconSupplier.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    iconSupplier.iconSize = new GSize(28, 50);
    iconSupplier.shadowSize = new GSize(28, 50);
    iconSupplier.iconAnchor = new GPoint(6, 20);
    iconSupplier.infoWindowAnchor = new GPoint(5, 1);

    for (_tempProvider in _json) {
        _tempProvider = _json[_tempProvider];
        map.addOverlay(createMarkerLocation(new GLatLng(_tempProvider.lat, _tempProvider.lng), _tempProvider.name, _tempProvider.cnt, _tempProvider.link, iconLoc));

    }
}

function createMarkerLocation(_point, _title, _cnt, _link, _icon) {
    //_icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
    _icon.image = "http://chart.apis.google.com/chart?chst=d_map_spin&chld=0.8|0|FFFFFF|12|_|" + _cnt;
    var _marker = new GMarker(_point, _icon);
    var _html = '<div style="width:200px"><span>We have ' + _cnt + ' Clinics in ' + _title + '<br/><a target="_top" href="' + _link + '/map">Click here </a>to see individaul clinics in ' + _title + '</span></div>';
    GEvent.addListener(_marker, "click", function() {
        _marker.openInfoWindowHtml(_html);
    });
    return _marker;
}

function processSuppliers() {

    // Create our "tiny" marker icon
    map.closeInfoWindow();
    var iconSupplier = new GIcon();
    iconSupplier.image = "http://labs.google.com/ridefinder/images/mm_20_blue.png";
    iconSupplier.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    iconSupplier.iconSize = new GSize(28, 50);
    iconSupplier.shadowSize = new GSize(22, 20);
    iconSupplier.iconAnchor = new GPoint(12, 40);
    iconSupplier.infoWindowAnchor = new GPoint(5, 1);
    for (_tempProvider in _json) {
        _tempProvider = _json[_tempProvider];

        map.addOverlay(createMarker(new GLatLng(_tempProvider.lat, _tempProvider.lng), _tempProvider, iconSupplier));
    }
}

function createMarker(_point, _clinicObject, _icon) {

    var _price = "";
    //set the price
    if (_clinicObject.price < 0)
        _price = "Free";
    else if (_clinicObject.price > 0) {
        _price = (_cRate * _clinicObject.price).toFixed(0);
        if (_price > 10000)
            _price = (_price / 1000).toFixed(0) + "k";
        else if (_price > 1000)
            _price = (_price / 1000).toFixed(1) + "k";
        _price = _cSymbol + _price;
    }
    //give the pro accounts a better color
    var _colour = (_clinicObject.proacc == 1 ? "FFCC00" : "00CBD9")

    _icon.image = "http://chart.apis.google.com/chart?chst=d_map_spin&chld=0." + (_price == "" && _clinicObject.proacc == 0 ? "6" : "9") + "|0|" + _colour + "|10|_|" + _price;
    _icon.iconSize = (_price == "" && _clinicObject.proacc == 0 ? new GSize(22, 40) : new GSize(36, 62));
    //                if (_price == "" && _clinicObject.proacc == 0) {
    //                    _icon.image = "http://chart.apis.google.com/chart?chst=d_map_spin&chld=0.6|0|" + _colour + "|6|_|";
    //                    //_icon.image = "http://labs.google.com/ridefinder/images/mm_20_blue.png";
    //                    _icon.iconSize = new GSize(22, 40);
    //                }else{
    //                    _icon.image = "http://chart.apis.google.com/chart?chst=d_map_spin&chld=0.9|0|" + _colour + "|10|_|" + _price;
    //                    _icon.iconSize = new GSize(36, 60);
    //                }
    //zindexprocess allows us place the pro pins above the others. handy when google clusters at hight zoom levels
    var _marker = new GMarker(_point, { zIndexProcess: function() { if (_clinicObject.proacc == 1) return _clinicObject.id * 10; else if (_price != "") return _clinicObject.id * 5; else return -_clinicObject.id; }, icon: _icon });

    //rather then output all html, make an ajax call to pull in only the clinics the person clicks on.
    GEvent.addListener(_marker, "click", function() {
        var _cacheObj = mapAjaxCache.getItem(_clinicObject.id)
        if (_cacheObj != null) {
            _marker.openInfoWindowHtml(_cacheObj);
        } else {

            $.ajax({
                url: "/consumer/ajax/ajaxgethints.aspx",
                data: { datatype: 7, cid: _curClinicType, pid: _curProc, id: _clinicObject.id },
                async: true,
                dataType: "json",
                success: function(_data) {

                    for (_clinicObject in _data)
                        _clinicObject = _data[_clinicObject];

                    var _html = generateHtml(_clinicObject, _json[_clinicObject.id]);
                    mapAjaxCache.setItem(_clinicObject.id, _html);

                    _marker.openInfoWindowHtml(_html);
                    try {
                        pageTracker._trackPageview("/mapviewof_" + _clinicObject.id);
                    } catch (ee) {
                    }
                },
                onerror: function(errorMsg) {
                    _marker.openInfoWindowHtml('<div>We encountered a problem trying to retrieve the details of this clinic. Please try selecting a different clinic.</div>');
                }
            });
        }
    });
    return _marker;
}
//basicly uses the information passed back from the ajax request to build a mini listing
function generateHtml(_clinicObject, _resultObject) {
    //var _html = '<div class="s_listing map_listing" ><div class="s_listing_title"><h3><a target="_top" href="' + _clinicObject.link + '" id="link" onclick=\"Javascript:parent.gvAjaxManager.rememberParams(parent.providersListParams);\">' + _clinicObject.name + '</a></h3></div>';
    //var _html = '<div class="s_listing map_listing" ><div class="s_listing_title"><h3><a target="_top" href="' + _clinicObject.link + '" id="link" >' + _clinicObject.name + '</a></h3></div>';

    var _html = '<div class="s_listing map_listing ' + (_clinicObject.imageid > 0 ? "" : "map_listing_no_image") + '" ><div class="s_listing_title" title="' + _clinicObject.name + '"><h3><a target="_top" onclick="Javascript:return displayProvider(' + _clinicObject.sid + ',' + _clinicObject.id + ',' + _resultObject.rpos + ',' + _resultObject.proacc + ',this);" href="' + _clinicObject.link + '" id="link" >' + (_clinicObject.name.length > 32 ? _clinicObject.name.substring(0, 32) + '..' : _clinicObject.name) + '</a></h3></div>';
    if (_clinicObject.imageid > 0)
        _html += '<div title="' + _clinicObject.name + '" style="background: transparent url(/SharedControls/getthumb.aspx?img=' + _clinicObject.imageid + '&amp;h=50&amp;w=75&amp;scale=true) no-repeat scroll 0px;" class="s_listing_thumbnail"></div>';

    _html += '<div class="map_listing_content">';

    if (typeof (_resultObject.price) != "undefined") {
        var _price = "Price On Request";
        //set the price
        if (_resultObject.price < 0)
            _price = "Free";
        else if (_resultObject.price > 0) {
            _price = (_cRate * _resultObject.price).toFixed(0);
            if (_price > 10000)
                _price = (_price / 1000).toFixed(0) + "k";
            else if (_price > 1000)
                _price = (_price / 1000).toFixed(1) + "k";
            _price = _cSymbol + _price + "+";
        }
        _html += '<span>' + _resultObject.procname + ' - ' + _price + '</span>';
    }
    _html += '<span>' + _clinicObject.address + '</span>';

    if (_clinicObject.reviewCnt > 0)
        _html += '<div title="Patient Reviews Available" class="s_listing_rating"><span title="Patient Reviews Available" class="rate rate' + _clinicObject.reviewPer + '"></span><a target="_top" href="' + _clinicObject.link + '">' + _clinicObject.reviewCnt + ' Review</a></div>';

    if (_clinicObject.special != '')
        _html += '<span title="This Clinic Specialises in these particualar areas"><b>Specialises in:</b><br/>' + _clinicObject.special + '</span>';

    _html += '</div>';

    _html += '<a class="s_listing_contactLink" target="_top"  href="/consumer/consultationform.aspx?' + _queryParams + '&rpos=' + _resultObject.rpos + '&sids=' + _clinicObject.sid + '&clinicid=' + _clinicObject.id + '" onclick="Javascript:gvAjaxManager.logRequest(\'link=15&clinicid=' + _clinicObject.id + '\');" rel="nofollow" class="jq_details view_details">Contact Clinic</a></div>';



    return _html;
} 