// JavaScript Document

$(document).ready(function() {

    $('iframe').attr('allowTransparency', 'true');
							   
    $('span.post_vote img.pvote_btn').click(function() {
        var id = $(this).parent().attr("id").split("_")[1];
        $.post("http://rhymr.net/vote", {
                id: id,
                type: 'post'
            },
            function(pcount){
                $('#vote_counter').hide();
                $('span.post_vote img').hide();
                $('#vote_counter').html(pcount).fadeIn("slow");
                $('span.post_vote').html('<img src="/images/btns/liked.gif" alt="post vote"/>');
                $('span.post_vote img').fadeIn(100);
            });
    });
    $('div.joint_vote img').click(function() {

        var id = $(this).parent().attr("id").split("_")[1];
        var v_type = $(this).attr('class');
        var r_type = v_type=='up' ? 'down' : 'up';
        if(!$(this).hasClass('selected')){
            $.post("http://rhymr.net/vote", {
                id: id,
                type: v_type
            },
            function(jcount){
                $('#j_'+id).find('img.'+v_type).attr('src', '/images/btns/rate_'+v_type+'_dis.gif').addClass('selected');
                $('#j_'+id).find('img.'+r_type).attr('src', '/images/btns/rate_'+r_type+'.gif').removeClass('selected');
                $('span.jcount', '#j_'+id).html(jcount);
                
            });
        }
    });
   hj = function(){
                $('.joint').hover(function(){
        $(this).children('.joint_text').addClass('j_border');
        $(this).children('.joint_info').show();
    },
    function(){
        $(this).children('.joint_text').removeClass('j_border');
        $(this).children('.joint_info').hide();
    }
    )}
    hj();

    $('.add_jbtn').click(function(){
        $('#add_joint').slideToggle(200);
    })

});

function showModal(name)
{
    $('.'+name).fadeIn(200);
}

function hideModal(name)
{
    $('.'+name).fadeOut(200);
}

function delete_comment(id, p)
{
    $.ajax({
        url: "/delete_comment",
        type: "POST",
        dataType: "html",
        data: {
            id:id,
            p:p
        },
        beforeSend: function(){
            $('#c_'+id).html('<img style="float:right" src="/images/load.gif"/>');
        },
        success: function(html) {
            $('#c_'+id).parents(".comment").slideUp(250, function(){
                $('#c_'+id).parents(".comment").remove();
            });
				
        }
    });
}
