$(document).ready(function(){
	$("#twittiza").getTwitter();

});


/*!
 * liScroll 1.0
 * Examples and documentation at: 
 * http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html
 * 2007-2010 Gian Carlo Mingati
 * Version: 1.0.2 (30-MARCH-2009)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires:
 * jQuery v1.2.x or later
 * Modificaciones por ze
 */

jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.07
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
				$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).width(); //outerWidth(true); // thanks to Michael Haszprunar
				});
				$strip.width(stripWidth);			
				var totalTravel = stripWidth+containerWidth;
				var defTiming = totalTravel/settings.travelocity;	// thanks to Scott Waye		
				function scrollnews(spazio, tempo){
				$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);				
				$strip.hover(function(){
				jQuery(this).stop();
				},
				function(){
				var offset = jQuery(this).offset();
				var residualSpace = offset.left + stripWidth;
				var residualTime = residualSpace/settings.travelocity;
				scrollnews(residualSpace, residualTime);
				});			
		});	
};




(function($) {
	/*	jquery.twitter.js v1.5
		Last updated: 08 July 2009

		Created by Damien du Toit
		http://coda.co.za/blog/2008/10/26/jquery-plugin-for-twitter

		Licensed under a Creative Commons Attribution-Non-Commercial 3.0 Unported License
		http://creativecommons.org/licenses/by-nc/3.0/
		
		mod by ze
	*/

	$.fn.getTwitter = function(options) 
	{	$.fn.getTwitter.defaults = {
			userName: "aliadodigital",
			numTweets: 5,
			loaderText: "Cargando tweets...",
			slideIn: false,
			slideDuration: 750,
			showHeading: false,
			headingText: "Tweets Recientes",
			showProfileLink: false,
			showTimestamp: false
		};
		var o = $.extend({}, $.fn.getTwitter.defaults, options);
		return this.each(function() 
		{	var c = $(this);
			c.hide().empty().addClass("twitted");										// hide container element, remove alternative content, and add class
			c.append("<ul id=\"twitter_update_list\"><li></li></ul>");					// add twitter list to container element
			var tl = $("#twitter_update_list");
			tl.hide();																	// hide twitter list
			var preLoaderHTML = $("<p class=\"preLoader\">"+o.loaderText+"</p>");		// add preLoader to container element
			c.append(preLoaderHTML);
			c.show();																	// show container element
			$.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();												// remove preLoader from container element
				if (!o.showTimestamp) 													// remove timestamp and move to title of list item
				{	tl.find("li").each(function() {
						var timestampHTML = $(this).children("a");
						var timestamp = timestampHTML.html();
						timestampHTML.remove();
						if(timestamp)	{	timestamp = timestamp.replace(/about/,'hace');	//about 15 hours ago
											timestamp = timestamp.replace(/hours ago/,'horas');	
										} else {timestamp=''; }
						otrolnk=$(this); 
						lnk=otrolnk.children("span").children("a").attr('href');	
						txt=otrolnk.children("span").text().replace(/:.*?$/,'');	
						$(this).html('<a href="'+lnk+'" title="'+timestamp+'">'+txt+'</a>');
					});
				}
				tl.show();
				tl.find("li:first").addClass("firstTweet");								// add unique class to first list item
				tl.find("li:last").addClass("lastTweet");								// add unique class to last list item
				tw=$('#twitter').html();
				$('ul#twitter_update_list').liScroll(); 
				
			});
		});
	};
})(jQuery);
