// Add Container to sidebar, but only if we are in the one of the specified sections of the site
IMEDO.PageSetup.buildSearchUrl = function(url){
  return "http://www.imedo.de" + url;
};

IMEDO.ZahnForumBuilder = {
  // data = result information from imedo related doctors api (parsed JSON Object)
  build: function(parentContainer, data){
    if(data.results.length === 0){ return; }
    parentContainer.empty();
    
    // Create a new box
    var wrapper = $jq('<div class="zahnforum-wrapper"></div>');
    // Add Header to box
    wrapper.append("<h2><span>Diese &Auml;rzte k&ouml;nnten Ihnen helfen (Anzeigen)</span>"+(data.expertise || "&Auml;rzte")+" in "+(data.location || "ihrer N&auml;he")+"</h2>");
    
    // Add result list to box
    var list = $jq("<ul></ul>");
    for(i=0; i < data.results.length; i++){
      var result  = data.results[i];
      var providerUrl = IMEDO.PageSetup.buildSearchUrl('/practice/provider/show/' + result.permalink);
      var header  = "<h3><a href='"+providerUrl+"?related_provider=" + (i + 1) + "&site_id=" + IMEDO.RelatedDoctors.siteId + "'>"+result.name+"</a></h3>";
      var image   = "<a href='"+providerUrl+"?related_provider=" + (i + 1) + "&site_id=" + IMEDO.RelatedDoctors.siteId + "'><img src='"+result.pictureUrl+"' alt='"+result.name+"' width='30' height='30' /></a>";
      var text    = "<p>"+result.text+"</p>";
      list.append("<li><div class='image'>"+ image + "</div><div class='text'>" + header + "</div>" + text + "</li>");
    }
    wrapper.append(list);
    var searchQuery  = encodeURI(data.expertise)+"&location="+encodeURI(data.location);
    var locationName = data.location || 'Ihrer N&auml;he';
    wrapper.append("<a href='"+IMEDO.PageSetup.buildSearchUrl('/practice/provider_search/list?query='+searchQuery)+"'>Mehr &Auml;rzte in "+locationName+"</a>");
    parentContainer.append(wrapper);
  }
};

IMEDO.RelatedDoctors.builder = "ZahnForumBuilder";
IMEDO.RelatedDoctors.apiUrl   = "http://doctors.imedo.de/practice/provider_search_api";
IMEDO.RelatedDoctors.limit   = 4;
IMEDO.RelatedDoctors.siteId   = 489;

