jQuery(document).ready(function($) {

	if(jQuery.browser.msie){
		jQuery(".shopspreview .shop:last-child").css("border-right","none");
		jQuery(".shopspreview .row:nth-child(2n+1)").css("background-color","#FEF5E0");
	}

	$('#nav .search input[name=name]').one('focus', function() {
		this.style.color = 'black';
		$(this).val('');
	});

	$('#user_comment, #suggest_shop #url, #suggest_shop #desc').one('focus', function() {
		$(this).val('');
	});


	//
	// rating system
	//
	var img_path = $('.rating img').first().attr('src');
	if (/^\.\./.test(img_path)) img_path = '../img/';
	else img_path = 'img/';

	$('.rating img').css('cursor', 'pointer')
	.bind("mouseenter", function(){
		var cur = $(this).attr('alt');
		$('img', $(this).parent()).each(function(){
			if ($(this).attr('alt') <= cur) $(this).attr('src', img_path+'rating_star.png');
			else $(this).attr('src', img_path+'rating_star_minus.png');
		});
    })
    .bind("click", function(){
    	var id = $(this).parent().attr('shop');
    	var value = $(this).attr('alt');
		$.post(img_path+'../catalog/rating.php', {'id':id, 'value':value}, function(data) {
			// show result
			var data = eval('(' + data + ')');
			var el = $('.rating[shop='+id+']');
			var html = el.html();
			el.html(data['mes']);
			el.attr('rating', data['rating']);
			var timer = setTimeout(function () {
				clearTimeout(timer);
				el.html(html);
				el.trigger('mouseleave');
			}, 3000);
		});
    });
    $('.rating').bind("mouseleave", function(){
    	var rating = Math.round($(this).attr('rating'));
		$('img', $(this)).each(function(){
			if ($(this).attr('alt') <= rating) $(this).attr('src', img_path+'rating_star.png');
			else $(this).attr('src', img_path+'rating_star_minus.png');
		});
    });


    equalHeight($(".deal"));
});




function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

