$(document).ready(function()
{
	initialize();
	$(".filter-option").click( function(){ $str_name = $(this).attr('id').substr(7); toggleClass($str_name,$(this).is(':checked')); });
	$("#button-filter").click( function(){ $(this).toggleClass('here'); $("#panel-filter").toggleClass('here'); } );
	$("#check-filter").click( function(){ c = document.filter.getElementsByTagName('input'); for (var i = 0; i < c.length; i++) { if (c[i].type == 'checkbox') { c[i].checked = true; } } initialize(); } );
	$("#uncheck-filter").click( function(){ c = document.filter.getElementsByTagName('input'); for (var i = 0; i < c.length; i++) { if (c[i].type == 'checkbox') { c[i].checked = false; } } initialize(); } );
});

function initialize() {
	c = document.filter.getElementsByTagName('input');
	for (var i = 0; i < c.length; i++) { 
		if (c[i].type == 'checkbox' && c[i].checked == true) { $str_name = c[i].id.substr(7); toggleClass($str_name,true); }
		if (c[i].type == 'checkbox' && c[i].checked == false) { $str_name = c[i].id.substr(7); toggleClass($str_name,false); $("#button-filter").addClass('here'); $("#panel-filter").addClass('here'); }
   	}
}

function toggleClass(str_name, flag_on) {
	if (flag_on) { $("."+str_name).show(); }
	else { $("."+str_name).hide(); }
}
