function refineSetStyles() {
	// resets styles
	$('.refineresults_controls label.sublabel').css("font-weight","normal");
	$('.refineresults_controls label.sublabel').css("color","#000000");
	
	// if checked, adds styles
	$(".refineresults_controls input:checked").each(function(i) {
		inputId = $(this).attr("id");
		$('label[for="'+inputId+'"]').css("font-weight","bold");
		$('label[for="'+inputId+'"]').css("color","#2d384d");
	});
}

function selectsolution(value) {
	refineSetStyles();
}

function selectlvl($thisLvl,value) {
	speed = 200;

	// This section unchecks next level inputs, then shows the approriate next level category if available.
	$nextLvl = $thisLvl + 1;
	$('#refine_lvl' + $nextLvl).hide();
	$('#arrow_lvl' + $nextLvl).hide();
	nextLvlItemsAvailable="false";
	$("[name='p" + $nextLvl + "']").each(function(i) {
		$("[name='p" + $nextLvl + "']")[i].checked=false;
	});
	$("#refine_lvl" + $nextLvl + " > div").each(function(i) {
		$divId = $(this).attr('id');
		if ($divId == value) {$(this).show(); nextLvlItemsAvailable="true";}
		else {$(this).hide();}
	});		
	if (nextLvlItemsAvailable=='true') {
		$('#refine_lvl' + $nextLvl).slideDown(speed);
		$('#arrow_lvl' + $nextLvl).show();
	}

	// This next section unchecks and hides all inputs at least two levels down from selection!
	$futureLvl = $thisLvl + 2;
	while ($futureLvl<=8) {
		$("[name='p" + $futureLvl + "']").each(function(i) {$("[name='p" + $futureLvl + "']")[i].checked=false;});
		$('#refine_lvl' + $futureLvl).hide();
		$('#arrow_lvl' + $futureLvl).hide();
		$futureLvl++;
	}

	refineSetStyles();
}

function reselectlvl(lvl,lvl2divtitle,lvl3divtitle,lvl4divtitle,lvl5divtitle,lvl6divtitle,lvl7divtitle,lvl8divtitle) {
	
	lvl2itemsAvailable="false";
	lvl3itemsAvailable="false";
	lvl4itemsAvailable="false";
	lvl5itemsAvailable="false";
	lvl6itemsAvailable="false";
	lvl7itemsAvailable="false";
	lvl8itemsAvailable="false";
	
	if(lvl=='lvl1' || lvl=='lvl2' || lvl=='lvl3' || lvl=='lvl4' || lvl=='lvl5' || lvl=='lvl6' || lvl=='lvl7' || lvl=='lvl8') {
		$('#refine_lvl2 > div').each(function(i) {
			if ($(this).attr('id')==lvl2divtitle) {$(this).show(); lvl2itemsAvailable="true";}
			else {$(this).hide();}
		});
	}
	if(lvl=='lvl2' || lvl=='lvl3' || lvl=='lvl4' || lvl=='lvl5' || lvl=='lvl6' || lvl=='lvl7' || lvl=='lvl8') {
		$('#refine_lvl3 > div').each(function(i) {
			if ($(this).attr('id')==lvl3divtitle) {$(this).show(); lvl3itemsAvailable="true";}
			else {$(this).hide();}
		});
	}
	if(lvl=='lvl3' || lvl=='lvl4' || lvl=='lvl5' || lvl=='lvl6' || lvl=='lvl7' || lvl=='lvl8') {
		$('#refine_lvl4 > div').each(function(i) {
			if ($(this).attr('id')==lvl4divtitle) {$(this).show(); lvl4itemsAvailable="true";}
			else {$(this).hide();}
		});
	}
	if(lvl=='lvl4' || lvl=='lvl5' || lvl=='lvl6' || lvl=='lvl7' || lvl=='lvl8') {
		$('#refine_lvl5 > div').each(function(i) {
			if ($(this).attr('id')==lvl5divtitle) {$(this).show(); lvl5itemsAvailable="true";}
			else {$(this).hide();}
		});
	}
	if(lvl=='lvl5' || lvl=='lvl6' || lvl=='lvl7' || lvl=='lvl8') {
		$('#refine_lvl6 > div').each(function(i) {
			if ($(this).attr('id')==lvl6divtitle) {$(this).show(); lvl6itemsAvailable="true";}
			else {$(this).hide();}
		});
	}	
	if(lvl=='lvl6' || lvl=='lvl7' || lvl=='lvl8') {
		$('#refine_lvl7 > div').each(function(i) {
			if ($(this).attr('id')==lvl7divtitle) {$(this).show(); lvl7itemsAvailable="true";}
			else {$(this).hide();}
		});
	}
	if(lvl=='lvl7' || lvl=='lvl8') {
		$('#refine_lvl8 > div').each(function(i) {
			if ($(this).attr('id')==lvl8divtitle) {$(this).show(); lvl8itemsAvailable="true";}
			else {$(this).hide();}
		});
	}

	if (lvl2itemsAvailable=="true" && (lvl=='lvl1' || lvl=='lvl2' || lvl=='lvl3' || lvl=='lvl4' || lvl=='lvl5' || lvl=='lvl6' || lvl=='lvl7' || lvl=='lvl8')) {
		$('#refine_lvl1').show();
		$('#arrow_lvl1').show();
		$('#refine_lvl2').show();
		$('#arrow_lvl2').show();
	}
	if (lvl3itemsAvailable=="true" && (lvl=='lvl2' || lvl=='lvl3' || lvl=='lvl4' || lvl=='lvl5' || lvl=='lvl6' || lvl=='lvl7' || lvl=='lvl8')) {
		$('#refine_lvl3').show();
		$('#arrow_lvl3').show();
	}
	if (lvl4itemsAvailable=='true' && (lvl=='lvl3' || lvl=='lvl4' || lvl=='lvl5' || lvl=='lvl6' || lvl=='lvl7' || lvl=='lvl8')) {
		$('#refine_lvl4').show();
		$('#arrow_lvl4').show();
	}
	if (lvl5itemsAvailable=='true' && (lvl=='lvl4' || lvl=='lvl5' || lvl=='lvl6' || lvl=='lvl7' || lvl=='lvl8')) {
		$('#refine_lvl5').show();
		$('#arrow_lvl5').show();
	}
	if (lvl6itemsAvailable=='true' && (lvl=='lvl5' || lvl=='lvl6' || lvl=='lvl7' || lvl=='lvl8')) {
		$('#refine_lvl6').show();
		$('#arrow_lvl6').show();
	}
	if (lvl7itemsAvailable=='true' && (lvl=='lvl6' || lvl=='lvl7' || lvl=='lvl8')) {
		$('#refine_lvl7').show();
		$('#arrow_lvl7').show();
	}
	if (lvl8itemsAvailable=='true' && (lvl=='lvl7' || lvl=='lvl8')) {
		$('#refine_lvl8').show();
		$('#arrow_lvl8').show();
	}

	refineSetStyles();
	
}

