function BlogPreview(container) {
	this.container_ = container;
}
BlogPreview.prototype.showBlog = function(url, opt_noTitle) {
								   var feed = new google.feeds.Feed(url);
								   var preview = this;
								   feed.load(function(result) {
								     preview.renderBlog_(result, opt_noTitle);
								    });
								 }
BlogPreview.prototype.showTwitter = function(url, opt_noTitle) {
									  var feed = new google.feeds.Feed(url);
									  var preview = this;
									  feed.load(function(result) {
									    preview.renderTwitter_(result, opt_noTitle);
									  });
									} 
BlogPreview.prototype.renderBlog_ = function(result, opt_noTitle) {
									    if (!result.feed || !result.feed.entries) return;
	  								    while (this.container_.firstChild) {
	    								  this.container_.removeChild(this.container_.firstChild);
	  								    }
										var blog = this.container_;
										var blog = this.createDiv_(this.container_, "bloque_blog");
										//if (!opt_noTitle) {
										// var header = this.createElement_("h2", blog, "");
										// this.createLink_(header, result.feed.link, result.feed.title);
										//}
										var header = this.createDiv_(blog, "header");
										//var header = this.createElement_("h2", blog, "");
										
										//this.createLink_(header, result.feed.link, "iblog");
										for (var i = 0; i < result.feed.entries.length -1; i++) {
											var entry = result.feed.entries[i];
											var className = "news";
											if (i==3) {
												className += " last_new";
											}
											var div = this.createDiv_(blog, className);
											var linkDiv = this.createSpan_(div, "titlePost", entry.title);
										    //this.createLink_(linkDiv, entry.link, entry.title);
										    //if (entry.author) {
											      //this.createDiv_(div, "author", "Posted by " + entry.author);
											//}
											//  if (entry.publishedDate) {
											//	this.createDiv_(div, "publish", "Fecha publicacion " + entry.publishedDate);
											//  }
										    this.createSpan_(div, "text", entry.contentSnippet);
										    var linkref = this.createLink_(div, entry.link, "+ ver entrada completa");
										    linkref.className = "vermas";
										    var div = this.createDiv_(div, "clearboth");
										}
										linkVerMas = this.createLink_(blog, "http://blog.idominiun.com/", "ir a ibloginiun");
										linkVerMas.className = "vermas_noticias";
									  }
BlogPreview.prototype.renderTwitter_ = function(result, opt_noTitle) {
											if (!result.feed || !result.feed.entries) {
												return;
											}
											while (this.container_.firstChild) {
												this.container_.removeChild(this.container_.firstChild);
											}
											var twitter = this.container_;
											var i = 0;
											var left = this.createDiv_(twitter, "left");
											//iz
											for(i; i< 2;i++) {
												var entry = result.feed.entries[i];
												var className = "tweet";
												if (i==1) {
													className += " last";
												}
												this.createTweet_(entry,left,className);
											}
											//de
											left = this.createDiv_(twitter, "right");
											for(i; i< 4;i++) {
												var entry = result.feed.entries[i];
												var className = "tweet";
												if (i==3) {
													className += " last";
												}
												this.createTweet_(entry,left,className);
											}
											var div = this.createDiv_(twitter, "clearboth");
										}

BlogPreview.prototype.createTweet_ = function(entry,divContendor, divClassName) {
	 									var texto = entry.content;
	    								var tweet = this.createDiv_(divContendor, divClassName);
											
										var link = this.createLink_(tweet, "http://twitter.com/idominiun","idominiun");
										link.className = "autor";
										//tweet.appendChild(document.createTextNode(texto.substring(7)));
										tweet.innerHTML += texto.substring(10);
										var link2 = this.createLink_(tweet, entry.link,"+ ver tweet");
										link2.className = "vermas";
										var fecha = new Date(entry.publishedDate);
										var spandate = this.createSpan_(tweet,"date",fecha.toLocaleDateString()+" "+fecha.toLocaleTimeString());
									 }

BlogPreview.prototype.createDiv_ = function(parent, className, opt_text) {
									  return this.createElement_("div", parent, className, opt_text);
								   }
BlogPreview.prototype.createSpan_ = function(parent, className, opt_text) {
	  								  return this.createElement_("span", 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;
										}

google.load("feeds", "1");
function initialize() {
	//Blog	    
	var url = "http://blog.idominiun.com/rss.php";
	var blog = new BlogPreview(document.getElementById("bloque_blog"));
	blog.showBlog(url,"true");
	//Twitter
	url = "http://twitter.com/statuses/user_timeline/96317017.rss";
	var twitter = new BlogPreview(document.getElementById("home_twitter_center"));
	twitter.showTwitter(url,"true");

}
google.setOnLoadCallback(initialize);
