// AF INC
// ContentFilter common JS
$.getScript("/js/ui.core.js");
$.getScript("/js/ui.tabs.js");


$(document).ready(function(){
	// on init hide all content-set-item DIVs

	 resetContentSet();
	 $.log("set radio");
    $(".ContentFilter-module .filter-container input:radio").attr('checked', false); 
    $(".ContentFilter-module .filter-container input:radio").click(onFilterChange);
	
	
});

function onFirstFilterClick(){
	
	return false;
}

function onFilterChange(){
	$.log("Filter Change 3");
    var selValue = "";
    var selDesc = "Selected filter option : ";
 	
	$.log( $(this).parents("div.filter-container"));
	
	if(  $(this).parents(".filter_options_fieldset_box").hasClass("first") && !$(".filter-container .second").hasClass("expanded") ){
		$(".filter-container .second").addClass("expanded");
		$(".filter-container .second").removeClass("hidden");
	}

    
	
    $(this).parents("div.filter-container").find("input:checked").each(function(){
    	$.log("radio:"+$(this).attr('name'));
    	selValue += $(this).val() + "_";
        selDesc += $(this).parents(".filter_options_fieldset_box").find(".filter_heading").html()+" "+$(this).next("label").html() + " ";
    });
    
	var showId = "#content-set_"+selValue.substr(0,selValue.length-1);
	resetContentSet();
	$.log("Filter Change:Show "+showId);
	$(showId).removeClass("content-set-item-hide");
	
	/* need to find a better place for this*/
	/* weird bug: don't need this line if firebug is open i.e. works with this line handled on ready()*/
	if( !$(showId+" .jquery-tabs").hasClass("ui-tabs") ){
		$(showId+" .jquery-tabs").tabs();
	}
	
	selDesc = selDesc.replace(".", " ");
    
    $(this).parents("div.filter-container").find("div.filter-live-region").each(function(){
    	$(this).html("");
        $(this).append("<span>"+selDesc+"</span>");
    });
   
}

function resetContentSet(){
	$.log( "resetContentSet:ENTRY" );
    $(".content-set .content-set-item").each(
    	function(){
        	$.log( "resetContentSet:"+$(this).attr("id") );
        	$(this).addClass("content-set-item-hide");
        }
     );
}
