function initRating(ratingProhibited, ratingFinished) {
    var LOADING_TEXT_DURATION = 500;
    $('a.rateable').live('click', function() {
    	// ak je hlasovanie zakazane - zobrazujeme znamky ineho uzivatela
    	if (ratingFinished) {
    		alert(ratingFinishedMessage);
    		return;
    	}
    	if (ratingProhibited) {
    		alert(ratingAnotherUserMessage);
    		return;
    	}
    	
    	var button = $(this),
    	    buttonId = button.attr('id'),
    	    attrs = button.attr('id').split('_'),
    	    coach = false,
    	    bubble = $("#bubble_" + attrs[1]),
    	    ratingBox = $("#scale_" + attrs[1]);

    	if (attrs[5] !== null && attrs[5] === 'coach') {
    		coach = true;
    	}
    	bubble.addClass('loading').text('');
    	bubble.css('visibility', 'visible');
    	// uložíme si původní obsah boxu pro hodnocení, abychom ho po hlasování mohli opět zobrazit
    	ratingBox.data('origHtml', ratingBox.html());
    	ratingBox.html('<span style="line-height:inherit;font-size:0.7em;color:#999999;float:none;text-align:center">' + ratingInProgress + '</span>');
    	setTimeout(function() {
    	    RatingDWRManager.markPlayerInMatch($.cookies.get('userContext'), attrs[3], attrs[2], attrs[1], attrs[4], coach, function(DTO) {
                var rate = DTO.rate / 10;

                ratingBox.children().text(rateSaved);
                // po LOADING_TEXT_DURATION - 100 ms se schová ajax loader a opět se zobrazí box pro hlasování
                setTimeout(function() {
                    if (rate >= 0 && rate < 2) {
                        bubble.attr('class', 'bubble rating r-player r-value-1');
                    } else if (rate >= 2 && rate < 4) {
                        bubble.attr('class', 'bubble rating r-player r-value-2');
                    } else if (rate >= 4 && rate < 6) {
                        bubble.attr('class', 'bubble rating r-player r-value-3');
                    } else if (rate >= 6 && rate < 8) {
                        bubble.attr('class', 'bubble rating r-player r-value-4');
                    } else if (rate >= 8 && rate <= 10) {
                        bubble.attr('class', 'bubble rating r-player r-value-5');
                    }
                    bubble.text(rate);

                    ratingBox.html(ratingBox.data('origHtml'));
                    button = $('#' + buttonId);

                    ratingBox.attr('class', 'rate-me rated');
                    ratingBox.children('.active').removeClass('active');
                    button.parent().addClass('active');
                }, LOADING_TEXT_DURATION - 100);
            });
    	}, LOADING_TEXT_DURATION);
  	});

    $('a.show').click(function() {
    	var button = $(this),
    	    attrs = button.attr('id').split('_');
    	RatingDWRManager.getAllMarksInMatch(attrs[1], function(DTO) {
    		if (DTO.homeTeamRate < 0) {    			
    			$("#home").text('?');
    		} else {
    			$("#home").text(DTO.homeTeamRate / 10);
    		}
    		if (DTO.visitorTeamRate < 0) {
    			$("#visitor").text('?');
    		} else {
    			$("#visitor").text(DTO.visitorTeamRate / 10);
    		}
    		$("#home").css('visibility', 'visible');
    		$("#visitor").css('visibility', 'visible');

    		var bubbles = $('div.inline-rating').find('span.bubble'),
    		    popup = button.closest('.popup'),
    		    bubble, tmp, rate;

    		for (var i = 0;i < bubbles.length;i++) {
    			bubble = bubbles.eq(i);
    			tmp = DTO.homeTeamPlayersRates[bubble.attr('id').split('_')[1]];

    			// ak to nie je domaci hrac
    			if (typeof tmp === 'undefined') {
    				tmp = DTO.visitorTeamPlayersRates[bubble.attr('id').split('_')[1]];
    			}
    			// ak to je rozhodca alebo komentator
    			if (typeof tmp === 'undefined') {
    				tmp = DTO.otherPersonsRates[bubble.attr('id').split('_')[1]];
    			}
    			if (typeof tmp !== 'undefined') {
    				if (tmp.rate < 0) {
    					bubble.text('?');
    				} else {
    					bubble.text(tmp.rate / 10);
    				}
        			rate = bubble.text();
            		if (rate >= 0 && rate < 2) {
            			bubble.attr('class', 'bubble rating r-player r-value-1');
            		} else if (rate >= 2 && rate < 4) {
            			bubble.attr('class', 'bubble rating r-player r-value-2');
            		} else if ((rate >= 4 && rate < 6) || rate === '?') {
            			bubble.attr('class', 'bubble rating r-player r-value-3');
            		} else if (rate >= 6 && rate < 8) {
            			bubble.attr('class', 'bubble rating r-player r-value-4');
            		} else if (rate >= 8 && rate <= 10) {
            			bubble.attr('class', 'bubble rating r-player r-value-5');
            		}
        			bubble.css('visibility', 'visible');
    			}
    			// ak sa dana osoba este nenachadza v zoznamoch dame jej otaznik
    			if (typeof tmp === 'undefined') {
    				bubble.text('?');
    				bubble.attr('class', 'bubble rating r-player r-value-3');
    				bubble.css('visibility', 'visible');
    			}
    		}

    		// pokud byl kliknutý odkaz v dialogu, dialog se zavře
    		if (popup.length !== 0) {
    		    popup.fadeOut();
    		}
    	});
    });
}
