﻿var DEBUG_XML = false; // to output XML resulted from JS to console debug (for firebug)
var picasaThumbnailSize = "s288"; // picasa has a problem of displaying image. need to specify thumbnail size to solve this problem
var outputDivName = "result"; // The name of the div to display result
var FLICKR_KEY = '3f6b93851e8a30e6d2b04d6ff4ba837b'; // please create a key for Clip and change this key value to that key
var XSL_FILE; // xsl file 

if(OUTPUT_STYLE == "column") {
	if(SORT_RESULT) {
		XSL_FILE = '/js/outtemplate.xsl';
	} else {
		XSL_FILE = '/js/outtemplate_nosort.xsl';
	}
} else if(OUTPUT_STYLE == "tile") {
	if(SORT_RESULT) {
		XSL_FILE = '/js/tile.xsl';
	} else {
		XSL_FILE = '/js/tile_nosort.xsl';
	}
}

var blogKeywords = [];
var blogIds = [];
var picasaIds = [];
var picasaKeywords = [];
var flickrIds = [];
var flickrKeywords = [];
var ytIds = [];
var ytKeywords = [];

var resultXml = "";
var xsl = null;
var wasShownBlogger = new Object();
var wasShownPicasaPicture = new Object();
var wasShownYt = new Object();

// The first function to be called for Picasa retrieval mechanism
function getPicasa() {
	for(var i=0;i<picasaIds.length;i++) {
		// retrieve all album ids for each user specified
		var picasaAlbumUrl = "http://picasaweb.google.com/data/feed/api/user/" + picasaIds[i] +"?alt=json-in-script&callback=picasaAlbumCallback";
		insertScript(picasaAlbumUrl);
	}
}

// Callback function for getPicasaJSON function
function picasaAlbumCallback(response) {
	//console.debug(response);
	if( ! response ) return;
	if( ! response.feed ) return;
	if( ! response.feed.entry ) return;
	var picasaId = response.feed.gphoto$user.$t;
	for(var i=0;i<response.feed.entry.length;i++) {
		var picasaAlbumId = response.feed.entry[i].gphoto$id.$t;
		for(var j=0;j<picasaKeywords.length;j++) {
			// retrieve images with each specified tag
			var picasaUri = "http://picasaweb.google.com/data/feed/api/user/" + picasaId + "/albumid/" + picasaAlbumId + "?kind=photo&alt=json-in-script&callback=picasaCallback&tag=" + picasaKeywords[j];
			insertScript(picasaUri);
		}
	}
}

// Callback function for picasaAlbumCallback function
function picasaCallback(response) {
	//console.debug(response);
	if( ! response ) return;
	if( ! response.feed ) return;
	if( ! response.feed.entry ) return;
	for (var i = 0; i < response.feed.entry.length; i ++) {
		// check if the picture has already added to the result
		if(wasShownPicasaPicture[response.feed.entry[i].gphoto$id.$t] != 1) {
			wasShownPicasaPicture[response.feed.entry[i].gphoto$id.$t] = 1;
			// mapping each information to the object
			var map = new Object();
			map["id"] = response.feed.entry[i].gphoto$id.$t;
			map["link"] = response.feed.entry[i].link[1].href;
			// convert photo url to use thumbnail because there is a problem displaying a full picture 
			var photourl = response.feed.entry[i].content.src;
			var tmp = photourl.split("/");
			var thumbnailUrl = "";
			for(var j=0;j<tmp.length-1;j++) {
				thumbnailUrl += tmp[j] + "/";
			}
			thumbnailUrl += picasaThumbnailSize + "/" + tmp[tmp.length-1];
			map["photoUrl"] = thumbnailUrl;
			map["title"] = response.feed.entry[i].title.$t;
			map["authorName"] = response.feed.author[0].name.$t;
			map["authorUrl"] = response.feed.author[0].uri.$t;
			map["publishedDate"] = response.feed.entry[i].published.$t.substring(0,10).replace(/-/g,"\/");
			map["publishedTime"] = response.feed.entry[i].published.$t.substring(11,19);
			map["publishedTimestamp"] = Date.parse(response.feed.entry[i].published.$t.substring(0,10).replace(/-/g,"\/") + " " + response.feed.entry[i].published.$t.substring(11,19));
			map["updatedDate"] = response.feed.entry[i].updated.$t.substring(0,10).replace(/-/g,"\/");
			map["updatedTime"] = response.feed.entry[i].updated.$t.substring(11,19);
			map["updatedTimestamp"] = Date.parse(response.feed.entry[i].updated.$t.substring(0,10).replace(/-/g,"\/") + " " + response.feed.entry[i].updated.$t.substring(11,19));
			map["content"] = response.feed.entry[i].summary.$t;
			map["source"] = "picasa";
			// convert the JSON object to XML text
			resultXml += "<entry>" + json2xml(map) + "</entry>";
			//console.debug(json2xml(map));
		}
	}
	convertXslt(resultXml);
}

