dojo.addOnLoad(function()
{    
    dojo.connect(searchResultsControl, "onMouseOverResult", "highlightMarker");
    dojo.connect(searchResultsControl, "onMouseAwayFromResult", "unHighlightMarker");    
});

/**
 * When a user has selected a find my nearest row, the event from the row object is fired
 * and calls this method to un-toggle the marker
 * 
 * @private
 */
function highlightMarker(rowData)
{
    var marker = getMarker(rowData);
    if (marker)
    {
        markerManager.highlightMarker(marker);
    }
}

/**
 * When a user has selected a find my nearest row, the event from the row object is fired
 * and calls this method to toggle the marker
 * 
 * @private
 */
function unHighlightMarker(rowData)
{
    var marker = getMarker(rowData);
    if (marker)
    {
        markerManager.unHighlightMarker(marker);
    }
}

/**
 * Get a amrker object from the markermanger using the id from the find my nearest row id
 * 
 * @private
 */
function getMarker(rowData)
{
    var id = rowData.getId();
    if (!markerManager)
    {
        markerManager = myMap.getMarkerManager();
    }
    var marker = markerManager.getMapMarkerById(id);
    return marker;
}

/**
 * Event driven method for when a user selects a map marker and the marker event
 * fires this method.  This method works out the offset for the location of the result
 * row and changes the containers offset to put the row in visible range
 * 
 * @private
 */
function highlightSRCRow(marker)
{    
    var results = searchResultsControl.getResultById(marker.id);        
    var parentOffsetTop = dojo.byId(results.id).parentNode.offsetTop;
    var offsetTop = dojo.byId(results.id).offsetTop - parentOffsetTop;    
    dojo.byId("findNearestResults").scrollTop = offsetTop;    
    results.setHighlightStyle("highlightedSearchResultsRow");
}

/**
 * Event driven method for when a user un-selects a map marker and the marker event
 * fires this method to remove the highlighting
 * 
 * @private
 */
function unHighlightSRCRow(marker)
{
    var results = searchResultsControl.getResultById(marker.id);    
    results.unHighlightStyle();
}
