﻿$(document).ready( function () {
	/*animate preview images*/
	$('.preview').hover(
		function () {
			if(!$(this).next().hasClass('cache')) return;
			$(this).stop().animate({'width' : 400, 'height' : 400}, 500, 'easeOutBack', function () {
				$(this).attr('src',$(this).attr('src').replace('medium','large'));
			});
		},
		function () {
			$(this).stop().animate({'width' : 210, 'height' : 210}, 500, 'easeOutBack', function () { 
				$(this).attr('src',$(this).attr('src').replace('large','medium'));
			});			
		}
	);
	
	$('.shops tr').hover( function () { $(this).addClass('current');}, function () { $(this).removeClass('current'); });
	
	/*unwrap function*/
	$.fn.unwrap = function () {
		return this.each(function(){
			$(this).parent().replaceWith( this );
		});
	};
	
	/*show-hide table*/
	$('thead').toggle(
		function () {
			$(this).parents('.card').animate({'height':$(this).height()},500,'easeOutExpo');
		},
		function () {
			$(this).parents('.card').animate({'height':$(this).parents('.card').find('table').height()},500,'easeOutExpo', function () { });
		}
	);
	
	/*voting*/
	$('.stars>li').hover( 
		function () {
			if($(this).parent().hasClass('disable')) return;
			$(this).nextAll().removeClass('red');
			$(this).addClass('red').prevAll().addClass('red');
		},
		function () {
			$('.stars>li').removeClass('red');
		}
	);
	
	$('.stars>li').click( function () {
		$.post('rating.php', { stars: $(this).find('i').html() });
		$(this).parent().addClass('disable').find('li').removeClass('red');
	});
	
});