//JQUERY
$(document).ready(function(){
	
	//tables
	$("table tr td:contains('*')").each(function(){
		var $head=$(this);
		$head.parent().children().addClass("header-tr");
		$head.text($head.text().replace("*",""));
	});
	$("table tr td:contains('§')").each(function(){
		var $head=$(this);
		$head.parent().children().addClass("sub-header-tr");
		$head.text($head.text().replace("§","")); 
	});
	
	$("table tr td:contains('#')").each(function(){
		var $special=$(this);
		$special.parent().children().addClass("special-tr");
		$special.text($special.text().replace("#",""));
	});
		
	/*$('.current_page_item').click(function(e) {
		e.preventDefault();
	}*/
	
	//no comments section if empty
	$("#comments:has(p.nocomments)").hide();
	
});

$(window).load(function () {

	//same height for all columns
	//var elements = $('#footer .widget-area ul:first-child');
	var elements1 = $('#footer #first ul:first-child, #footer #second ul:first-child, #footer #third ul:first-child');
	var elements2 = $('#footer #fourth ul:first-child, #footer #fifth ul:first-child, #footer #sixth ul:first-child');
	var max_height1 = 0;
	var max_height2 = 0;

	elements1.each(function(){
	     if($(this).height() > max_height1){
	        max_height1 = $(this).height();   
	    }
	});
	
	elements2.each(function(){
	     if($(this).height() > max_height2){
	        max_height2 = $(this).height();   
	    }
	});

	elements1.height(max_height1);
	elements2.height(max_height2);
	
	//dynamic sidebar height
	var contheight = $("#content").outerHeight();
	var primheight = $("#primary").outerHeight();
	var sideheight = $("#primary").outerHeight() + $("#secondary").outerHeight();
	var commheight = $("#comments").outerHeight();
	var diff = contheight - primheight - 20;
	var diffneg = sideheight - (contheight - commheight)

	if (contheight > sideheight) {
		if ($('#secondary').length == 0) {
			$("#primary").css({'height': contheight + 'px'});
		} else {
			$("#secondary").css({'height': diff + 'px'});
		}
	}
	
	if (sideheight > contheight) {
		$('#comments').css({'height': diffneg + 'px'});
	}
	
	//resize images in sidebar
	$('#primary img, #secondary img').each(function(){
		if ($(this).width() > '195') {
			$(this).css({'width': '195px'});
		}
	});
	
	//resize images in footer
	$('#footer .textwidget img').each(function(){
		if ($(this).width() > '256') {
			$(this).css({'width': '256px'});
		}
	});
	
});
