$(document).ready(function(){
	$('.rating img').css('cursor', 'pointer');
	
	$('.rating img').mouseover(function() {
		var i = parseInt($(this).attr('id').substring(3, 4));
		for (var j = 1; j < 6; j++) {
			$('#img' + j).attr('rel', $('#img' + j).attr('src'));
			
			if (j < (i+1)) {
				$('#img' + j).attr('src', '/images/star-on-hover.gif');
			} else {
				$('#img' + j).attr('src', '/images/star-off-hover.gif');
			}
		}
	});

	$('.rating img').mouseout(function() {
		var i = parseInt($(this).attr('id').substring(3, 4));
		for (var j = 1; j < 6; j++) {	 
			$('#img' + j).attr('src', $('#img' + j).attr('rel'));
		}
	});

	$('.rating img').click(function() {
		var rating = parseInt($(this).attr('id').substring(3, 4));
		$.post("/js/ratevideo.php", { id: id, rating: rating }, function(data) {
			$(".rating").append(data.result);
			$('.rating img').unbind('click');
			for (var j = 1; j < 6; j++) {
				$('#img' + j).attr('src', $('#img' + j).attr('rel'));
			}
			$('.rating img').unbind('mouseover');
			$('.rating img').unbind('mouseout');			
			$('.rating img').css('cursor', 'default');
		}, 'json');
	});

	var title = '';

	$('div#related img').hover(function(e) {
		title = $(this).parent().attr('title');
		var img = $(this).attr('src');
		var href = $(this).parent().attr('href');
		var desc = $(this).parent().children('span').html();

		$(this).parent().attr('title', '');
	
		$('<div id="hoverbox" />').appendTo('body');
	
		$('div#hoverbox').html('<p><small><strong>' + title + '</strong></p><p>' + desc + '</p></small></div>');
		$('div#hoverbox').css('top', (e.pageY - 10) + 'px').css('left', (e.pageX + 10) + 'px'); 
	}, function(e) {
		$('div#hoverbox').remove();
		$(this).parent().attr('title', title);
	});
 
	$('div#related img').mousemove(function(e) {
		$('div#hoverbox').css('top', (e.pageY - 10) + 'px').css('left', (e.pageX + 10) + 'px');
	});
					   
});