﻿$(function() {
    $('form').attr('action', '');

    $('h4').click(function() {				   
		$(this).prev('div').fadeIn('500');
    });
	
	$('.newcommentform span').click(function() {				   
		$(this).parent('div').fadeOut('1000');
    });

    $('.newcommentform .submit').click(function() {
        var itemid = $(this).next('input#itemid').val();
		var userid = $(this).next().next('input#userid').val();
        var thisParam = $(this);
        var comment = $(this).prev('input').val();

        $.ajax({
            type: 'post',
            url: 'insertcomment.php',
            data: 'comment=' + comment + '&iid=' + itemid + '&uid=' + userid,

            success: function(createcomment) {
                var newcomment = '<div class=comment><span class=commenter>You:</span> ' + comment + '</div>';
				$(thisParam).parent().parent('div').before(newcomment).fadeIn('1000');
				$('input').parent().parent('div').hide();
            }

        });

    });
	
	$('.comment img').click(function() {
        var commentid = $(this).parent('div').find('img').attr('id');
		var thisParam = $(this);

        $.ajax({
            type: 'post',
            url: 'deletecomment.php',
            data: 'dcid=' + commentid,

            success: function(deletecomment) {
                $(thisParam).parent('div').fadeOut('500');
				
            }

        });
								
		
    });

});
	