﻿$(function() {
	var pop = function() {
		$(".popup-window.follow-group").popup({
			onSuccess: function(popup, data) {
				popup.closest(".follow_item").html(data);

//				var participantsCount = 0;

//				if (this.title == "Sledi skupini") {
//					var test = popup.closest("td").prev();
//					participantsCount = $(".num_users center a:first").html() + 1;
//					alert(participantsCount);
//					$(".num_users center a:first").html(participantsCount);
//				}
//				else {
//					var participantsCount = Number($(".num_users a span:first").html()) + 1;
//					$(".num_users a span:first").html(participantsCount);
//				}
				pop();
			}
		});
	};
	pop();

	$.tablesorter.addParser({
		// set a unique id 
		id: 'links',
		is: function(s) {
			// return false so this parser is not auto detected 
			return false;
		},
		format: function(s) {
			// format your data for normalization 
			return s.replace(new RegExp(/<.*?>/), "");
		},
		// set type, either numeric or text
		type: 'text'
	});

	$.tablesorter.addParser({
		id: 'numeric',
		is: function(s) {
			return false;
		},
		format: function(s) {
			s = s.replace(new RegExp(/<.*?>/), "");
			s = s.replace(new RegExp(/<\/.*?>/), "");
			return s;
		},
		type: 'numeric'
	});

	$.tablesorter.addParser({
		// set a unique id
		id: 'numericLinks',
		is: function(s) {
			// return false so this parser is not auto detected 
			return false;
		},
		format: function(s) {
			// format your data for normalization

			s = s.replace(new RegExp(/<.*?>/), "");
			s = s.replace(new RegExp(/<\/.*?>/), "");
			s = s.replace(new RegExp(/<.*?>/), "");
			s = s.replace(new RegExp(/<\/.*?>/), "");
			return s;
		},
		// set type, either numeric or text
		type: 'numeric'
	});

	$("#group_all_table").tablesorter({
		cssAsc: "asc",
		cssDesc: "desc",
		headers: {
			0: {
				sorter: 'links'
			},
			1: {
				sorter: false
			},
			2: {
				sorter: 'numericLinks'
			},
			3: {
				sorter: 'numericLinks'
			},
			4: {
				sorter: 'numericLinks'
			},
			5: {
				sorter: 'numericLinks'
			}
		}
	});

	//	$("#group_all_table thead tr th").click(function() {

	//		var isAsc = null;

	//		if ($("span", this).hasClass("asc")) {
	//			isAsc = false;
	//		}
	//		else if ($("span", this).hasClass("desc")) {
	//			isAsc = true;
	//		}

	//		$("#group_all_table span").removeClass("asc");
	//		$("#group_all_table span").removeClass("desc");

	//		if (isAsc == null) {
	//			$("span", this).addClass("asc");
	//		}
	//		else if (isAsc) {
	//			$("span", this).removeClass("desc");
	//			$("span", this).addClass("asc");
	//		}
	//		else if (!isAsc) {		

	//		$("span", this).removeClass("asc");
	//		$("span", this).addClass("desc");
	//		}




	//	});
});
