
function saveRating( video, vote ){
	$.ajax({
		type: "POST",
		url: "/ajax/videos_save_rating.php",
		data: "video="+video+"&vote="+vote,
		success: function(msg){
			$('.star_rating[rel='+video+']').removeClass('vote_for').html(msg).next('.voteMsg').text('Thank you for rating this video');
		},
		error: function(msg) {
			//$('#post_purchase_survey').html(msg);
		}
	});
}

$(document).ready(function(){
	$('#videos_list').css({position:"relative"}).jScrollPane({scrollbarWidth:21,dragMaxHeight:27,showArrows:true});
	
	$('.star_rating').hover(function(){
		$(this).next('.voteMsg').show();
		
		if( $(this).hasClass('vote_for') ){
			
			$(this).children('.stars').clone().appendTo(this).removeClass('stars').attr('id','voting');
			$(this).children('.stars').hide();
			
			$('#voting img').each(function(){
				$(this).wrap('<a href="#"></a>');
			});
			
			$('#voting a').hover(function(){
				var index = $('#voting a').index(this) + 1;
				$('#voting a:lt('+index+')').children('img').attr('src','/img/hairstyle-guide/bg/star_vote.gif');
				$('#voting a:gt('+(index-1)+')').children('img').attr('src','/img/hairstyle-guide/bg/star_off.gif');
				
				$(this).click(function(e){
					var videoID = $(this).parent().parent().attr('rel').replace('vote_for_','');
					$(this).parent().parent();//.removeClass('vote_for');//.unbind('hover');
					$('.stars:hidden').show();
					$('#voting').remove();
					saveRating( videoID , index );
					return false;
				});
			},
			function(){});
		}
	},
	function(){			
		$(this).next('.voteMsg').hide();
		$('#voting').remove();
		$(this).children('.stars').show();
	});
	
});