/**
 * @author User
 */

window.addEvent('domready', function() {
	star_vote_eventer();
});

var star_vote_orig_src = new Array();

var star_vote_eventer = function() {
	document.getElements('.star').each(function(star, index) {

//		star_vote_orig_src[index] = star.getStyle('background');

		if(star.hasClass('star_active')) {
			star_vote_orig_src[index] = 'star_active';
		}
		else if(star.hasClass('star_half')) {
			star_vote_orig_src[index] = 'star_half';
		}
		else {
			star_vote_orig_src[index] = 'star_inactive';
		}



		var tmp = star.getProperty('id').split('_');

		var id		= tmp[1].toInt();
		var value	= tmp[2].toInt();

		var parent	= star.getParent('div');

		star.removeEvents();


		star.addEvents({
			'mouseenter': function()
			{
				for(var counter = 0; counter <= value; counter++) {
//					$('star_' + id + '_' + counter).setStyle('background', 'url(/images/gfx/voting/star_hover.png) 0 0 no-repeat');
					$('star_' + id + '_' + counter).addClass('star_hover');
				}

			},
			'mouseleave': function()
			{
				//this.setProperty('src', src);
				for(var counter = 0; counter <= value; counter++) {
//					$('star_' + id + '_' + counter).setStyle('background', star_vote_orig_src[counter]);

					$('star_' + id + '_' + counter).removeClass('star_hover');
//					$('star_' + id + '_' + counter).addClass(star_vote_orig_src[counter]);
				}
			},
			'click': function(e) {
				e.stop();


				value = value.toInt()+1;
				new Request({
					'method': 'post',
					'url': '/unterhaltung/fotoalbum/inc/star_vote.php',
					'data': 'id=' + id + '&value=' + value,

					onSuccess: function(response) {
						parent.set('html', response);
						star_vote_eventer();
					}
				}).send();
			}
		});
	});
}
