/* vim:set expandtab tabstop=4 shiftwidth=4: */

var Twitter    = Class.create();

Twitter.updateCounter = function() {
    new Ajax.Updater(
        'twitterCount',
        '/maps/update', {
            asynchronous: true,
            evalScripts:  true,
            onSuccess:    function(request) {
                new Effect.Shake('twitterCount',{});
            }
        }
    );
}

Twitter.update = function(delay) {
    setTimeout("Twitter.updateCounter();", delay);
}

Twitter.showtip = function(s) {
    l = $('likebox');
    l.update(s + ' this post');
    l.style.backgroundImage = "url('images/"+ s + ".png')";
    l.style.display = 'inline';
    l.style.opacity = 0.9;
}

Twitter.like = function(s, id) {
    new Ajax.Request( '/user_feedback/update?like=1&id='+id, {method : 'post'});
    l = $('likebox');
    l.update("liking " + s);
    l.style.backgroundImage = "url('images/like.png')";
    l.style.display = 'inline';
    setTimeout("new Effect.Fade('likebox')", 1200);
}

Twitter.dislike = function(s, id) {
    new Ajax.Request( '/user_feedback/update?like=-1&id='+id, {method : 'post'});
    l.update("disliking " + s);
    l.style.backgroundImage = "url('images/dislike.png')";
    l.style.display         = 'inline';
    setTimeout("new Effect.Fade('likebox')", 1200);
}

Twitter.savePref = function(e) {
    // Get the form parameters, then disable the form
    var parameters = Form.serialize('pref');

    new Ajax.Request('user/save_preferences', {
        asynchronous: true,
        evalScripts:  true,
        onSuccess:    function(request) {
            new Effect.Fade("preferences",{});
        },
        parameters:Form.serialize(this)
    });

    // Stop form from submitting when JavaScript is enabled
    Event.stop(e);
}


