	var avg_rating = 3;
	var my_rating = 2;

	function rateVideo(item) {
		$('#video_rating #rating_img').children('img').each(function(index) {
			if ($(item).index() == index) {
				my_rating = index+1;
				sendRating($('#videoclip_id').html(),my_rating);
			}
		 });
	}

	function initRateVideo() {
		$('#video_rating').bind('mouseenter', function()	{startRating();});
		$('#video_rating').bind('mouseleave', function()	{stopRating();});

		$('#video_rating #rating_img').children('img').bind('mouseover', function() {
			moverRating(this);
		});
		$('#video_rating #rating_img').children('img').bind('click', function() {
		  rateVideo(this)
		});
	}

	function moverRating(item) {
		$('#video_rating #rating_img').children('img').each(function(index) {
			if (index <= $(item).index())  {
				$(this).attr('src', 'http://www.nrw.tv/static/gfx/videoarchiv/ico-14-star-a-1.png');
			} else {
				$(this).attr('src', 'http://www.nrw.tv/static/gfx/videoarchiv/ico-14-star-a-0.png');
			}
		});
	}
	function startRating() {
		$('#video_rating #rating_label').html('Deine Bewertung:');
		$('#video_rating #rating_label').css('color','#ccc');
		$('#video_rating #rating_img').children('img').each(function(index) {
			if (my_rating <= $(this).index())  {
				$(this).attr('src', 'http://www.nrw.tv/static/gfx/videoarchiv/ico-14-star-a-0.png');
			} else {
				$(this).attr('src', 'http://www.nrw.tv/static/gfx/videoarchiv/ico-14-star-a-1.png');
			}
		});
	}

	function stopRating() {
		$('#video_rating #rating_label').css('color','#808080');
		$('#video_rating #rating_label').html('&empty; Bewertung:');
		$('#video_rating #rating_img').children('img').each(function(index) {
			if (avg_rating <= $(this).index())  {
				$(this).attr('src', 'http://www.nrw.tv/static/gfx/videoarchiv/ico-14-star-b-0.png');
			} else {
				$(this).attr('src', 'http://www.nrw.tv/static/gfx/videoarchiv/ico-14-star-b-1.png');
			}
		});
	}

	function sendRating(videoclip_id,rate) {
		$('#rating_loader img').attr('src','http://www.nrw.tv/static/gfx/videoarchiv/rating-loader.gif');
		$('#rating_loader img').show();
		$.ajax({
			url: 'http://player.tneg.de/dataprovider/nrw.tv/videoclip/rateVideoClip.php',
			data: "videoclip_id="+videoclip_id+"&rate="+rate+"&callback=?",
			dataType: "json",
			beforeSend: function(data) {

			},
			success: function(msg){
				window.setTimeout("$('#rating_loader img').hide();", 1000);
				$('#rating_helper').html(msg);
			},
			complete: function() {
				var count = $('#rating_helper_count').html();
				$('#video_info_rating').html('&empty; ' + $('#rating_helper_avg').html() + " / Anzahl der Bewertungen: "+ count);
				setRating();
			}
		});
	}
	
	function setRating() {
		avg_rating = $('#rating_helper_avg').html();
		stopRating();
	}
	