function addFilters($type) {
	if ($type=='producttypes') {
		$('#refine_addproducttypes').hide();
		$('#refine_lvl1').show();
	}
	if ($type=='solutions') {
		$('#refine_addsolutions').hide();
		$('#refine_solutions').show();
	}
}

function refineDefault($pageSelected) {

	// Can the product categories be selected by PHP, just like the solutions?
	if ($pageSelected == 'products_audio.php' || $pageSelected == 'products_specialeffects.php' || $pageSelected == 'products_video.php' || $pageSelected == 'products_lighting.php' || $pageSelected == 'products_consumableproducts.php' || $pageSelected == 'products_usedequipment.php') {	
		if ($pageSelected == 'products_audio.php') {$selected_pCategoryName="Audio"; $selected_pCategoryId=36;}
		if ($pageSelected == 'products_specialeffects.php') {$selected_pCategoryName="Special Effects"; $selected_pCategoryId=32;}
		if ($pageSelected == 'products_video.php') {$selected_pCategoryName="Video"; $selected_pCategoryId=8;}
		if ($pageSelected == 'products_lighting.php') {$selected_pCategoryName="Lighting"; $selected_pCategoryId=1;}
		if ($pageSelected == 'products_consumableproducts.php') {$selected_pCategoryName="Consumable Products"; $selected_pCategoryId=45;}
		if ($pageSelected == 'products_usedequipment.php') {$selected_pCategoryName="Used Equipment"; $selected_pCategoryId=46;}
		$("[name='p1']").each(function(i) {
			if ($("[name='p1']")[i].value == $selected_pCategoryId) {
				$("[name='p1']")[i].checked=true;
				selectlvl(1, $selected_pCategoryName);
			}
		});
	}

	$solutionChecked = 'false';
	$productChecked = 'false';

	$("[name='s[]']").each(function(i) {
		if($("[name='s[]']")[i].checked === true) {
			$solutionChecked = 'true';
		}
	});

	$("[name='p1']").each(function(i) {
		if($("[name='p1']")[i].checked === true) {
			$productChecked = 'true';
		}
	});
			
	if ($solutionChecked == 'true') {
		$('#refine_addsolutions').hide();
		$('#refine_solutions').show();
	}
	else {
		$('#refine_addsolutions').show();
		$('#refine_solutions').hide();
	}
	
	if ($productChecked == 'true') {
		$('#refine_addproducttypes').hide();
		$('#refine_lvl1').show();
	}
	else {
		$('#refine_addproducttypes').show();
		$('#refine_lvl1').hide();
	}	
	
}
