
   window.addEvent(
      'domready',
      function() {

         $$('.vote a').addEvent(
            'click', 
            function(e) {
               var e = new Event(e).stop();
               vote.jsonLink(this);
            }
         );

         $$('.vote').each(
            function(el) {
               if (el.getChildren().length > 2)
                  el.addEvents({
                     'mouseover':
                        function() {
                           this.getLast().getFirst().setStyle('display', 'none');
                        },
                     'mouseout':
                        function() {
                           this.getLast().getFirst().setStyle('display', 'block');
                        }
                  });
            }
         );

      }
   );

   var vote = {
      jsonLink: function(oLink) {
         new Request.JSON(
            {
               url: oLink.getProperty('href'), 
               onComplete: 
                  function(jsonObj) {
                     if ($defined(jsonObj.result)) {

                        oLink.getParent().getParent().removeEvents().getChildren().each(
                           function(el) {
                              if (el.getFirst().tagName == 'A')
                                 el.destroy();
                              else if (el.getFirst().tagName == 'I') 
                                 el.getFirst().set({'html': 'Rating: ' + jsonObj.result + '/5'});
                              else 
                                 el.getFirst().setStyles({'width': Math.round(jsonObj.result * 16), 'display': 'block'});
                           }
                        );
                        return true;
                     }
                     else {
                        return false;
                     }
                  }.bind(this)
            }
         ).get({'json':''});
         return false;
      }
   }

	var pSwitch = function(sContainer,oImg) {
		$(sContainer).src = oImg.src.replace('/small', '/big');
		return false;
	}

