
var UT_RATING_IMG       = 'http://s3.moveon.org/obama/images/star_gold.gif'
var UT_RATING_IMG_HOVER = 'http://s3.moveon.org/obama/images/star_gold.gif';
var UT_RATING_IMG_BG    = 'http://s3.moveon.org/obama/images/star_grey.gif'

var maxStars = 4;

// pre-fetch images
(new Image()).src = UT_RATING_IMG;

function showStars(el, starNum) {
    clearStarTimer(el);
    greyStars(el);
    colorStars(el,starNum);
}

function colorStars(el,starNum) {
    for (var i=0; i < starNum; i++) {
        $(el).find('.star_' + (i+1)).attr('src', UT_RATING_IMG);
    }
}

function greyStars(el) {
    for (var i=0; i < maxStars; i++) {
        //if (i <= this.starCount) {
            $(el).find('.star_' + (i+1)).attr('src', UT_RATING_IMG_BG);
        //} else {
        //    this.element.find('.star_' + (i+1)).src = UT_RATING_IMG_BG;
        //}
    }
}

function setStars(el,starNum) {
    el.starCount = starNum;
    drawStars(el,starNum);
    showStars(el,starNum, 1);
}


function drawStars(el,starNum) {
    $(el).attr('starCount',starNum);
}

function clearStars(el) {
    resetStars(el);
    // starTimer = setTimeout(function() { resetStars(el); });
}

function resetStars(el) {
    clearStarTimer(el);
    var sc = $(el).attr('starCount');
    if ( sc ) {
        drawStars(el,sc);
        showStars(el,sc);
    } else {
        greyStars(el);
    }
}

function clearStarTimer(el) {
    if (el.starTimer) {
        clearTimeout(el.starTimer);
        el.starTimer = null;
    }
}