// The first function to be called for Blogger retrieval
function getBlogger() {
	for(i=0;i<blogIds.length;i++) {
		// repeat all blog ids
  		var blogBaseUri = "http://www.blogger.com/feeds/" + blogIds[i] + "/posts/default/-/";
  		for(j=0;j<blogKeywords.length;j++) {
  			// repeat all keywords
  			var blogUri = blogBaseUri + blogKeywords[j] + '?alt=json-in-script&callback=bloggerCallback';
			insertScript(blogUri);
  		}
	}
}

//  Callback function for getBlogger function
function bloggerCallback(response) {
	//console.debug(response);
	if( ! response ) return;
	if( ! response.feed ) return;
	if( ! response.feed.entry ) return;
	for (var i = 0; i < response.feed.entry.length; i ++) {
		// check if the blog has already added to the result
		if(wasShownBlogger[response.feed.entry[i].id.$t] != 1) {
			wasShownBlogger[response.feed.entry[i].id.$t] = 1;
			// mapping each information to the object
			var map = new Object();
			map["id"] = response.feed.entry[i].id.$t;
			map["title"] = response.feed.entry[i].title.$t;
			map["link"] = response.feed.entry[i].link[0].href;
			var contentHtml = $("<div>" + response.feed.entry[i].content.$t + "</div");
			map["content"] = contentHtml.text();
			map["publishedDate"] = response.feed.entry[i].published.$t.substring(0,10).replace(/-/g,"\/");
			map["publishedTime"] = response.feed.entry[i].published.$t.substring(11,19);
			map["publishedTimestamp"] = Date.parse(response.feed.entry[i].published.$t.substring(0,10).replace(/-/g,"\/") + " " + response.feed.entry[i].published.$t.substring(11,19));
			map["updatedDate"] = response.feed.entry[i].updated.$t.substring(0,10).replace(/-/g,"\/");
			map["updatedTime"] = response.feed.entry[i].updated.$t.substring(11,19);
			map["updatedTimestamp"] = Date.parse(response.feed.entry[i].updated.$t.substring(0,10).replace(/-/g,"\/") + " " + response.feed.entry[i].updated.$t.substring(11,19));
			map["authorName"] = response.feed.entry[i].author[0].name.$t;
			map["authorUrl"] = response.feed.entry[i].author[0].uri.$t;
			
			// find an image in the blog content
			var imgTagPos = response.feed.entry[i].content.$t.indexOf("img");
			var imgPath = "";
			if(imgTagPos > -1) {
				// there is at least one image in the Content
				var imgSrcPos = response.feed.entry[i].content.$t.indexOf("src", imgTagPos);
				var quotePos = response.feed.entry[i].content.$t.indexOf("\'", imgSrcPos);
				var doubleQuotePos = response.feed.entry[i].content.$t.indexOf("\"", imgSrcPos);
				if( (quotePos > -1) && (quotePos < doubleQuotePos) ) {
					// means that ' is used to cover image src ( src='http://xxxxx')
					imgPath = response.feed.entry[i].content.$t.substring(quotePos+1, response.feed.entry[i].content.$t.indexOf("\'", quotePos+1));
				} else {
					// double quote was used
					imgPath = response.feed.entry[i].content.$t.substring(doubleQuotePos+1, response.feed.entry[i].content.$t.indexOf("\"", doubleQuotePos+1));
				}
			}
			map["photoUrl"] = imgPath;
			map["source"] = "blogger";
			// convert the JSON object to XML text
			resultXml += "<entry>" + json2xml(map) + "</entry>";
		}
	}
	convertXslt(resultXml);
}

// FLICKR
// The first function to be called for flickr picture retrieval
function getFlickr() {
	var keywords = flickrKeywords.join(",");
	for(var i=0;i<flickrIds.length;i++) {
		flickr_search({ user_id : flickrIds[i], tags: keywords });
	}
}

