function twitterCallback2(twitters) {
  var statusHTML = [];
  for (var i=0; i<twitters.length; i++){
    var username = twitters[i].user.screen_name;
    var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
      return '<a href="'+url+'">'+url+'</a>';
    }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
      return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
    });
    statusHTML.push('<li><span>'+status+'</span> <a style="font-size:85%" href="http://twitter.com/'+username+'/statuses/'+twitters[i].id_str+'">'+relative_time(twitters[i].created_at)+'</a></li>');
  }
  document.getElementById('twitter_update_list').innerHTML = statusHTML.join('');
}

function relative_time(time_value) {
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
  var parsed_date = Date.parse(time_value);
  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
  delta = delta + (relative_to.getTimezoneOffset() * 60);

  if (delta < 60) {
    return 'less than a minute ago';
  } else if(delta < 120) {
    return 'about a minute ago';
  } else if(delta < (60*60)) {
    return (parseInt(delta / 60)).toString() + ' minutes ago';
  } else if(delta < (120*60)) {
    return 'about an hour ago';
  } else if(delta < (24*60*60)) {
    return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
  } else if(delta < (48*60*60)) {
    return '1 day ago';
  } else {
    return (parseInt(delta / 86400)).toString() + ' days ago';
  }
}

$(document).ready(function() {
	$('div#LoginFecha').click(function(){
		$('div#MenuTextos').animate({
			height: '300px'
		})
		.animate({
			height: '200px'
		}, 'fast', function() {
				$('div#LoginCerrar').show();
			});
		$('div#LoginFecha').toggle();
	});	
	$('div#LoginCerrar').click(function(){
		$('div#LoginCerrar').hide();
		$('div#MenuTextos').animate({
			height: '20px'
		}, 'fast', function() {
				$('div#LoginFecha').slideDown('fast');
			});
	});
	
	$('.SliderFlecha').click(function(){
		$('div#NewSlider').animate({
			height: '261px'
		})
		.animate({
			height: '0px'
		}, 'fast', function() {
				$('.SliderFlechaCerrar').show();
			});
		$('.SliderFlecha').toggle();
	});	
	$('.SliderFlechaCerrar').click(function(){
		$('.SliderFlechaCerrar').hide();
		$('div#NewSlider').animate({
			height: '261px'
		}, 'fast', function() {
				$('.SliderFlecha').show();
			});
	});	
	
	$('div#FechaTwitter').click(function(){
		$('div#Twitter').animate({
			height: '120px'
		})
		.animate({
			height: '120px'
		}, 'fast', function() {
				$('div#CerrarTwitter').show();
				Twitter();				
			});
		$('div#FechaTwitter').toggle();
	});	
	$('div#CerrarTwitter').click(function(){
		$('div#Twits').hide();
		$('div#CerrarTwitter').hide();
		$('div#Twitter').animate({
			height: '0px'
		}, 'fast', function() {
				$('div#FechaTwitter').slideDown('fast');
			});
	});		
});

function Twitter() {
	$("#Twits").getTwitter({
		userName: "binamico",
		numTweets: 5,
		loaderText: "Cargando tweets...",
		slideIn: true,
		slideDuration: 750,
		showHeading: false,
		headingText: "Últimos Tweets",
		showProfileLink: false,
		showTimestamp: true
	});
}
	
(function($) {

	$.fn.getTwitter = function(options) {

		$.fn.getTwitter.defaults = {
			userName: null,
			numTweets: 5,
			loaderText: "Cargando tweets...",
			slideIn: true,
			slideDuration: 750,
			showHeading: true,
			headingText: "Últimos Tweets",
			showProfileLink: false,
			showTimestamp: true
		};

		var o = $.extend({}, $.fn.getTwitter.defaults, options);

		return this.each(function() {
			var c = $(this);

			c.hide().empty().addClass("twitted");
			if (o.showHeading) {
				c.append("<h2>"+o.headingText+"</h2>");
			}
			var twitterListHTML = "<ul id=\"twitter_update_list\"><li></li></ul>";
			c.append(twitterListHTML);

			var tl = $("#twitter_update_list");

			tl.hide();

			var preLoaderHTML = $("<p class='preLoader'>"+o.loaderText+"</p>");
			c.append(preLoaderHTML);

			if (o.showProfileLink) {
				var profileLinkHTML = "<p class=\"profileLink\"><a href=\"http://twitter.com/"+o.userName+"\">http://twitter.com/"+o.userName+"</a></p>";
				c.append(profileLinkHTML);
			}

			c.show();

			//$.getScript("http://twitter.com/javascripts/blogger.js");
			$.getScript("http://twitter.com/statuses/user_timeline/"+o.userName+".json?callback=twitterCallback2&count="+o.numTweets, function() {
				$(preLoaderHTML).remove();

				if (!o.showTimestamp) {
					tl.find("li").each(function() {
						var timestampHTML = $(this).children("a");
						var timestamp = timestampHTML.html();
						timestampHTML.remove();
						$(this).attr("title", timestamp);
					});
				}

				if (o.slideIn) {
					var tlHeight = tl.data("originalHeight");

					if (!tlHeight) {
						tlHeight = tl.show().height();
						tl.data("originalHeight", tlHeight);
						tl.hide().css({height: 0});
					}

					tl.show().animate({height: tlHeight}, o.slideDuration);
				}
				else {
					tl.show();
				}

				tl.find("li:first").addClass("firstTweet");

				tl.find("li:last").addClass("lastTweet");
			});
		});
	};
})(jQuery);












(function($) {
	var opts = new Array;
	var level = new Array;
	
	$.fn.jqIsoText = $.fn.jqisotext = function(options){
	
	init = function(el){

		opts[el.id] = $.extend({}, $.fn.jqIsoText.defaults, options);

		text = el.firstChild.nodeValue;
		$(el).html('');

		if(opts[el.id].split != 'yes') { 
			$.le(text,el);
		} else {
			// word spliting
			t = text.split(' ');
			for (var tt in t){
				$.le(t[tt]+' ',el);
			}
		}		

	};
		
	$.le = function(text,ths){
		
		inc = 1;
		len = text.length;

		for(i=0;i<len;i++){
			letter = text.slice(i,i+1);
			if(i<len/2) 
				j=i; 
			else 
				j=len-i-1;

			meml = (opts[ths.id].fromSize-opts[ths.id].toSize)/(len/2);
			if (letter == ' ') letter = "&nbsp;";
			$("<span style='font-size:"+parseInt(opts[ths.id].fromSize-j*meml)+"px'>"+letter+"</span>").appendTo(ths);

		}
	}

	this.each (
		function()
		{ init(this); }
	)
	
};

	// default values
	$.fn.jqIsoText.defaults = {	
		fromSize: 15,
		toSize	: 40,
		split	: 'no'
	};

})(jQuery);
