/*
 * Bing search pagemod functions
 *
 * @author Arend-Jan Tetteroo <aj@cleanbits.net>
 * @copyright Cleanbits/The Green Web Foundation 2010-2013
 */

/**
 * On Request, find all hrefs and assign green or grey icon
 */
chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        if (request.data){
            data = request.data;
            $("#results ul > li").each(function (i) {
                var loc = getUrl($(this).find('a').first().attr('href'));

                if(data[loc]){
                    $(this).find('.TGWF').first()
                      .html(getResultNode(data[loc]).append('&nbsp;'))
                      .qtip({
                          content: { 
                            text: function(api) { 
                              return getTitleWithLink(data[loc]); 
                              } 
                            },
                            show: { delay: 700 },
                            hide: { fixed:true,  delay:500 }
                      });
                      if(data[loc].green){
                        $(this).find('.TGWF').first().qtip('option', { 'style.classes': 'qtip-green'});
                      } else {
                        $(this).find('.TGWF').first().qtip('option', { 'style.classes': 'qtip-light'});
                      }                
                }
            });
        }
    });

/**
 * If document is ready, find the urls to check
 */
$(document).ready(function() {
    chrome.storage.local.get("tgwf_search_disabled", function(items) {
        if(items.tgwf_search_disabled == 1){
          // Green web search is disabled, return
          return;
        }
        $('#results').prepend("<p id='thegreenweb'>" + getLinkImage('green','The Green Web extension shows if a site is sustainably hosted') + ' The Green Web is enabled</p>');
        var locs = new Object();
        if ( $("#results ul > li").length > 0 ) {
             $("#results ul > li").each(function (i) {
                 $(this).find('a').first().prepend($('<span>', { class: 'TGWF'}).append(getImageNode('greenquestion')).append('&nbsp;'));
                 var loc = getUrl($(this).find('a').first().attr('href'));
                 locs[loc] = loc;
             });
        }
        if(Object.keys(locs).length > 0) {
            chrome.extension.sendMessage({locs: locs}, function(response) {});
        }
    });
});
@@ -70,21 +70,33 @@
 %3Caj@
-cleanbits.net
+thegreenwebfoundation.org
 %3E%0A *
@@ -154,9 +154,9 @@
 -201
-3
+4
 %0A */
@@ -381,32 +381,34 @@
         $(%22#
+b_
 results 
 ul %3E li%22).ea
@@ -387,35 +387,32 @@
   $(%22#b_results 
-ul 
 %3E li%22).each(func
@@ -1704,16 +1704,18 @@
     $('#
+b_
 results'
@@ -1917,32 +1917,34 @@
    if ( $(%22#
+b_
 results 
 ul %3E li%22).le
@@ -1931,23 +1931,23 @@
 results 
-ul %3E li
+.b_algo
 %22).lengt
@@ -1973,24 +1973,26 @@
     $(%22#
+b_
 results 
 ul %3E li%22
@@ -1987,15 +1987,15 @@
 lts 
-ul %3E li
+.b_algo
 %22).e

Fix for new bing page layout