﻿var userRatingId;
var voteButtonId;

$(document).ready(function() {

    //Comment section sliding up/down
    $("#Comments h4").click(function(event) {
        var $self = $(this);

        $self.next(".entries-video-comments-body").slideToggle(500, function() { $self.parent().toggleClass("closed-comments") })
        event.preventDefault()
        return false
    })

    $("#NotYetVoted input[type=image]").live({
        mouseenter: function() {
            var rating = $(this).attr("rel");
            updateRating(rating);
        },
        mouseleave: function() {
            var currentRating = $("#" + userRatingId).val();
            updateRating(currentRating);
        },
        click: function() {
            var rating = $(this).attr("rel");
            $("#" + userRatingId).val(rating);
        }
    });

    /*
    //Reset if not voted yet
    $("#" + userRatingId).val("0");

    //$(".entries-video-comments-body .stars img").hover(
    $("#NotYetVoted img").hover(
    function() {
    var rating = $(this).attr("rel");
    console.log(rating);
    updateRating(rating);
    //$("#" + userRatingId).val(rating);
    $("#" + voteButtonId).removeAttr("disabled");
    //alert("1");
    },
    function() {
    var currentRating = $("#" + userRatingId).val();
    console.log(currentRating);
    updateRating(currentRating);
    }
    ).click(function() {
    var rating = $(this).attr("rel");
    $("#" + userRatingId).val(rating);
    __doPostBack(userRatingId, '');
    });
    */
});

var blankStar = "/VideoContest/Images/large-star-blank.png";
var filledStar = "/VideoContest/Images/large-star-filled.png";

function updateRating(rating) {
    //$(".entries-video-comments-body .stars img").each(function() {
    $("#NotYetVoted input[type=image]").each(function() {
        var current = $(this).attr("rel");
        //console.log("rating=" + rating + ", current=" + current);
        if (current <= rating) {
            $(this).attr("src", filledStar);
        } else {
            $(this).attr("src", blankStar);
        }
    });
}

/*
function validateRating(ctl, args) {
    var val = $("#" + userRatingId).val();
    args.IsValid = (val != "0");
}
*/


