function startTip() {
				
    $('logo').store('tip:title', "Ir al inicio");
    $('logo').store('tip:text', "Haz click para volver a la p&aacute;gina de inicio de Chocolates de La Abuela");
				

    var SimpleTip = new Tips($('logo'), {
				  
        fixed: false,
        offsets:{
            x:125,
            y:200
        },
        hideDelay: 50,
        showDelay: 50

    });
    SimpleTip.addEvents({
        'show': function(tip) {
            tip.fade('in');
        },
        'hide': function(tip) {
            tip.fade('out');
        }
    });

				
}

Request.Twitter = new Class({

    Extends: Request.JSONP,

    options: {
        linkify: true,
        url: 'http://twitter.com/statuses/user_timeline/{term}.json',
        data: {
            count: 5
        }
    },

    initialize: function(term, options){
        this.parent(options);
        this.options.url = this.options.url.substitute({
            term: term
        });
    },

    success: function(data, script){
        var tweets = data[0];
        if (this.options.linkify) tweets.each(function(tweet){
            tweet.text = this.linkify(tweet.text);
        }, this);

        if (data[0]) this.options.data.since_id = tweets[0].id; // keep subsequent calls newer

        this.parent(data, script);
    },

    linkify: function(text){
        // modified from TwitterGitter by David Walsh (davidwalsh.name)
        // courtesy of Jeremy Parrish (rrish.org)
        return text.replace(/(https?:\/\/[\w\-:;?&=+.%#\/]+[\w\-:;?&=+%#\/])/gi, '<a href="$1">$1</a>')
        .replace(/(^|\W)@(\w+)/g, '$1<a href="http://twitter.com/$2">@$2</a>')
        .replace(/(^|\W)#(\w+)/g, '$1#<a href="http://search.twitter.com/search?q=%23$2">$2</a>');
    }

});

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 'hace menos de un minuto';
    }
    else
    if (delta < 120) {
        return 'hace un minuto';
    }
    else
    if (delta < (60 * 60)) {
        return 'hace ' + (parseInt(delta / 60)).toString() + ' minutos';
    }
    else
    if (delta < (120 * 60)) {
        return 'hace una hora';
    }
    else
    if (delta < (24 * 60 * 60)) {
        return 'hace ' + (parseInt(delta / 3600)).toString() + ' horas';
    }
    else
    if (delta < (48 * 60 * 60)) {
        return 'hace un día';
    }
    else {
        return 'hace ' + (parseInt(delta / 86400)).toString() + ' días';
    }
}
		
window.addEvent('domready', function(){
    startTip();
    new Request.Twitter('chocAbuela',{
        data:{
            count: 2
        },
        onComplete: function(tweets){
            var contenedor = $('twitter_update_list');
            contenedor.empty();
            tweets.each(function(tweet){
                var texto = tweet.text;
                texto += ' <a style="font-size:85%" href="http://twitter.com/' + tweet.user.screen_name + '/statuses/' + tweet.id + '">' + relative_time(tweet.created_at) + '</a>';
                var item = new Element('li',{
                    'html': texto
                });
                item.inject(contenedor);
            });
        }
    }).send();
});
