function hoverStars(){
    $('div.rating_stars a.vote-link').hover(
        function(){ //on over
            $(this).removeClass('empty').addClass('full');
            $(this).prevAll().removeClass('empty').addClass('full');
            $(this).nextAll().removeClass('full').addClass('empty');
        },
        function() { //on out
        }
    );

    $('div.rating_stars').mouseleave( function() {
        restoreStars();
    });
}

function restoreStars(){
    var a_stop = $('div.rating_stars a.stop');
    // when a.stop doesn't exist it means revert all stars to full
    if(a_stop.length == 0){
        $('div.rating_stars a.vote-link').removeClass('empty').addClass('full');
    } else{
        a_stop.prevAll().removeClass('empty').addClass('full');
        a_stop.nextAll().removeClass('full').addClass('empty');
        a_stop.removeClass('full').addClass('empty');
    }
}

function noteSelection() {

    $("#noteList li").click( function() {
        if( !$(this).hasClass('main') ){
            document.location = $(this).children("a").attr('href');
        }
        $(this).removeClass('hover');

        if( $(this).hasClass('selected') &&  ! $("#noteList").hasClass('expand') ) {
            $("#noteList").addClass('expand');
            $("#noteList li").removeClass('hide');

            return false; //stop bubbling li click -> body click ( check below on body.click() )
        }
    });

    $("#noteList li").hover( function() {
        if( !$("#noteList").hasClass('expand') ) {
            return;
        }

        $(this).addClass('hover');
    },
    function() {
        $(this).removeClass('hover');
    });

    $("#noteList .expand-list").click( function() {
        if( $("#noteList").hasClass('expand') ) {
            $("#noteList").removeClass('expand');
            $("#noteList li").addClass('hide');
        }
        else{
            $("#noteList").addClass('expand');
            $("#noteList li").removeClass('hide');
        }

        return false; //stop bubbling
    });

    $("body").click( function() {
        if( $("#noteList").hasClass('expand') ) {
            $("#noteList").removeClass('expand');
            $("#noteList li:not(.selected)").addClass('hide');
        }
    });
}

$(document).ready( function() {
       noteSelection();
       hoverStars();
});
