$(document).ready(function() {
	var headers = {};
	var add = {};
	$("table.sortable th").each(function(i) {
		if($(this).hasClass('unsortable')) {
			add[i] = {sorter:false};
			jQuery.extend(headers, add);
		}
		if($(this).hasClass('digit')) {
			add[i] = {sorter:'digit'};
			jQuery.extend(headers, add);
		}
		if($(this).hasClass('text')) {
			add[i] = {sorter:'text'};
			jQuery.extend(headers, add);
		}
		if($(this).hasClass('isoDate')) {
			add[i] = {sorter:'isoDate'};
			jQuery.extend(headers, add);
		}
	});
	$("table.sortable").tablesorter({
		'headers': headers,
		textExtraction:'complex'
	});
	$('table tr:even').addClass('even');
	$('form.uniForm').uniform();
	/*$(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'light_rounded'});*/
	$('table.textCenter').removeClass('textCenter').addClass('table');
	$('table.centerText').removeClass('centerText').addClass('table');
	$(".article img").each(function() {
		var src = $(this).attr('src');
		if(src.lastIndexOf("/pictures")) {
			$(this).attr('src', 'http://nashvek.ru'+src.substring(src.lastIndexOf("/pictures")));
			$(this).attr('no_error','no_error');
		}
		return;
	});
	$("img").error(function() {
		if($(this).attr('no_error')) {return;}
		var size = 120;
		if($(this).attr('width') || $(this).attr('height')) {
			size = ($(this).attr('width') > $(this).attr('height'))?$(this).attr('height'):$(this).attr('width');
			if(size % 2 != 0) {size--;}
			$(this).attr('width', size).attr('height', size);
		} else {
			$(this).attr('width', size).attr('height', size);
		}
		$(this).attr('src', '/images/no_image_available.png');
	});
	var flow_error_count = 0;
	$('.underconstruction').click(function() {
		$('.flow_error').append('<dl class="error" id="'+flow_error_count+'" style="display:none;"><dt>Ошибка!</dt><dd>Этот функционал ещё не разработан.</dd></dl>');
		$('.flow_error dl#'+flow_error_count).fadeIn('slow');
		flow_error_count++;
		setTimeout(function(){
			$('.flow_error dl:first').remove();
			}, 3000
		);
		return false;
	});
});
$(window).load(function() {
	$('#throbber').hide();
});

