﻿function mouseOverHalfStar() {
    $(this).parent().find("span").each(function() {
        if (this.isHalfStar) {
            $(this).removeClass($(this).parent().parent().attr("HalfStarCssClass"));
        }
    });
}

function mouseOutHalfStar() {
    $(this).parent().find("span").each(function() {
        if (this.isHalfStar) {
            $(this).addClass($(this).parent().parent().attr("HalfStarCssClass"));
        }
    });
}

function pageLoad() {
    $("span.rating>div").each(function() {
        var ratingCtrlId = this.id;
        var isUserLogged = $(this).attr("isUserLogged");
        var halfStarNumber = $(this).attr("halfStarNumber");
        $("#" + ratingCtrlId + " > a").each(function() {
            if ($find(ratingCtrlId + "_RatingExtender").get_ReadOnly()) {
                var rate = this.title;
                if (rate == 0) {
                    this.title = "Non ancora votato";
                }
                else if (rate == 1) {
                    this.title = "Voto 1 stella";
                }
                else if (rate > 1) {
                    var toolTip = "Voto ~value~ stelle";
                    this.title = toolTip.replace(/~value~/g, rate);
                }
            }
            else {
                $(this).find("span").each(function() {
                    var rate = this.value;
                    if (isUserLogged == 1) {
                        if (rate == 1)
                            this.title = "Clicca per votare 1 stella";
                        else if (rate > 1) {
                            var toolTip = "Clicca per votare ~value~ stelle";
                            this.title = toolTip.replace(/~value~/g, rate);
                        }
                    }
                    else {
                        this.title = "Per assegnare un voto devi essere registrato";
                    }
                    $(this).hover(mouseOverHalfStar, mouseOutHalfStar);
                });
            }

            $(this).find("span").each(function() {
                var rate = this.value;
                this.isHalfStar = rate == halfStarNumber;

                if (rate == halfStarNumber) {
                    $(this).addClass($(this).parent().parent().attr("HalfStarCssClass"));
                }
            });
        });
    });
}

