function csmLoadRss(url) {
     // alert("Loading rss from ("+url+")...");
     $.ajax( {
          url: url,
          async: "false",
          dataType: "xml",
          success: function(xml) {
               console.log("Done getting rss feed");

               var html = "<ul>\n";
               $(xml).find("item").each ( function () {
                         var title = $(this).find("title").text();
                         var text = $(this).find("description").text();
                         /* ( var link = $(this).find("guid").text(); */
                         link = "/wordpress";
                         /* console.log("This is the link: " + link); */
                         var pubdate = $(this).find("pubDate").text();
                         var printer = pubdate.replace(/2007.*/,"2007");
                         html += "<li>\n<a class=\"bloglink\" href=\""+link+"\">"+title+"</a>\n";
                         html += "<p class=\"date\">Published "+printer+"</p>\n";
                         var truncated_text = text.substring(0,20);
                         if (truncated_text.length < text.length) {
                              truncated_text += "...";
                         }
                         html += truncated_text;
                         html += "</li>\n";
                    }
               );
               html += "</ul>";
               /* console.log("This is the blog html\n" + html); */
               $("#rss").append(html);
          },
          error: function(request,settings) {
               $("#rss").append("<p>I was unable to contact the blog. The error was this:</p>");
               $("#rss").append("<p>"+ settings.url +"</p>");
               
          }
        });
        console.log("Done running ajax.");

}

function get_image_list(url) {
          // fucking cache
     var i = Math.round(10000*Math.random());
     url += "&chad="+i;
          console.log("Loading xml containing images from ("+url+")...");
          $("p#status").text("Loading images...\n");
          $("P#status").toggle();
     var imageurls = new Array();
     var response_images = $.ajax( {
          url: url,
          type: "GET",
          dataType: "html",
          async: "true",
          success: function(csmresponse) {
               var raw_response_string;
               // this is the raw response
               // alert("This is the response (" + response_images.responseText + ")")
               // alert("This is the html"+html);
               // console.log("this is csmresponse: " + csmresponse);
               // can we parse hmtl?
               // var random_something = $("<p>chad was here<\p>");
               // $().find(random_something,"p").each( function () {
               //     console.log("Something is " + this);
               //});
               // console.log("This is random something: " + random_something);
               $("div#gallery_response").html(csmresponse);
               // console.log("this is parsed response" + parsed_html);
               // alert("Parsed html is " + parsed_html);
               //var links = $(".gallery_container",html);
               // console.log("There are this many divs in that document: ("+links.length+")\n");
               // console.log("Done getting image list. This is the html: " + html);
               // alert("This is the html inside the object ("+$(html).html()+")\n");
               var list = "<ul>\n";
               // $(xml).find(".gallery_container").each ( function () {
               $("div.container").each( function (i) {
                         // console.log("Found item " + this + " Class: " + $(this).attr("class"));
                              // var text = $(this).find("description").text();
                              // var enclosure = $(this).find(".gallery_resized img").attr("src");
                              // console.log("this is the enclosure: " + enclosure);
                              // console.log("Description is " + text);
                              // var img = $(text);
                              // console.log("img is " + img);
                              // var imglink = $(img).html();
                         var link = $(this).find("div.gallery_resized img").attr('src') ||
                              $(this).find("div.gallery_large img").attr('src') || 
                              $(this).find("div.gallery_thumbnail").attr('src');
                         var alt = $(this).find("div.gallery_large img").attr('alt');
                              //console.log("link is " + link);
                              // link = "/wordpress";
                              // var pubdate = $(this).find("pubDate").text();
                              // var printer = pubdate.replace(/2007.*/,"2007");
                         list += "<li>";
                         list += "<a href=\""+link+"\">\n";
                         // list += "<img src=\""+link+"\" width=\"82\" alt=\""+alt+"\">\n";
                         list += "<img src=\""+link+"\" width=\"82\">\n";
                         list += "</a></li>\n";
                              // html += link;
                    }
               );
               list += "</ul>";
               // alert("This is the gallery html\n" + list);
               // console.log("This is the gallery html: " + list);
               $("p#status").text('Done!');
               $("p#status").toggle();
               $("#gallery").append(list);
               $("#gallery_debug").append(list);
               // $("#gallery_debug").append(html);
               console.log("Preparing to bind jqGalView");
               $("#gallery").jqGalViewII();
               console.log("Done binding.");
          },
          error: function(request,error) {
               console.log("There was an error running ajax: " + error);
               $("#gallery").append("<p>I was unable to contact the gallery. The error was this:</p>");
               $("#gallery").append("<p>"+ error +"</p>");
          }
        });
        console.log("Done running ajax to get images.");
}

function label() {
     console.log("Starting.");
     $("div item description").each( function() {
          console.log("Description object is " + this);
          var contents = $(this).nodeValue;
          console.log("Contents are " + contents);
          
     });
     console.log("Done.");
}


function populate_gallery_list(id,url) {
     // /alert("populating gallery list from ("+url+")...");
     var response_images = $.ajax( {
          url: url,
          type: "GET",
          dataType: "html",
          async: "true",
          success: function(csmresponse) {
               console.log("Great. response is " + csmresponse);
               $("div#list_response").html(csmresponse);
               // $("select#galleryselectbox option").remove();
               $("div#galleryselecttemp select option").each( function() {
                    console.log("Appending to ("+this+")...\n");
                    $(this).appendTo("select#galleryselectbox");
                    });
              // alert("Done with ajax"); 
          },
          error: function(request,error) {
               console.log("Urgle... " + error);
          }
          });
 }
