function BlogPreview(container) {
  this.container_ = container;
}

BlogPreview.prototype.show = function(url, opt_noTitle) {
  var feed = new google.feeds.Feed(url);
  var preview = this;
  feed.load(function(result) {
    preview.render_(result, opt_noTitle);
  });
}

BlogPreview.prototype.render_ = function(result, opt_noTitle) {
  if (!result.feed || !result.feed.entries) return;
  while (this.container_.firstChild) {
    this.container_.removeChild(this.container_.firstChild);
  }

  var blog = this.createDiv_(this.container_, "blog");
//  if (!opt_noTitle) {
//    var header = this.createElement_("h2", blog, "");
    //this.createLink_(header, result.feed.link, result.feed.title);
//  }

//  for (var i = 0; i < result.feed.entries.length; i++) {
    var i = 0;
    var entry = result.feed.entries[i];
    var div = this.createDiv_(blog, "entry");
    this.createDiv_(div, "title", entry.title);
    //var linkDiv = this.createDiv_(div, "title");
    //this.createLink_(linkDiv, entry.link, entry.title);
    //if (entry.author) {
    //  this.createDiv_(div, "author", "Posted by " + entry.author);
    //}
    //alert(entry.content.indexOf("<img "));
    var begImg = entry.content.indexOf("src=\"http://");
    var endImg = entry.content.indexOf(" ", entry.content.indexOf("src=\"http://"));
    var srcImgVal = entry.content.substring(begImg,endImg);
    this.createDiv_(div, "body", removeHTMLTags(entry.content.substring(0, 250)+'...'));
    //this.createDiv_(div, "body", removeHTMLTags(entry.content));
    var linkDiv2 = this.createDiv_(div, "click");
    this.createLink_(linkDiv2, entry.link, 'Click here to read more >>>')
    if (begImg > 0) {
       document.getElementById('img').innerHTML = "<img border=1 width=141 height=106 align=center hspace=5 "+srcImgVal+" />";
    }
//  }
}

function removeHTMLTags(strInputCode){
 		/* 
  			This line is optional, it replaces escaped brackets with real ones, 
  			i.e. < is replaced with < and > is replaced with >
 		*/	
 	 	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		});
 		var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
 		return strTagStrippedText;
}


BlogPreview.prototype.createDiv_ = function(parent, className, opt_text) {
  return this.createElement_("div", parent, className, opt_text);
}

BlogPreview.prototype.createLink_ = function(parent, href, text) {
  var link = this.createElement_("a", parent, "", text);
  link.href = href;
  return link;
}

BlogPreview.prototype.createElement_ = function(tagName, parent, className,
                                                opt_text) {
  var div = document.createElement(tagName);
  div.className = className;
  parent.appendChild(div);
  if (opt_text) {
    div.appendChild(document.createTextNode(opt_text));
  }
  return div;
}
