$(document).ready(function(){
    $('.fave-img').hover(function() { $(this).attr('src','/images/faved.gif'); }, function() { $(this).attr('src','/images/fave.gif'); });
    $('.flag-img').hover(function() { $(this).attr('src','/images/flagd.gif'); }, function() { $(this).attr('src','/images/flag.gif'); });
    $('.fb-img').hover(function() { $(this).attr('src','/images/fbd.gif'); }, function() { $(this).attr('src','/images/fb.gif'); });
    $('.link-img').hover(function() { $(this).attr('src','/images/linkd.gif'); }, function() { $(this).attr('src','/images/link.gif'); });
    $('.twit-img').hover(function() { $(this).attr('src','/images/twitd.gif'); }, function() { $(this).attr('src','/images/twit.gif'); });
    $('.vote-img').hover(function() { $(this).attr('src','/images/voted.gif'); }, function() { $(this).attr('src','/images/vote.gif'); });

    $('.profile-submit').click(function() {
        
        var dataString = $('#formprofile').serialize();
        var parent = $(this);

        $(this).attr('disabled', true);
            $.ajax({
                type: 'POST',
                url: '/saveprofile.php',
                data: dataString,
                cache: false,
                success: function() { $('#profile-submit-message').html('Saved.'); }
        });
        $(this).removeAttr('disabled', 'disabled');
 
        return false;
    });
    $('.fave').click(function() {
        var dataString = 'id=' + $(this).attr('id');
        var parent = $(this);

        if ($(this).attr('name') == 'fave') {
            $.ajax({
                type: 'POST',
                url: '/savefave.php',
                data: dataString,
                cache: false,
                success: function(html){ parent.html(html); }
            });
        }
        return false;
    });

    $('.flag').click(function() {
        var dataString = 'id=' + $(this).attr('id');
        var parent = $(this);

        if ($(this).attr('name') == 'flag') {
            $.ajax({
                type: 'POST',
                url: '/saveflag.php',
                data: dataString,
                cache: false,
                success: function(html){ parent.html(html); }
            });
        }
        return false;
    });

    $('.vote').click(function() {
        var dataString = 'id=' + $(this).attr('id');
        var parent = $(this);

        if ($(this).attr('name') == 'vote') {
            $.ajax({
                type: 'POST',
                url: '/savevote.php',
                data: dataString,
                cache: false,
                success: function(html){ parent.html(html); }
            });
        }
        return false;
    });
});
