$( function () {
    $('.smile_a').click(function (e) {
        var el = $(e.currentTarget);
        var quote_id = el.attr('quote');
        var score = el.attr('score');
        var url = "/like/quote/" + quote_id + "/?score=" + score;
        $.get(url, function(r) {
            $('#score_' + quote_id).html(r);
            var smiles = el.parent().find('.smile_a').each(function (i, smile) {
                var smile = $(smile);
                if (smile.attr("score") != score) {
                    var img = $(smile.children()[0]);
                    img.attr('src', img.attr('src').replace('.gif', '_grey.gif'));
                }
            });
        });
        return false;

    });
    $('.report').click(function (e) {
        var el = $(e.currentTarget);
        var model_id = el.attr('model_id');
        var model = el.attr('model');
        var url = "/quotes/report/" + model + "/" + model_id + "/";
        $.get(url, function (r) {
            el.parent().html('Reported');
        });
        return false;
    });
    $('.closewm').click(function (e) {
        $('#welcomeBg').hide();
        $.get('/profile/hidewm/');
        return false;
    });


    $('.comment_quote').click(function (e) {
        var el = $(e.currentTarget);
        var text = el.attr('comment_text');
        var i = $('#addComment');
        i.html(i.html() + text + '\n');
    });
   $('.happy img,strong').mouseover(function (e) {
        var el = $(e.currentTarget);
        if (el.attr('title') == "") {
            el = $(el.children()[0]);
        }
        $('#tooltip').html(el.attr('title')).show();
        return false;

    }).mouseleave(function (e) {
        $('#tooltip').hide();

    }).mousemove(function (e) {
        var coords = {top:e.pageY + 15, left:e.pageX + 15};
        $('#tooltip').css(coords);
        return false;
    });
    
        
    $('.happy a,strong').tooltip({
        track: true,
        delay: 0,
        showURL: false,
        showBody: " - ",
        fade: 250
    });

    $('.like_quote').click(function (e) {
        var el = $(e.currentTarget);
        var quote_id = el.attr('quote');
        var url = "/like/quote/" + quote_id + "/"
        $.get(url, function (r) {
            $('#score_' + quote_id).html(r);
            el.parent().html('Liked')
        });
        return false;
    });
    $('.like_comment').click(function (e) {
        var el = $(e.currentTarget);
        var comment_id = el.attr('comment');
        var url = "/like/comment/" + comment_id + "/"
        $.get(url);
        $(e.currentTarget).parent().html('Liked')
        return false;
    });
    $('.add_fav').click(function (e) {
        var el = $(e.currentTarget);
        var quote_id = el.attr('quote');
        var url = "/profile/favorites/add/" + quote_id + "/"
        $.get(url);
        el.parent('.fav_span').hide()
        el.hide()
        return false;
    });
});

