$(function(){
	if (0 < $('img[star_plus]').length <= 0) return true;
	
	$('img[star_plus]')
		.hover(
			function(){ $(this).css('cursor', 'pointer'); },
			function(){ $(this).css('cursor', 'auto'); })
		.click(function(){
			if (0 < $('#div_star_plus_' + $(this).attr('star_plus')).length) {
				$('#div_star_plus_' + $(this).attr('star_plus')).remove();
				$(this).attr('src', '/images/star_button.gif').css({width: '23px', height: '18px'});
			} else {
				var e=$('<div></div>')
					.attr({
						id: 'div_star_plus_' + $(this).attr('star_plus'),
						div_star_plus: $(this).attr('star_plus')})
					.css({
						background: 'url(/images/bg_star_plus.gif) right top no-repeat #FFF',
						'border-left': '1px solid #BDD0DA',
						'border-right': '1px solid #BDD0DA',
						'border-bottom': '1px solid #BDD0DA',
						position: 'absolute',
						top: $(this).position().top + $(this).height(),
						left: $(this).position().left,
						padding: '3px',
						width: '56px'})
				.append($('<img>')
					.attr({src: '/images/stars_plus_1.gif', stars_button: 1})
					.css({display: 'block', margin: '4px 0'}))
				.append($('<img>')
					.attr({src: '/images/stars_plus_2.gif', stars_button: 2})
					.css({display: 'block', margin: '4px 0'}))
				.append($('<img>')
					.attr({src: '/images/stars_plus_3.gif', stars_button: 3})
					.css({display: 'block', margin: '4px 0'}))
				.append($('<img>')
					.attr({src: '/images/stars_plus_4.gif', stars_button: 4})
					.css({display: 'block', margin: '4px 0'}))
				.append($('<img>')
					.attr({src: '/images/stars_plus_5.gif', stars_button: 5})
					.css({display: 'block', margin: '4px 0'}));
				$(this).attr('src', '/images/star_button_over.gif');
				
				var id=$(this).attr('star_plus');
				
				$('body').append($(e));
				$(window).resize(function(){
					$('div[div_star_plus]').each(function(index){
						$(this).css({
							top: $('img[star_plus="' + $(this).attr('div_star_plus') + '"]').position().top + $('img[star_plus="' + $(this).attr('div_star_plus') + '"]').height(),
							left: $('img[star_plus="' + $(this).attr('div_star_plus') + '"]').position().left
						});
					});
				});
				
				$('img[stars_button]')
					.hover(
						function(){ $(this).css('cursor', 'pointer'); },
						function(){ $(this).css('cursor', 'pointer'); })
					.click(function(){
						$('#div_star_plus_' + id).remove();
						$('img[star_plus="' + id + '"]').attr('src', '/images/loading.gif').css({cursor: 'auto', width: '22px', height: '22px'});
						
						$.ajax({
							url:  '/',
							data: {
								m:  'detail_star',
								star: $(this).attr('stars_button'),
								id: id,
								xml: 1
							},
							success: function(data, dataType){
								var stars=data.getElementsByTagName('star');
								$('img[star_image="' + id + '"]')
									.attr('src', '/images/star_r_' + stars[0].getAttribute('value') + '.gif')
									.attr('alt', '平均星' + stars[0].getAttribute('value') + 'つ');
								$('span[star_num="' + id + '"]')
									.html(stars[0].getAttribute('num'));
								
								$('img[star_plus="' + id + '"]').attr('src', '/images/star_button.gif').css({width: '23px', height: '18px'});
							}
						});
					});
			}
		});
});