function flickr_search ( param ) {
	// Flickr API parameters
	param.api_key  = FLICKR_KEY;
	param.method   = 'flickr.photos.search';
	param.per_page = 10;
	param.sort     = 'date-posted-desc';
	param.format   = 'json';
	param.jsoncallback = 'flickrCallback';

	// call flickr 
	var url = 'http://www.flickr.com/services/rest/?' + obj2query( param );
	insertScript(url);
}

// Function to get information of an image
function flickr_getInfo( param ) {
	param.api_key  = FLICKR_KEY;
	param.method   = 'flickr.photos.getInfo';
	param.format   = 'json';
	param.jsoncallback = 'flickrInfoCallback';
	var url = 'http://www.flickr.com/services/rest/?' + obj2query( param );
	insertScript(url);
}

// callback function for flickr_search function
function flickrCallback ( data ) {
	//console.debug(data);
    if ( ! data ) return;
    if ( ! data.photos ) return;
    var list = data.photos.photo;
    if ( ! list ) return;
    if ( ! list.length ) return;

	for(var i=0;i<list.length;i++) {
		flickr_getInfo({ photo_id : list[i].id });
	}
}

// callback function for flickr_getInfo function
function flickrInfoCallback( data ) {
	//console.debug(data);
    if ( ! data ) return;
    if ( ! data.photo ) return;
	var photo = data.photo;
	// mapping each information to the object
	var map = new Object();
	map["id"] = photo.id;
	map["link"] = 'http://www.flickr.com/photos/' + photo.owner.nsid + '/' + photo.id;
	map["photoUrl"] = 'http://farm' + photo.farm + '.static.flickr.com/' + photo.server + '/' + photo.id + '_' + photo.secret + '.jpg';
	map["title"] = photo.title;
	map["authorName"] = photo.owner.username;
	map["authorUrl"] = 'http://www.flickr.com/people/' + photo.owner.nsid + '/';
	var publishedDateTime = new Date(photo.dates.posted * 1000);
	map["publishedDate"] = publishedDateTime.toLocaleDateString().replace(/年/,"\/").replace(/月/,"\/").replace(/日/,"");
	map["publishedTime"] = publishedDateTime.toLocaleTimeString();
	map["publishedTimestamp"] = photo.dates.posted * 1000;
	var updatedDateTime = new Date(photo.dates.lastupdate * 1000);
	map["updatedDate"] = updatedDateTime.toLocaleDateString().replace(/年/,"\/").replace(/月/,"\/").replace(/日/,"");
	map["updatedTime"] = updatedDateTime.toLocaleTimeString();
	map["updatedTimestamp"] = photo.dates.lastupdate * 1000;
	map["content"] = photo.description._content;
	map["source"] = "flickr";
	// convert the JSON object to XML text
	resultXml += "<entry>" + json2xml(map) + "</entry>";
	//console.debug(resultXml); 
	convertXslt(resultXml);
}

// YOUTUBE
// The first function to be called for Youtube retrieval
function getYoutube() {
	for(i=0;i<ytIds.length;i++) {
		// repeat all youtube ids
  		var ytBaseUri = "http://gdata.youtube.com/feeds/api/users/" + ytIds[i] + "/uploads/-/";
  		for(j=0;j<ytKeywords.length;j++) {
  			// repeat all keywords
			var ytUri = ytBaseUri + ytKeywords[j] + '?alt=json-in-script&callback=ytCallback';
			insertScript(ytUri);
  		}
	}
}

