preloadImages('/images/note_recipe_big1.gif', '/images/note_recipe_big2.gif', '/images/note_recipe_big3.gif', '/images/note_recipe_big4.gif', '/images/note_recipe_big5.gif');

var Note = Class.create();
var voted;
Note.prototype = {
  	initialize: function(elem, idx, isLogued) {
		this.elem = elem;
		this.idx = idx;
		this.isLogued = isLogued;
		voted = false;
		
	},

  	on: function() { 
  		if (voted == false)
		{
			$(this.elem).className = this.elem + this.idx;	
			$(this.elem + '_status').update(rate_expl[this.idx - 1]);
		}
	},
	
	off: function() { 
		if (voted == false)
		{
			$(this.elem).className = this.elem; 
			$(this.elem + '_status').update('');
		}
	},
	
	send: function() {
		elem = this.elem;
		
		if (voted==false)
		{
			if (this.isLogued)
			{
		
				$(elem + '_status').update('<img src=/images/ajax_indicator.gif>');
				
				new Ajax.Request('/index.php?obj=feed&action=feed_data_note&idx=' + this.idx + '&id=' + $(elem + '_id').value, {
						onSuccess: function(t) {
							if (parseInt(t.responseText) == 0) 
								$(elem + '_status').innerHTML = $(elem + '_err').value;
							else {
								$(elem + '_status').innerHTML = $(elem + '_ok').value;
								$(elem + '_curr').src = '/images/' + elem + '_small' + t.responseText + '.gif';
							}
						}
					});
					
				voted = true;
				$('feed_comment').show();
			}
			else
			{
			new PopupDiv('/index.php?obj=members&action=member_form&member_source=NOTE&feed_data_id='+$(elem + '_id').value+'&from=vote&note='+ this.idx);
			}
		}
	}
};

Event.observe(window, 'load', function() {
	for (i = 1; i<=5; i++) {		
		n = new Note('note_recipe', i, isLogued);
		n.evOn = n.on.bindAsEventListener(n);
		n.evOff = n.off.bindAsEventListener(n);
		n.evSend = n.send.bindAsEventListener(n);
		Event.observe('vote_recipe' + i, 'mouseover', n.evOn);
		Event.observe('vote_recipe' + i, 'mouseout', n.evOff);
		Event.observe('vote_recipe' + i, 'click', n.evSend);
	}
});