function filter_factory(are_hidden_form_fields_static, are_form_field_value_filters_static, item, the_look_key) {

	this.are_hidden_form_fields_static			= are_hidden_form_fields_static;
	this.are_form_field_value_filters_static	= are_form_field_value_filters_static;
	this.item									= item;
	this.the_look_key							= the_look_key;

	this.hidden_form_fields;
	this.form_field_value_filters;

	this.is_value_static = function(static_variable_name) {
		var is_static = (typeof this['are_' + static_variable_name + '_static'] === 'undefined')? false : this['are_' + static_variable_name + '_static'];
		return is_static;
	}

	this.set_static_value = function(static_variable_name) {
		if (typeof this[static_variable_name] === 'undefined') {
			var foo = '__get_' + static_variable_name;
			var val = this[foo]();
			this[static_variable_name] = val;
		}
	}

	this.get_filter = function(static_variable_name) {
		var result;
		var is_static = this.is_value_static(static_variable_name);
		if (is_static) {
			this.set_static_value(static_variable_name);
			result = this[static_variable_name];
		}
		else {
			var foo = '__get_' + static_variable_name;
			result = this[foo]();
		}
		return result;
	}

	this.get_hidden_form_fields = function() {
		var static_variable_name = 'hidden_form_fields';
		return this.get_filter(static_variable_name);
	}

	this.get_form_field_value_filters = function() {
		var static_variable_name = 'form_field_value_filters';
		return this.get_filter(static_variable_name);
	}

	// --------------------------------------------------------------------------------------------

	this.sku_restrictions = {
		"bold":	{
			"fabrics":		{
								"default":	["G101","G204","G205","G210","G218","G304"]
							},
			"hide_piping":	["PNB","PKBNC"]
		},
		"crisp":	{
			"fabrics":		{
								"default":	["G101","G201","G204","G205","G215","G304"]
							},
			"hide_piping":	[]
		},
		"zen":	{
			"fabrics":		{
								"default":	["G207","G208","G211","G214","G304","G305"]
							},
			"hide_piping":	[]
		},
		"serene":	{
			"fabrics":		{
								"default":	["G203","G207","G209","G211","G303","G305"]
							},
			"hide_piping":	[]
		},
		"eclectic":	{
			"fabrics":		{
								"default":	["G206","G208","G212","G216","G304","G306"]
							},
			"hide_piping":	[]
		},
		"earthy":	{
			"fabrics":		{
								"FMBN":		["G208","G211","G207","G203","G305"],
								"CH13-N":	["G208","G207","G203","G305","G306"]
							},
			"hide_piping":	[]
		}
	};

	// --------------------------------------------------------------------------------------------

	this.__get_hidden_form_fields = function() {
		var result;
	/*
		result = null;
		if (
				(typeof this.the_look_key === 'undefined')
			||	(typeof this.sku_restrictions[this.the_look_key] === 'undefined')
			||	(typeof this.sku_restrictions[this.the_look_key].hide_piping === 'undefined')
			||	(this.sku_restrictions[this.the_look_key].hide_piping.length === 0)
			||	($.inArray(this.item.sku, this.sku_restrictions[this.the_look_key].hide_piping) === -1)
		) {return result;}
	*/
		result = [this.item.form_field_aliases.piping_fabric];
		return result;
	}

	// --------------------------------------------------------------------------------------------

	this.__get_form_field_value_filters = function() {
		var result = null;
		if (
				(typeof this.the_look_key === 'undefined')
			||	(typeof this.sku_restrictions[this.the_look_key] === 'undefined')
			||	(typeof this.sku_restrictions[this.the_look_key].fabrics === 'undefined')
		) {return result;}

		var whitelist = [];

		if (typeof this.sku_restrictions[this.the_look_key].fabrics[this.item.sku] !== 'undefined') {
			whitelist = this.sku_restrictions[this.the_look_key].fabrics[this.item.sku];
		}
		else if (typeof this.sku_restrictions[this.the_look_key].fabrics['default'] !== 'undefined') {
			whitelist = this.sku_restrictions[this.the_look_key].fabrics['default'];
		}

		if (whitelist.length === 0) {return result;}

		result = {"main_fabric":{"whitelist": whitelist}};
		return result;
	}

	// --------------------------------------------------------------------------------------------
}

var thelook_filter_factory;

function load_filter_factory(caller) {
	if (typeof thelook_filter_factory === 'undefined') {
		thelook_filter_factory = new filter_factory(true, true, caller, the_look_key);
	}
}

function get_hidden_form_fields(caller) {
	load_filter_factory(caller);
	return thelook_filter_factory.get_hidden_form_fields();
}

function get_form_field_value_filters(caller) {
	load_filter_factory(caller);
	return thelook_filter_factory.get_form_field_value_filters();
}