function ytCallback(response) {
	//console.debug(response);
	if( ! response ) return;
	if( ! response.feed ) return;
	if( ! response.feed.entry ) return;
	for (var i = 0; i < response.feed.entry.length; i ++) {
		// check if the picture has already added to the result
		if(wasShownYt[response.feed.entry[i].id.$t] != 1) {
			wasShownYt[response.feed.entry[i].id.$t] = 1;
			// mapping each information to the object
			var map = new Object();
			map["id"] = response.feed.entry[i].id.$t;
			map["link"] = response.feed.entry[i].link[0].href;
			map["photoUrl"] = response.feed.entry[i].media$group.media$thumbnail[0].url;
			map["title"] = response.feed.entry[i].title.$t;
			map["authorName"] = response.feed.author[0].name.$t;
			map["authorUrl"] = response.feed.link[1].href;
			map["publishedDate"] = response.feed.entry[i].published.$t.substring(0,10).replace(/-/g,"\/");
			map["publishedTime"] = response.feed.entry[i].published.$t.substring(11,19);
			map["publishedTimestamp"] = Date.parse(response.feed.entry[i].published.$t.substring(0,10).replace(/-/g,"\/") + " " + response.feed.entry[i].published.$t.substring(11,19));
			map["updatedDate"] = response.feed.entry[i].updated.$t.substring(0,10).replace(/-/g,"\/");
			map["updatedTime"] = response.feed.entry[i].updated.$t.substring(11,19);
			map["updatedTimestamp"] = Date.parse(response.feed.entry[i].updated.$t.substring(0,10).replace(/-/g,"\/") + " " + response.feed.entry[i].updated.$t.substring(11,19));
			map["content"] = response.feed.entry[i].content.$t;
			map["source"] = "youtube";
			// convert the JSON object to XML text
			resultXml += "<entry>" + json2xml(map) + "</entry>";
		}
	}
	convertXslt(resultXml);
}

// Function to insert and run javascript code on the fly
function insertScript(query) {
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = query;
	$('head').append(script);
}

// Function to convert parameters to a query
function obj2query ( obj ) {
	var list = [];
	for( var key in obj ) {
		var k = encodeURIComponent(key);
		var v = encodeURIComponent(obj[key]);
		list[list.length] = k+'='+v;
	}
	var query = list.join( '&' );
	return query;
}

// Function to convert XML text based on XSLT
function convertXslt(xml) {
	if(DEBUG_XML) {
		console.debug(xml);
	}
	var escapedXml = escape(xml);
	if( ! xsl ) {
		// need to pass the resultXML as a parameter for the callback function
		$.post(XSL_FILE, { dataType: "xml", resultXML: escapedXml }, xslCallback);
	} else {
		this.data = "resultXML=" + escapedXml;
		xslCallback(xsl);
	}
}

// Callback function for convertXslt function
function xslCallback(response) {
	xsl = response;
	var tmp = this.data.split("&");
	var xmlText = '<?xml version="1.0" encoding="utf-8"?>';
	for(var i=0;i<tmp.length;i++) {
		// get the xml text from the parameter resultXML
		if(tmp[i].split("=")[0] == "resultXML") {
			xmlText += '<entries>' + tmp[i].split("=")[1] + '</entries>';
		}
	}
	var xmlDoc;
	if (window.ActiveXObject) {
		// code for IE
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(unescape(unescape(xmlText)));
		ex=xmlDoc.transformNode(xsl);
		$("#"+outputDivName).html(ex);
	} else if (document.implementation && document.implementation.createDocument) {
		// code for Mozilla, Firefox, Opera, etc.
		parser=new DOMParser();
		xmlDoc=parser.parseFromString(unescape(unescape(xmlText)),"text/xml");
		xsltProcessor=new XSLTProcessor();
		xsltProcessor.importStylesheet(xsl);
		resultDocument = xsltProcessor.transformToDocument(xmlDoc);
		$("#"+outputDivName).html(resultDocument.documentElement.innerHTML);
	}
}

// Function to convert JSON object to XML text
function json2xml(o, tab) {
   var toXml = function(v, name, ind) {
      var xml = "";
      if (v instanceof Array) {
         for (var i=0, n=v.length; i<n; i++)
            xml += ind + toXml(v[i], name, ind+"\t") + "\n";
      }
      else if (typeof(v) == "object") {
         var hasChild = false;
         xml += ind + "<" + name;
         for (var m in v) {
            if (m.charAt(0) == "@")
               xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\"";
            else
               hasChild = true;
         }
         xml += hasChild ? ">" : "/>";
         if (hasChild) {
            for (var m in v) {
               if (m == "#text")
                  xml += v[m];
               else if (m == "#cdata")
                  xml += "<![CDATA[" + v[m] + "]]>";
               else if (m.charAt(0) != "@")
                  xml += toXml(v[m], m, ind+"\t");
            }
            xml += (xml.charAt(xml.length-1)=="\n"?ind:"") + "</" + name + ">";
         }
      }
      else {
         xml += ind + "<" + name + ">" + v.toString() +  "</" + name + ">";
      }
      return xml;
   }, xml="";
   for (var m in o)
      xml += toXml(o[m], m, "");
   return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
}

