var Skillopedia_Rating = function(stars, element, current_not_voted)
{
    this.current_not_voted = current_not_voted;
	this.Stars   = stars;
    this.Element = element;

    this.vote = function(quantity, self)
    {
        this.current_not_voted = false;
		JsHttpRequest.query(
            '_parts/rating/vote.php',
            {
                'entity': this.Element,
                'vote': quantity
            },
            function(result, data)
            {
                if (result === false)
                {
                    alert(data);
                    return;
                }

                rating.setStars(result);
                votes = document.getElementById('votes-number');
                votes.innerHTML = parseFloat(votes.innerHTML) + 1;

                for (i=1; i < 6; i++) {
                    star = document.getElementById('star-'+i);
                    star.onclick = function(){ };
                    star.parentNode.onmouseover = function(){ };
                }

            },
            true
        );
    }

    this.setStars = function(amount)
    {
        this.Stars = amount;
        this.redraw(this.Stars);
    }

    this.redraw = function(amount, clear)
    {
        for ( i=1; i < 6; i++ ) {
            star = document.getElementById('star-'+i);

			if (clear) {
				star.src = '_images/common/big_star_inactive.png';
			} else {
	            if (i <= amount) star.src = '_images/common/big_star_active.png';
    	        else star.src = '_images/common/big_star_inactive.png';
        	}
        }
    }

    this.highlight = function(amount)
    {
        this.redraw(amount);
        document.getElementById('rating_watches').style.display = 'none';
        var value = new Array('', 'Плохо', 'Ничего особенного', 'Стоит посмотреть', 'Хорошо', 'Супер');
        document.getElementById('rating_text').innerHTML = value[amount];
    }

    this.unhighlight = function()
    {

		this.redraw(this.Stars, this.current_not_voted);
        document.getElementById('rating_watches').style.display = 'block';
        document.getElementById('rating_text').innerHTML = '&nbsp;';
    }
}

