var closeCommentForm = function()
{
    $('#addNoteComment_form').slideUp('fast');
    $('input#addNoteCommentButton').fadeIn('slow');
}

var toggleActiveStars = function(stars, num)
{
    num = parseInt(num);
    for(i=0; i<=num; i++)
    {
        $(stars[i]).addClass('active');
    }
}

var removeNote = function()
{
    var stars = $('form#addNoteComment_form span.star');
    var note = $('form#addNoteComment_form input#product_note');
    var link = $('form#addNoteComment_form tr.stars td.link a');
    
    stars.removeClass('active');
    note.val(0);
    link.addClass('hide');
}

$(document).ready(function ()
{
    var stars = $('form#addNoteComment_form span.star');
    var note = $('form#addNoteComment_form input#product_note');
    var link = $('form#addNoteComment_form tr.stars td.link a');
    
    stars.each(function(i, star){
        star = $(star);
        
        star.addClass('star-'+i);
        
        star.mouseover(function(){
            stars.removeClass('active');
            toggleActiveStars(stars, i);
        });
        
        star.mouseout(function(){
            var noteValue = parseInt(note.val());
            stars.removeClass('active');
            if(noteValue>0)
                toggleActiveStars(stars, noteValue-1);
        });
        
        star.mouseup(function(){
            stars.removeClass('active');
            toggleActiveStars(stars, i);
            note.val(parseInt(i)+1);
            link.removeClass('hide');
        });
    });
    
    stars.removeClass('active');
});
