$(document).ready(function() { 
	$('.closebutton').click(function() {$(this).parent().fadeOut(400); });
	$('.closebutton').mouseover(function() {$(this).css('background','url(/i/closebutton_hover.gif) no-repeat')});
	$('.closebutton').mouseout(function() {$(this).css('background','url(/i/closebutton.gif) no-repeat')});
	$('.thumbs img').each(function() {
		var folder = $(this).parent().attr('folder');
		$(this).wrap('<a href="'+ folder +$(this).attr('src')+'" rel="fancybox"></a>');
		$(this).attr('src',folder+'small/'+$(this).attr('src'));
	});


	$('.thumbs').each(function() {
		if ($(this).children('a').size()>4) {
			var closedid = genId();
			$(this).append('<br clear="all" /><span class="link serv" onclick="mytoggle(\''+closedid+'\')">еще картинки</span><div id="'+closedid+'" class="hidden mtop"></div>');
			$(this).children('a:gt(2):not(:last)').each(function() {
				$(this).clone().appendTo('#'+closedid);
				$(this).remove();
			});
		}
	});

	var satisfacount = $('#satisfa li').size();
	$('#satisfato').html(rightnum(satisfacount));
	
	$(".fancybox a").fancybox({ 
				'padding'		:	0,
				'overlayShow'		:	true,
				'overlayOpacity'	:	0.7,
				'overlayColor'		:	'white'
	}); 

	$("a.fancybox").fancybox({ 
				'padding'		:	0,
				'overlayShow'		:	true,
				'overlayOpacity'	:	0.7,
				'overlayColor'		:	'white'
	}); 

	// смета
	
	$("table.smeta tbody").each(function() {
		var summ = 0;
		$(this).children('tr').children('td:last-child').each(function() {
			//alert(Number($(this).html()));
			summ += Number($(this).html());
		});
		//alert(summ);
		$(this).parent().after('<div class="summ">Итого по разделу: '+summ+' руб.</div>');
	}); 
	// раскраски
	$('.smeta tr td:first-child').addClass('name');
	
	
	// раскраски
	$('.timeline tr td:first-child').addClass('noborder');
});

function mytoggle(id) {
	var tmp = $('#'+id);
	if (tmp.is(':visible')) tmp.fadeOut(400); else tmp.fadeIn(400);
}

function rightnum(count) {
	var tmp = '';
	if (count>1 && count<5) tmp = 'м';
	if (count>=5) tmp = 'и';
	return count+'-'+tmp;
}

var idcounter = 0;
function genId() {
	return 'gi' + idcounter++;
};