// Functions below were used to output HTML by the javascript
// They are not used when output is generated by XSLT
/*
function showOutput(result) {
	// format output html
	var titleHtml = "";
	var authorHtml = "";
	for(var i=0;i<result.length;i++) {
		titleHtml = '<a href="' + result[i]["blogLink"] + '">';
		titleHtml += "<h3>" + result[i]["blogTitle"] + "</h3>";
		titleHtml += '</a> ';
		authorHtml = '<div class="sb">';
		if(result[i]["blogAuthorUrl"] != "") {
			authorHtml += '<a href="' + result[i]["blogAuthorUrl"] + '">';
		}
		authorHtml += result[i]["blogAuthorName"];
		if(result[i]["blogAuthorUrl"] != "") {
			authorHtml += '</a>';
		}
		authorHtml += '</div>';
		//alert(result[i]["blogContent"]);
		var contentHtml = jQuery("<div>" + result[i]["blogContent"] + "</div>"); // if the content is not covered by <div>, some information lost (jQuery bug?)
		var contentText = contentHtml.text() ;
		// search for positon of IMG tag
		var imgTagPos = result[i]["blogContent"].indexOf("img");
		var imgPath = "";
		if(imgTagPos > -1) {
			// there is at least one image in the Content
			var imgSrcPos = result[i]["blogContent"].indexOf("src", imgTagPos);
			var quotePos = result[i]["blogContent"].indexOf("\'", imgSrcPos);
			var doubleQuotePos = result[i]["blogContent"].indexOf("\"", imgSrcPos);
			if( (quotePos > -1) && (quotePos < doubleQuotePos) ) {
				// means that ' is used to cover image src ( src='http://xxxxx')
				imgPath = result[i]["blogContent"].substring(quotePos+1, result[i]["blogContent"].indexOf("\'", quotePos+1));
			} else {
				// double quote was used
				imgPath = result[i]["blogContent"].substring(doubleQuotePos+1, result[i]["blogContent"].indexOf("\"", doubleQuotePos+1));
			}
		}
		//content.wrap(document.createElement("div"));
		//newHtml += content.text();
		var icon = '<img src="/img/Blogger_Icon_by_firemarble.png" height="20" alt="blogger" hspace="5" class="left"/>';
		var flameTop = '<div class="sbl" ><div class="sbr"><div class="stl"><div class="str">';
		var flameBottom = '</div></div></div></div>';
		var imageHtml = "";
		if(imgPath != "") {
			imageHtml += '<img style="width:100px" src="' + imgPath + '" class="thumbnail right"/>';
		}
		// extract 130 first characters from content
		var resultHtml = flameTop + icon + titleHtml ;
		resultHtml += imageHtml;
		resultHtml += contentText.substring(0, numberOfCharsToDisplay) + "..." + flameBottom + authorHtml;
		resultHtml = '<div class="cbox">' + resultHtml + '</div>';
		$('#result').html($('#result').html() + resultHtml);
	}
	
}

function picasaShowResult(result) {
	// format output html
	var titleHtml = "";
	var authorHtml = "";
	for(var i=0;i<result.length;i++) {
		titleHtml = '<a href="' + result[i]["picasaPhotoLink"] + '">';
		titleHtml += "<h3>" + result[i]["picasaPhotoTitle"] + "</h3>";
		titleHtml += '</a> ';
		authorHtml = '<div class="sb">';
		if(result[i]["picasaPhotoAuthorUrl"] != "") {
			authorHtml += '<a href="' + result[i]["picasaPhotoAuthorUrl"] + '">';
		}
		authorHtml += result[i]["picasaPhotoAuthorName"];
		if(result[i]["picasaPhotoAuthorUrl"] != "") {
			authorHtml += '</a>';
		}
		authorHtml += '</div>';
		var icon = '<img src="/img/Blogger_Icon_by_firemarble.png" height="20" alt="picasa" hspace="5" class="left"/>';
		var flameTop = '<div class="sbl" ><div class="sbr"><div class="stl"><div class="str">';
		var flameBottom = '</div></div></div></div>';
		var imageHtml = "";
		imageHtml += '<img style="width:100px" src="' + result[i]["picasaPhotoUrl"] + '" class="thumbnail center"/>';
		var resultHtml = flameTop + icon + titleHtml ;
		resultHtml += imageHtml + flameBottom + authorHtml;
		resultHtml = '<div class="cbox">' + resultHtml + '</div>';
		$('#picasaResult').html($('#picasaResult').html() + resultHtml);
	}
}

function setupMyService() {
  var myService = new google.gdata.blogger.BloggerService('exampleCo-exampleApp-1');
  return myService;
}

// Callback function for getMyBlogFeed function
function handleMyBlogFeed(myResultsFeedRoot) {
	//var result = [];
	//console.debug(myResultsFeedRoot);
	for(i=0;i<myResultsFeedRoot.feed.getEntries().length;i++) {
		var blog = myResultsFeedRoot.feed.getEntries()[i];
		if(wasShownHash[blog.getId().getValue()+""] != 1) {
			wasShownHash[blog.getId().getValue()+""] = 1;
			var map = new Object();
			// mapping all information to the object
			map["id"] = blog.getId().getValue();
			map["title"] = blog.getTitle().getText();
			map["link"] = blog.getLink().getHref();
			var contentHtml = $("<div>" + blog.getContent().getText() + "</div");
			map["content"] = contentHtml.text();
//			map["content"] = blog.getContent().getText();
			var tmpMonth = blog.getPublished().getValue().getDate().getMonth() + 1;
			map["publishedDate"] = blog.getPublished().getValue().getDate().getFullYear() + "/" + tmpMonth + "/" + blog.getPublished().getValue().getDate().getDate();
			map["publishedTime"] = blog.getPublished().getValue().getDate().getHours() + ":" + blog.getPublished().getValue().getDate().getMinutes() + ":" + blog.getPublished().getValue().getDate().getSeconds();
			map["publishedTimestamp"] = Date.parse(blog.getPublished().getValue().getDate().toUTCString());
			var tmpMonth = blog.getUpdated().getValue().getDate().getMonth() + 1;
			map["updatedDate"] = blog.getUpdated().getValue().getDate().getFullYear() + "/" + tmpMonth + "/" + blog.getUpdated().getValue().getDate().getDate();
			map["updatedTime"] = blog.getUpdated().getValue().getDate().getHours() + ":" + blog.getUpdated().getValue().getDate().getMinutes() + ":" + blog.getUpdated().getValue().getDate().getSeconds();
			map["updatedTimestamp"] = Date.parse(blog.getUpdated().getValue().getDate().toUTCString());
			if(blog.getAuthors().length > 0) {
				map["authorName"] = blog.getAuthors()[0].getName().getValue();
				if(blog.getAuthors()[0].getUri() != null) {
					map["authorUrl"] = blog.getAuthors()[0].getUri().getValue();
				} else {
					map["authorUrl"] = "";
				}
			} else {
				map["authorName"] = "";
				map["authorUrl"] = "";
			}
			
			// find an image in the blog content
			var imgTagPos = blog.getContent().getText().indexOf("img");
			var imgPath = "";
			if(imgTagPos > -1) {
				// there is at least one image in the Content
				var imgSrcPos = blog.getContent().getText().indexOf("src", imgTagPos);
				var quotePos = blog.getContent().getText().indexOf("\'", imgSrcPos);
				var doubleQuotePos = blog.getContent().getText().indexOf("\"", imgSrcPos);
				if( (quotePos > -1) && (quotePos < doubleQuotePos) ) {
					// means that ' is used to cover image src ( src='http://xxxxx')
					imgPath = blog.getContent().getText().substring(quotePos+1, blog.getContent().getText().indexOf("\'", quotePos+1));
				} else {
					// double quote was used
					imgPath = blog.getContent().getText().substring(doubleQuotePos+1, blog.getContent().getText().indexOf("\"", doubleQuotePos+1));
				}
			}
			map["photoUrl"] = imgPath;
			// set the source of this information
			map["source"] = "blogger";
			// convert JSON object to XML text
			resultXml += "<entry>" + json2xml(map) + "</entry>\n";
			// add the result data to the result list
			//result.push(map);
			//$('#debug').html($('#debug').html() + "<br>" + blog.getTitle().getText());
		}
	}
	//console.debug(json2xml(result));
	//console.debug(resultXml);
//	showOutput(result);
	convertXslt(resultXml);
	
}
//google.load("gdata", "1.x");
//google.setOnLoadCallback(getMyBlogFeed);

*/
