﻿function setUpStars() {
    
    var ratedStars = jQuery('.rated_star');
    ratedStars.each(function(item) {
        jQuery(item).mouseover(function (event) {

			var img = event.target;

			var list = jQuery(img).parent('li').parent('ul');

			var nextList = jQuery(list).next('ul');

			//if this star has a list of rating_star with it (i.e. it can be rated)
			if (nextList != 'undefined') {
				var thisId = parseInt(img.id.substring(img.id.length - 1));

				nextList.children().each(function (index, item) {

					var itemImg = jQuery(item).children().children()[0];

					var id = parseInt(itemImg.id.substring(itemImg.id.length - 1));
					if (id <= thisId) {
						itemImg.src = ratingStar;
					} else {
						itemImg.src = offStar;
					}
				});

				nextList.show();
				list.hide();
			}
		});
    });

    var ratingStars = jQuery('.rating_star');
    ratingStars.each(function(index, item) {
        jQuery(item).mouseout(function(event) {
		var list = jQuery(event.target).parents('ul');

		list.prev().show();
		list.hide();
        });
    });

    jQuery('.rating_list').each(function(index, item) {
        jQuery(item).hide();
    });
}
    

