
var articulos_actuales_marcados = 'recientes';

function cambiar_articulos(valor)
{
	articulos_actuales = articulos_actuales_marcados;
	
	var tab_actual = document.getElementById('articulos_' + articulos_actuales);
	var tab_visible = document.getElementById('articulos_' + valor);
	
	tab_actual.style.display = 'none'; tab_visible.style.display = 'block';
	
	var tabs_actuales = document.getElementById('tabs_articulos_' + articulos_actuales);
	var tabs_visible = document.getElementById('tabs_articulos_' + valor);
	
	tabs_actuales.className = 'enlace';	tabs_visible.className = 'visible';

	articulos_actuales_marcados = valor;
}

function string_create_urls(input){
	return input.replace(/(ftp|http|https|file):\/\/[\S]+(\b|$)/gim,
		'<a href="$&" class="my_link" target="_blank">$&</a>').replace(/([^\/])(www[\S]+(\b|$))/gim,
		'$1<a href="http://$2" class="my_link" target="_blank">$2</a>');
}

function pinta_titulo(input){
	
   var titulo=String((input)).substring(16, String(input).length);
   return string_create_urls(titulo);
}

function pinta_autor(input){
	
   var autor=String((input)).substring(String(input).indexOf("(")+1, String(input).indexOf(")"));
   var autorTwitter=String((input)).substring(0, String(input).indexOf("("));
	
	return "<a href=\"http://twitter.com/" + autorTwitter + "\" target=\"_BLANK\" rel=\"nofollow\">" + autor + "</a>";
    //return autor;
}

function fecha(entry){
	var entrydate=new Date(entry.publishedDate);
	var entrydatestr=checkTime(entrydate.getDate())+"/"+checkTime(entrydate.getMonth()+1)+"/"+entrydate.getFullYear()+" "+checkTime(entrydate.getHours())+":"+checkTime(entrydate.getMinutes());
	return entrydatestr;
}

function checkTime(i){
	if (i<10) 
		{i="0" + i}
	return i
}

function grabThumb(thumbNodes) {
	var ti = 0;
	var node = thumbNodes[ti];
	var thumb = null;
	var attr = node.getAttributeNode("url");
	if (attr != null) {
		thumb = node.getAttributeNode("url").nodeValue;
	} else {
		thumb = node.firstChild.nodeValue;
	}
	return thumb;
};
    function loadTwitter() {
	var feed = new google.feeds.Feed("http://search.twitter.com/search.atom?q=@compradoronline+he+comprado");
	//var feed = new google.feeds.Feed("http://search.twitter.com/search.atom?lang=es&q=%23comprador");
		
	feed.setNumEntries(5);
	feed.load(function(result) {
		var container = document.getElementById("twitterss");
		if (!result.error) {
			var entries=result.feed.entries;
			var html="";
			var clase="";
			for(var i=0; i<entries.length; i++){
				if((i%2)==0)
					clase="";
				else
					clase="alrow";
					
				var entry = entries[i];
				//alert(entry.title);
				//alert(entry.link); //http://twitter.com/seguros_medicos/statuses/1146537928
				//alert(entry.title);
				//alert(entry.author);
				//var titulo=String((entry.title)).substring(String(entry.title).indexOf(":")+1);

				html+="<p>"+pinta_titulo(entry.title)+"<br/> <span class=\"itemMetaFeed\"> por "+pinta_autor(entry.author)+" - " + fecha(entries[i])+"</span></p>";
			}
			container.innerHTML=html;
		}else{
			container.innerHTML="<p>Error cargando el feed</p>";
		}
	}
	)
  }

var usertwitter="compradoronline";

function showred(mostrarred){

	document.getElementById("div_"+mostrarred).style.display='';
}

function OnLoad() {
	showred("twitterss");	
	if(usertwitter!="") loadTwitter();
}


