$(document).ready(function() 
{
	var imgRoot = '/wp-content/themes/pas/images/';  

	// comparizon table			
	var toggleMinus = imgRoot + 'btn_collapse.png';
	var togglePlus = imgRoot + 'btn_expand.png';
	var imgColorA = '<img src="' + imgRoot + 'ico_ok.png" alt="yes" />';
	var imgColorB = '<img src="' + imgRoot + 'ico_ok.png" alt="yes" />';
	var subs = $(".comparizon tbody tr:not(.Expandable)");
	
	// add missing cells for togglers
	$(".comparizon thead tr").prepend('<th width="35"> </th>');
	$(".Expandable", ".comparizon").prepend('<th> </th>');
	subs.prepend('<th> </th>');
	
	// add togglers
	var subHead = $('.Expandable:first th:first-child', ".comparizon");
	subHead.prepend('<img class="left" src="' + toggleMinus + '"alt="collapse this section" />');
	$('img', subHead).addClass('clickable');
	subHead = $('th:first-child', $('.Expandable:gt(0)'));
	subHead.prepend('<img class="left" src="' + togglePlus + '"alt="collapse this section" />');
	$('img', subHead).addClass('clickable');

	// collapse all (almost) rows
	var firstBody = $('.comparizon tbody:first');
	firstBody.siblings('tbody').children("tr:not(.Expandable)").css("display", "none");
	
	// add border, remove unnecessary borders
	$('.comparizon').wrap('<div style="border-bottom: 1px solid #ccc;" />');
	$(".comparizon tbody tr:last-child *").css("border-bottom", "0 none");
	subs.children("th:first-child").css("border-bottom", "0 none" );
	
	// style marks
	$('strong', $('td:first',subs)).replaceWith(imgColorA);
	$('strong', $('td:eq(1)',subs)).replaceWith(imgColorB);


	$(".clickable").click(function(){
		var toggleSrc = $(this).attr('src');
		var parentBody = $(this).parents('tbody');
		if ( toggleSrc == toggleMinus ) {
			$(this).attr('src', togglePlus);
			if($.browser.msie)
				parentBody.children("tr:not(.Expandable)").css("display", "none");
			else
				parentBody.children("tr:not(.Expandable)").fadeOut("slow");
		} else{
			$(this).attr('src', toggleMinus);
			if($.browser.msie)
				parentBody.children("tr:not(.Expandable)").css("display", "table-row");
			else
				parentBody.children("tr:not(.Expandable)").fadeIn("slow");
		}
	});
});
