Dvintage.SizeFilter = Class.create(
    {
        initialize: function () {
            this.SHOES			= 'SHOES';
            this.CLOTHING		= 'CLOTHING';
			this.BAGS			= 'BAGS';
			this.HATS			= 'HATS';
            this.BELTS			= 'BELTS';
			this.GLOVES			= 'GLOVES';
            this.SUNGLASSES		= 'SUNGLASSES';
            this.JEWELRY		= 'JEWELRY';
            this.WATCHES        = 'WATCHES';
            this.OTHER			= 'OTHER';

            this.GENERIC		= 'S/M/L';
            this.ITALY			= 'ITALY';
            this.UK				= 'UK';
            this.US				= 'US';
            this.FRANCE			= 'FRANCE';
            this.GERMANY		= 'GERMANY';
            this.JAPAN			= 'JAPAN';
			this.EUROPE			= 'EUR';
			this.AGE			= 'AGE';
			
			this.SIZE			= 'SIZE';

			this.category		= null;
            this.TopCategory 	= this.OTHER;
            this.country		= this.ITALY;

			this.channel		= Dvintage.channel.getChannel();

            this.matrix			= this._initSizeMatrix();
			
        },
		
        setCategory: function (category) {
			
            this.TopCategory = category;
        
		},
		
        getCategory: function () {
			
            return this.TopCategory;
			
        },
		
        setCountry: function (country) {
			
            this.country = country;
			
        },
		
        getCountry: function() {
			
            return this.country;
			
        },
		
		/*
		 * only accepts a topcategory
		 * returns all countries and their sizes.
		 */
		getAllValuesByCategory: function (category) {
			
			var values = this.matrix.get(this.channel + '_' + category);
			return values;
			
		},
		
        getDisplayValues: function(values) {
            var map = new Array(0);
            for(var i=0;i < values.length; i++) {
                 map.push(this.matrix.get(this.channel + '_' + this.TopCategory).get(this.country).get(values[i].name));
            }
            if(values.length==0) {
                map = this.matrix.get(this.channel + '_' + this.TopCategory).get(this.country).values();
            }
            return map;
        },
		
		getDisplayValue: function(value) {
            return this.matrix.get(this.channel + '_' + this.TopCategory).get(this.country).get(value);
        },
		
        getDataValue: function(value) {
            var keys = this.matrix.get(this.channel + '_' + this.TopCategory).get(this.country).keys();

            for(var i=0;i<keys.length;i++) {
                if(this.matrix.get(this.channel + '_' + this.TopCategory).get(this.country).get(keys[i]) == value) {
                    return keys[i];
                }
            }
            return null;
        },
		
		/* given unique 'internal' value size, return matches for all countries. formatted like [[FRANCE,40],[ITALY,39],...] */
		getColumnValues: function (value) {
			var returnValues = [];
			this.matrix.each(function(cat){
				if(cat[0].startsWith(Dvintage.channel.getChannel())) {
                    cat[1].each(function(column){
                        column[1].each(function(size){
                            if (size[0] == value) {
                                returnValues.push([column[0],size[1]])
                            }
                        })
                    })
                }
			})
			return returnValues;
		},

		hasSizesByName: function(category) {
            
			var hasSize = false;
			this.category = category.replace(/^\s+|\s+$/g, "");
            
			switch (this.category) {
                case 'Dresses':
                    this.TopCategory = this.CLOTHING;
                    hasSize = true;
                    break;
                case 'Pants':
                    this.TopCategory = this.CLOTHING;
                    hasSize = true;
                    break;
                case 'Tops':
                    this.TopCategory = this.CLOTHING;
                    hasSize = true;
                    break;
                case 'Jeans':
                    this.TopCategory = this.CLOTHING;
                    hasSize = true;
                    break;
                case 'Jackets':
                    this.TopCategory = this.CLOTHING;
                    hasSize = true;
                    break;
                case 'Coats':
                    this.TopCategory = this.CLOTHING;
                    hasSize = true;
                    break;
                case 'Evening Dresses':
                    this.TopCategory = this.CLOTHING;
                    hasSize = true;
                    break;
                case 'Skirts':
                    this.TopCategory = this.CLOTHING;
                    hasSize = true;
                    break;
                case 'Suits':
                    this.TopCategory = this.CLOTHING;
                    hasSize = true;
                    break;
                case 'Tops & Bottoms':
                    this.TopCategory = this.CLOTHING;
                    hasSize = true;
                    break;
                case 'Footies':
                    this.TopCategory = this.CLOTHING;
                    hasSize = true;
                    break;
                case "Heels":
                    this.TopCategory = this.SHOES;
                    hasSize = true;
                    break;
                case 'Flats':
                    this.TopCategory = this.SHOES;
                    hasSize = true;
                    break;
                case 'Boots':
                    this.TopCategory = this.SHOES;
                    hasSize = true;
                    break;
                case 'Boots Boys':
                    this.TopCategory = this.SHOES;
                    hasSize = true;
                    break;				
                case 'Boots Girls':
                    this.TopCategory = this.SHOES;
                    hasSize = true;
                    break;
                case 'Flats Boys':
                    this.TopCategory = this.SHOES;
                    hasSize = true;
                    break;
                case 'Flats Girls':
                    this.TopCategory = this.SHOES;
                    hasSize = true;
                    break;
                case 'Clutches':
                    this.TopCategory = this.BAGS;
                    hasSize = true;
                    break;
                case 'Luggage':
                    this.TopCategory = this.BAGS;
                    hasSize = true;
                    break;
                case 'Shoulder Bags':
                    this.TopCategory = this.BAGS;
                    hasSize = true;
                    break;
                case 'Small leather goods':
                    this.TopCategory = this.BAGS;
                    hasSize = true;
                    break;
                case 'Handbags':
                    this.TopCategory = this.BAGS;
                    hasSize = true;
                    break;
                case 'Totes':
                    this.TopCategory = this.BAGS;
                    hasSize = true;
                    break;	
				case 'Gloves':
                    this.TopCategory = this.GLOVES;
                    hasSize = true;
                    break;
                case 'Accessories':
                    this.TopCategory = this.OTHER;
                    hasSize = false;
                    break;
                case 'Bags':
                    this.TopCategory = this.BAGS;
                    hasSize = true;
                    break;
                case 'Clothing':
                    this.TopCategory = this.CLOTHING;
                    hasSize = true;
                    break;
                case 'Shoes':
                    this.TopCategory = this.SHOES;
                    hasSize = true;
                    break;
                case 'Hats':
                    this.TopCategory = this.HATS;
                    hasSize = true;
                    break;
                case 'Belts':
                    this.TopCategory = this.BELTS;
                    hasSize = true;
                    break;
                case 'Sunglasses':
                    this.TopCategory = this.SUNGLASSES;
                    hasSize = true;
                    break;
                case 'Jewelry':
                    this.TopCategory = this.JEWELRY;
                    hasSize = true;
                    break;
                case 'Watches':
                    this.TopCategory = this.WATCHES;
                    hasSize = true;
                    break;
                default:
                    this.TopCategory = this.OTHER;
                    hasSize = false;
            }
			return hasSize;
        },
		
        hasSizes: function(category) {
			
            return this.hasSizesByName(category.name);
       
	    },
		
        getCountries: function() {
			
            return this.matrix.get(this.channel + '_' + this.TopCategory).keys();
        
		},
		
		createNodes: function() {

			// are there sizes for this category.
			if (!this.hasSizesByName(this.category)) {
				return('');
			}

			var tdWidth	= 49;
			
			var divNode = new Element('div', {className:'sizing'});
			var table	= new Element('table', {border:0, cellspacing:1, cellpadding:0, className:'sizetable '+ this.TopCategory});
			var tbody	= new Element('tbody');

			var divV = new Element('div', {className: 'sizetablescrollarea'});
			var tableV	= new Element('table', {border:0, cellspacing:2, cellpadding:0, className:'sizetable '+ this.TopCategory});
			var tbodyV	= new Element('tbody');

			var tr		= new Element('tr').insert('<td class="p" colspan="25"><h2>' + this.TopCategory + ' SIZE CHART</h2></td>');
			var columns	= new Hash();

			// insert country table
			divNode.insert(table);
			table.insert(tbody);
			tbody.insert(tr);
			
			// insert value table
			divNode.insert(divV);
			tableV.insert(tbodyV);
			divV.insert(tableV);

			var handleMouseover = function(valueTd, index){
				valueTd.addClassName('sizetableCellover');
				var theColumn = columns.get(index);
				theColumn.invoke('addClassName', 'sizetableColumnOver');				
			};
			var handleMouseout = function(valueTd, index){
				valueTd.removeClassName('sizetableCellover');
				var theColumn = columns.get(index);
				theColumn.invoke('removeClassName', 'sizetableColumnOver');				
			};			
			

		
			// calc total width and apply to value table.
            var valuelength = this.matrix.get(this.channel + '_' + this.TopCategory).values()[0].values().length;
			var totalWidth = valuelength * tdWidth;
			tableV.setStyle({
				width: totalWidth + 'px'
			});
			
			this.matrix.get(this.channel + '_' + this.TopCategory).each(function(entry) {
			
				var country = entry[0];
				var values = entry[1];
				
				// insert country td.
				var newTr = new Element('tr')
				var newTd = new Element('td', {
					className: 'p',
					country: country
				}).update(country);
				newTr.insert(newTd);
				tbody.insert(newTr);
				
				// create new value row
				var newTrV = new Element('tr');
				tbodyV.insert(newTrV);
				
				// insert all value td's
				values.each(function(value, index){
					var valueTd = new Element('td', {
						value: value[0],
						country: country
					}).update(value[1]);
					
					if (!columns.get(index)) {
						columns.set(index, []);
					}
					var column = columns.get(index);
					column.push(valueTd);
					newTrV.insert(valueTd);
					
					// attach mouseover handler
					valueTd.observe('mouseover', function(){
						handleMouseover(valueTd, index)
					});
					valueTd.observe('mouseout', function(){
						handleMouseout(valueTd, index)
					});
					
				})
				
				
				
			});
			

			return divNode;

		},
		
		
        _initSizeMatrix: function() {

            var clothingGeneric = new Hash();
            clothingGeneric.set(20, 'XXS');
            clothingGeneric.set(21, 'XS');
            clothingGeneric.set(22, 'S');
            clothingGeneric.set(23, 'M');
            clothingGeneric.set(24, 'L');
            clothingGeneric.set(25, 'XL');

            var clothingFrance = new Hash();
            clothingFrance.set(20, '34');
            clothingFrance.set(21, '36');
            clothingFrance.set(22, '38');
            clothingFrance.set(23, '40');
            clothingFrance.set(24, '42');
            clothingFrance.set(25, '44');
            
			var clothingGermany = new Hash();
            clothingGermany.set(20, '32');
            clothingGermany.set(21, '34');
            clothingGermany.set(22, '36');
            clothingGermany.set(23, '38');
            clothingGermany.set(24, '40');
            clothingGermany.set(25, '42');
           
		    var clothingItalian = new Hash();
            clothingItalian.set(20, '38');
            clothingItalian.set(21, '40');
            clothingItalian.set(22, '42');
            clothingItalian.set(23, '44');
            clothingItalian.set(24, '46');
            clothingItalian.set(25, '48');
            
			var clothingJapan = new Hash();
            clothingJapan.set(20, '5');
            clothingJapan.set(21, '7');
            clothingJapan.set(22, '9');
            clothingJapan.set(23, '11');
            clothingJapan.set(24, '13');
            clothingJapan.set(25, '15');
            
			var clothingUk = new Hash();
            clothingUk.set(20, '6');
            clothingUk.set(21, '8');
            clothingUk.set(22, '10');
            clothingUk.set(23, '12');
            clothingUk.set(24, '14');
            clothingUk.set(25, '16');

            var clothingUs = new Hash();
            clothingUs.set(20, '0/2');
            clothingUs.set(21, '4');
            clothingUs.set(22, '6');
            clothingUs.set(23, '8');
            clothingUs.set(24, '10');
            clothingUs.set(25, '12');
			// add 101 in database
            
			var shoesItaly = new Hash();
            shoesItaly.set(100,'35');
            shoesItaly.set(101,'35.5');
            shoesItaly.set(102,'36');
            shoesItaly.set(103,'36.5');
            shoesItaly.set(104,'37');
            shoesItaly.set(105,'37.5');
            shoesItaly.set(106,'38');
            shoesItaly.set(107,'38.5');
            shoesItaly.set(108,'39');
            shoesItaly.set(109,'39.5');
            shoesItaly.set(110,'40');
            shoesItaly.set(111,'40.5');
            shoesItaly.set(112,'41');
            
			var shoesUk = new Hash();
            shoesUk.set(100,'2');
            shoesUk.set(101,'2.5');
            shoesUk.set(102,'3');
            shoesUk.set(103,'3.5');
            shoesUk.set(104,'4');
            shoesUk.set(105,'4.5');
            shoesUk.set(106,'5');
            shoesUk.set(107,'5.5');
            shoesUk.set(108,'6');
            shoesUk.set(109,'6.5');
            shoesUk.set(110,'7');
            shoesUk.set(111,'7.5');
            shoesUk.set(112,'8');
            
			var shoesUs = new Hash();
            shoesUs.set(100,'5');
            shoesUs.set(101,'5.5');
            shoesUs.set(102,'6');
            shoesUs.set(103,'6.5');
            shoesUs.set(104,'7');
            shoesUs.set(105,'7.5');
            shoesUs.set(106,'8');
            shoesUs.set(107,'8.5');
            shoesUs.set(108,'9');
            shoesUs.set(109,'9.5');
            shoesUs.set(110,'10');
            shoesUs.set(111,'10.5');
            shoesUs.set(112,'11');
            
			var shoesFrance = new Hash();
            shoesFrance.set(100,'36');
            shoesFrance.set(101,'36.5');
            shoesFrance.set(102,'37');
            shoesFrance.set(103,'37.5');
            shoesFrance.set(104,'38');
            shoesFrance.set(105,'38.5');
            shoesFrance.set(106,'39');
            shoesFrance.set(107,'39.5');
            shoesFrance.set(108,'40');
            shoesFrance.set(109,'40.5');
            shoesFrance.set(110,'41');
            shoesFrance.set(111,'41.5');
            shoesFrance.set(112,'42');

            var glovesGeneric = new Hash();
            glovesGeneric.set(10,'XS');
            glovesGeneric.set(11,'S');
            glovesGeneric.set(12,'M');
            glovesGeneric.set(13,'L');
            glovesGeneric.set(14,'XL');
            
			var glovesSize = new Hash();
            glovesSize.set(10,'6 - 6.5');
            glovesSize.set(11,'7 - 7.5');
            glovesSize.set(12,'8 - 8.5');
            glovesSize.set(13,'9 - 9.5');
            glovesSize.set(14,'10 - 10.5');

            var bagsGeneric = new Hash();
            bagsGeneric.set(30,'S');
            bagsGeneric.set(31,'M');
            bagsGeneric.set(32,'L');

			var kidsShoesEur = new Hash();
            kidsShoesEur.set(1000,'17');
            kidsShoesEur.set(1001,'18');
            kidsShoesEur.set(1002,'19');
            kidsShoesEur.set(1003,'20');
            kidsShoesEur.set(1004,'21');
            kidsShoesEur.set(1005,'22');
            kidsShoesEur.set(1006,'23');
            kidsShoesEur.set(1007,'24');
            kidsShoesEur.set(1008,'25');
            kidsShoesEur.set(1009,'26');
            kidsShoesEur.set(1010,'27');
            kidsShoesEur.set(1011,'28');
            kidsShoesEur.set(1012,'29');
            kidsShoesEur.set(1013,'30');
            kidsShoesEur.set(1014,'31');
            kidsShoesEur.set(1015,'32');
            kidsShoesEur.set(1016,'33');
            kidsShoesEur.set(1017,'34');
            kidsShoesEur.set(1018,'35');
            kidsShoesEur.set(1019,'36');
            kidsShoesEur.set(1020,'37');
            kidsShoesEur.set(1021,'38');
            kidsShoesEur.set(1022,'39');

			var kidsShoesUs = new Hash();
            kidsShoesUs.set(1000,'1.5 - 2');
            kidsShoesUs.set(1001,'2.5 - 3');
            kidsShoesUs.set(1002,'3.5 - 4');
            kidsShoesUs.set(1003,'4.5 - 5');
            kidsShoesUs.set(1004,'5.5');
            kidsShoesUs.set(1005,'6 - 6.5');
            kidsShoesUs.set(1006,'7 - 7.5');
            kidsShoesUs.set(1007,'8');
            kidsShoesUs.set(1008,'8.5 - 9');
            kidsShoesUs.set(1009,'9.5');
            kidsShoesUs.set(1010,'10 - 10.5');
            kidsShoesUs.set(1011,'11');
            kidsShoesUs.set(1012,'11.5');
            kidsShoesUs.set(1013,'12');
            kidsShoesUs.set(1014,'13 - 13.5');
            kidsShoesUs.set(1015,'1');
            kidsShoesUs.set(1016,'1.5 - 2');
            kidsShoesUs.set(1017,'2.5 - 3');
            kidsShoesUs.set(1018,'3.5');
            kidsShoesUs.set(1019,'4 - 4.5');
            kidsShoesUs.set(1020,'5 - 5.5');
            kidsShoesUs.set(1021,'6 - 6.5');
            kidsShoesUs.set(1022,'7');

			var kidsShoesUk = new Hash();
            kidsShoesUk.set(1000,'1');
            kidsShoesUk.set(1001,'1.5 - 2');
            kidsShoesUk.set(1002,'2.5 - 3');
            kidsShoesUk.set(1003,'3.5 - 4');
            kidsShoesUk.set(1004,'4.5');
            kidsShoesUk.set(1005,'5 - 5.5');
            kidsShoesUk.set(1006,'6 - 6.5');
            kidsShoesUk.set(1007,'7');
            kidsShoesUk.set(1008,'7.5 - 8');
            kidsShoesUk.set(1009,'8.5');
            kidsShoesUk.set(1010,'9 - 9.5');
            kidsShoesUk.set(1011,'10');
            kidsShoesUk.set(1012,'10.5');
            kidsShoesUk.set(1013,'11');
            kidsShoesUk.set(1014,'12 - 12.5');
            kidsShoesUk.set(1015,'13');
            kidsShoesUk.set(1016,'1');
            kidsShoesUk.set(1017,'1.5 - 2');
            kidsShoesUk.set(1018,'2.5');
            kidsShoesUk.set(1019,'3 - 3.5');
            kidsShoesUk.set(1020,'4 - 4.5');
            kidsShoesUk.set(1021,'5 - 5.5');
            kidsShoesUk.set(1022,'6');
			
			var kidsClothingAge = new Hash();
            kidsClothingAge.set(1100, '0M');
            kidsClothingAge.set(1101, '1M');
            kidsClothingAge.set(1102, '3M');
            kidsClothingAge.set(1103, '6M');
            kidsClothingAge.set(1104, '9M');
            kidsClothingAge.set(1105, '12M');
            kidsClothingAge.set(1106, '18M');
            kidsClothingAge.set(1107, '24M');
            kidsClothingAge.set(1108, '2 - 3');
            kidsClothingAge.set(1109, '3 - 4');
            kidsClothingAge.set(1110, '4 - 5');
            kidsClothingAge.set(1111, '5 - 6');
            kidsClothingAge.set(1112, '6 - 7');
            kidsClothingAge.set(1113, '8 - 10');
            kidsClothingAge.set(1114, '10 - 12');
            kidsClothingAge.set(1115, '12 - 14');
            kidsClothingAge.set(1116, '14 - 16');
            kidsClothingAge.set(1117, '16 - 18');

			var kidsClothingGerman = new Hash();
            kidsClothingGerman.set(1100, '50');
            kidsClothingGerman.set(1101, '56');
            kidsClothingGerman.set(1102, '62');
            kidsClothingGerman.set(1103, '68');
            kidsClothingGerman.set(1104, '74');
            kidsClothingGerman.set(1105, '80');
            kidsClothingGerman.set(1106, '86');
            kidsClothingGerman.set(1107, '92');
            kidsClothingGerman.set(1108, '98');
            kidsClothingGerman.set(1109, '104');
            kidsClothingGerman.set(1110, '110');
            kidsClothingGerman.set(1111, '116');
            kidsClothingGerman.set(1112, '128');
            kidsClothingGerman.set(1113, '140');
            kidsClothingGerman.set(1114, '152');
            kidsClothingGerman.set(1115, '164');
            kidsClothingGerman.set(1116, '170');
            kidsClothingGerman.set(1117, '176');

			var kidsClothingFrench = new Hash();
            kidsClothingFrench.set(1100, '50');
            kidsClothingFrench.set(1101, '56');
            kidsClothingFrench.set(1102, '60');
            kidsClothingFrench.set(1103, '67');
            kidsClothingFrench.set(1104, ' - ');
            kidsClothingFrench.set(1105, '74');
            kidsClothingFrench.set(1106, '81');
            kidsClothingFrench.set(1107, '86');
            kidsClothingFrench.set(1108, '94');
            kidsClothingFrench.set(1109, '102');
            kidsClothingFrench.set(1110, '110');
            kidsClothingFrench.set(1111, '114');
            kidsClothingFrench.set(1112, '126');
            kidsClothingFrench.set(1113, '138');
            kidsClothingFrench.set(1114, '150');
            kidsClothingFrench.set(1115, '162');
            kidsClothingFrench.set(1116, '168');
            kidsClothingFrench.set(1117, '174');

			var kidsClothingUsa = new Hash();
            kidsClothingUsa.set(1100, ' - ');
            kidsClothingUsa.set(1101, '0M');
            kidsClothingUsa.set(1102, '3M');
            kidsClothingUsa.set(1103, '6M');
            kidsClothingUsa.set(1104, '9M');
            kidsClothingUsa.set(1105, '12M');
            kidsClothingUsa.set(1106, ' - ');
            kidsClothingUsa.set(1107, '2T');
            kidsClothingUsa.set(1108, '3T');
            kidsClothingUsa.set(1109, '4T');
            kidsClothingUsa.set(1110, '5T');
            kidsClothingUsa.set(1111, '6T');
            kidsClothingUsa.set(1112, '7T');
            kidsClothingUsa.set(1113, '8T');
            kidsClothingUsa.set(1114, '10T');                                                               
            kidsClothingUsa.set(1115, '12 - 14T');
            kidsClothingUsa.set(1116, '14 - 16T');
            kidsClothingUsa.set(1117, '16 - 18T');

			var kidsGlovesGeneric = new Hash();
            kidsGlovesGeneric.set(1200, 'S');
            kidsGlovesGeneric.set(1201, 'M');
            kidsGlovesGeneric.set(1202, 'L');

            var hatsGeneric = new Hash();
            hatsGeneric.set(1300,'S');
            hatsGeneric.set(1301,'M');
            hatsGeneric.set(1302,'L');

            var beltsGeneric = new Hash();
            beltsGeneric.set(1400,'S');
            beltsGeneric.set(1401,'M');
            beltsGeneric.set(1402,'L');

            // --------------------------------------------------------------------------------
            var clothing = new Hash();
            clothing.set(this.GENERIC, clothingGeneric);
            clothing.set(this.FRANCE, clothingFrance);
            clothing.set(this.GERMANY, clothingGermany);
            clothing.set(this.ITALY, clothingItalian);
            clothing.set(this.JAPAN, clothingJapan);
            clothing.set(this.UK, clothingUk);
            clothing.set(this.US, clothingUs);

            var kidsClothing = new Hash();
            kidsClothing.set(this.AGE, kidsClothingAge);
            kidsClothing.set(this.GERMANY, kidsClothingGerman);
            kidsClothing.set(this.FRANCE, kidsClothingFrench);
            kidsClothing.set(this.US, kidsClothingUsa);

            var shoes = new Hash();
            shoes.set(this.FRANCE, shoesFrance);
            shoes.set(this.ITALY, shoesItaly);
            shoes.set(this.UK, shoesUk);
            shoes.set(this.US, shoesUs);

            var kidsShoes = new Hash();
            kidsShoes.set(this.EUROPE, kidsShoesEur);
            kidsShoes.set(this.US, kidsShoesUs);
            kidsShoes.set(this.UK, kidsShoesUk);

			var gloves = new Hash();
			gloves.set(this.GENERIC, glovesGeneric);
			gloves.set(this.SIZE, glovesSize);

			var kidsGloves = new Hash();
			kidsGloves.set(this.GENERIC, kidsGlovesGeneric);

			var bags = new Hash();
			bags.set(this.GENERIC, bagsGeneric);

            var hats = new Hash();
            hats.set(this.GENERIC, hatsGeneric);

            var belts = new Hash();
            belts.set(this.GENERIC, beltsGeneric);

            var sunglasses = new Hash();
            sunglasses.set(this.GENERIC, beltsGeneric);

            var jewelry = new Hash();
            jewelry.set(this.GENERIC, beltsGeneric);

            var watches = new Hash();
            watches.set(this.GENERIC, beltsGeneric);

            // build the final matrix
            var matrix = new Hash();
            matrix.set('women_' + this.CLOTHING, clothing);
            matrix.set('women_' + this.SHOES, shoes);
            matrix.set('women_' + this.GLOVES, gloves);
            matrix.set('women_' + this.BAGS, bags);
			matrix.set('women_' + this.BELTS, belts);
			matrix.set('women_' + this.SUNGLASSES, sunglasses);
			matrix.set('women_' + this.JEWELRY, jewelry);
			matrix.set('women_' + this.WATCHES, watches);

            matrix.set('fashion_' + this.CLOTHING, clothing);
            matrix.set('fashion_' + this.SHOES, shoes);
            matrix.set('fashion_' + this.GLOVES, gloves);
            matrix.set('fashion_' + this.BAGS, bags);
			matrix.set('fashion_' + this.BELTS, belts);
            matrix.set('fashion_' + this.SUNGLASSES, sunglasses);
            matrix.set('fashion_' + this.JEWELRY, jewelry);
            matrix.set('fashion_' + this.WATCHES, watches);

			matrix.set('kids_' + this.SHOES, kidsShoes);
			matrix.set('kids_' + this.CLOTHING, kidsClothing);
            matrix.set('kids_' + this.GLOVES, kidsGloves);
            matrix.set('kids_' + this.BAGS, bags);			/* same as women */
            matrix.set('kids_' + this.HATS, hats);
            matrix.set('kids_' + this.BELTS, belts);
            matrix.set('kids_' + this.SUNGLASSES, sunglasses);
            matrix.set('kids_' + this.JEWELRY, jewelry);
            matrix.set('kids_' + this.WATCHES, watches);

            return matrix;
        }
    }
);



// called onchange...
Dvintage.configureSizes = function() {
	

	var SHOES_TEXT = 'Please specify the length of the shoe by measuring from heel to toe. Specify the width by measuring the broadest part of the sole.';
	var BAGS_TEXT = 'Please specify the height and width of your designer bag.';
	var HATS_TEXT= 'Please specify the width and length of your designer hat.';
	var CLOTHS_TEXT = 'Please specify the bust-waist-hips and total length measurements of your designer piece. Just lay it out flat and, for example, measure from armpit to armpit for the bust size. Don’t forget to multiply..For the length of a pair of trousers measure the innerleg. And so on.';
	var BELTS_TEXT = 'Please specify the total length and also measure the height of the belt. Don’t forget to click inches or centimeters...';
	var GLOVES_TEXT = 'Please specify the length of the gloves by measuring the length of the middle finger. Specify the width by measuring the broadest part of the glove.';
	var SCARVES_TEXT = 'Please specify the length and the height of your scarve. Lay it out flat and measure the sides.';
	var SUNGLASSES_TEXT = 'Please specify the total length of the front and also measure the height of the sunglasses. Don’t forget to click inches or centimeters...';
    var JEWELRY_TEXT = 'Please specify the total length and also measure the height of the jewelry. Don’t forget to click inches or centimeters...';
    var WATCHES_TEXT = 'Please specify the total length and also measure the height of the watch. Don’t forget to click inches or centimeters...';

    var sf = new Dvintage.SizeFilter();
	var selectedOption = $('category').options[$('category').selectedIndex];
	var selectedValue = selectedOption.readAttribute('textvalue');
	
	// sets correct cat:
    sf.hasSizesByName(selectedValue);

	// step 3 needs extra height when no sizes table is present. button needs to go down as well
	if (sf.category != 'CLOTHING' && sf.category != 'SHOES') {
		$$('#makemehigherelement').invoke('remove');
//		var makeMeHigherElement = new Element('p', {id:'makemehigherelement'}).setStyle({height:'168px'});
//		$('step3').insert(makeMeHigherElement);
//		$('step3').setStyle({marginTop:'145px'});
		
	} else {
		if ($('makemehigherelement')) {
			$('makemehigherelement').remove();
//			$('step3').setStyle({marginTop:'-20px'});
		}
	}


	// show correct table
	/*
    $$('.sizing').each(function(element, i) {
        if(element.readAttribute('sizes_of') == sf.category) {
            element.show();
        } else {
            element.hide();
        }
    })
	*/
	
	var createMeasurementsTable = function (vals) {
		// initialize:
		$$('.measurementstable').each(function(tbl){tbl.remove();})

		// fix #108: IE misses camelcase. 
		if ($('measurementUnit')) {
			$('measurementUnit').remove();
		}
		if ($('measurementunit')) {
			$('measurementunit').remove();
		}
		// end fix #108.

		var hiddeninput = $$('input[name=size]')[0]; hiddeninput.value="0";
		var originalSize = $$('input[name=originalSize]')[0]; originalSize.value="0";
		var features = $$('input[name=features]')[0]; features.value="";

		var measurementstable = new Element('table', {border:0,cellspacing:0,cellpadding:0,className:'measurementstable'});
		measurementstableb = new Element('tbody');
		measurementstable.insert(measurementstableb);
		measurementstableb.update('<tr><td colspan="' + vals.measurements.length + '"><h2>MEASUREMENTS</h2></td></tr>');
		var tr = new Element('tr');
		measurementstableb.insert(tr);
		if (vals.radio) {
			var td = new Element('td');
			var insertAsRadio = {
				name:'unitlesssize',
				childNodes: vals.measurements.collect(function(val){return {value:val,html:val}})	// childNodes: [{value:val,html:val}, ...]
			}
			tr.insert(td);
			var unitlesssizeRadio = new Dvintage.Radioinput(td,{insertNodes: insertAsRadio});
			unitlesssizeRadio.setCallBack(Dvintage.createFeatureString);
		} else {
			vals.measurements.each(function(val, index){
				var td = new Element('td');
				// are there sererate labels?
				if (vals.labels) {
					td.update(vals.labels[index]);										
				} else {
					td.update(val);					
				}
				tr.insert(td);
			})
			tr = new Element('tr');
			measurementstableb.insert(tr);
			vals.measurements.each(function(val) {
				var td = new Element('td');
				var propername = val.replace(' ', '');
				var input = new Element('input', {type:'text', className:'measurements',name:propername})
				td.insert(input);
				tr.insert(td);
				input.observe('change', Dvintage.createFeatureString);
			})
		}
		
		$('conditionheadercomment').insert({before:measurementstable});
		
		// update comment text:
		$('measurementscomment').update(vals.commenttext);
		
	}
	
	var measurementsPerCat = {
    	Coats:{radio:false,measurements:['bust','waist','hips','total length'], commenttext: CLOTHS_TEXT},
		Dresses:{radio:false,measurements:['bust','waist','hips','total length'], commenttext: CLOTHS_TEXT},
		'Evening Dresses':{radio:false,measurements:['bust','waist','hips','total length'], commenttext: CLOTHS_TEXT},
		Jackets:{radio:false,measurements:['bust','waist','hips','total length'], commenttext: CLOTHS_TEXT},
		Jeans:{radio:false,measurements:['waist','hips','total length'], labels:['waist','hips','innerleg length'], commenttext: CLOTHS_TEXT},
		Pants:{radio:false,measurements:['waist','hips','total length'], labels:['waist','hips','innerleg length'], commenttext: CLOTHS_TEXT},
		Skirts:{radio:false,measurements:['waist','hips','total length'], commenttext: CLOTHS_TEXT},
		Suits:{radio:false,measurements:['bust','waist','hips','total length'], commenttext: CLOTHS_TEXT},
		Tops:{radio:false,measurements:['bust','waist','hips','total length'], commenttext: CLOTHS_TEXT},
		'Tops & Bottoms':{radio:false,measurements:['width','length'], commenttext: CLOTHS_TEXT},	/*kids*/
		Footies:{radio:false,measurements:['width','length'], commenttext: CLOTHS_TEXT},			/*kids*/
		Boots:{radio:false,measurements:['width','length'], commenttext: SHOES_TEXT},
		'Boots Boys':{radio:false,measurements:['width','length'], commenttext: SHOES_TEXT},	/*kids*/
		'Boots Girls':{radio:false,measurements:['width','length'], commenttext: SHOES_TEXT},	/*kids*/
		'Flats Boys':{radio:false,measurements:['width','length'], commenttext: SHOES_TEXT},	/*kids*/
		'Flats Girls':{radio:false,measurements:['width','length'], commenttext: SHOES_TEXT},	/*kids*/
		Flats:{radio:false,measurements:['width','length'], commenttext: SHOES_TEXT},
		Heels:{radio:false,measurements:['width','length', 'height of heels'], commenttext: SHOES_TEXT},
		Clutches:{radio:false,measurements:['height','width'], commenttext: BAGS_TEXT},
		Luggage:{radio:false,measurements:['height','width'], commenttext: BAGS_TEXT},
		'Shoulder Bags':{radio:false,measurements:['height','width'], commenttext: BAGS_TEXT},
		Handbags:{radio:false,measurements:['height','width'], commenttext: BAGS_TEXT},
		'Small leather goods':{radio:false,measurements:['height','width'], commenttext: BAGS_TEXT},
		Totes:{radio:false,measurements:['height','width'], commenttext: BAGS_TEXT},
		Belts:{radio:false,measurements:['length','height'], commenttext: BELTS_TEXT},
        Sunglasses:{radio:false,measurements:['length','height'], commenttext: SUNGLASSES_TEXT},
        'Jewelry':{radio:false,measurements:['length','height'], commenttext: JEWELRY_TEXT},
        'Watches':{radio:false,measurements:['length','height'], commenttext: WATCHES_TEXT},
		Gloves:{radio:false,measurements:['width','length'], commenttext: GLOVES_TEXT},
		Scarves:{radio:false,measurements:['length','height'], commenttext: SCARVES_TEXT},
        'Hats':{radio:false,measurements:['width','length'], commenttext: HATS_TEXT},
        'Bags':{radio:false,measurements:['height','width'], commenttext: BAGS_TEXT}
	}

	createMeasurementsTable(measurementsPerCat[selectedValue]);
	
	if (!measurementsPerCat[selectedValue]['radio']) {
		var container = new Element('div');
		$('conditionheader').insert({before:container});
		var insertAsRadio = {
			id:'measurementUnit',
			name:'measurementUnit',
			childNodes: [{value:'cm',html:'CM'},{value:'inches',html:'INCHES'}]
		}
		Dvintage.measurementUnitRadio = new Dvintage.Radioinput(container, {insertNodes: insertAsRadio});
		Dvintage.measurementUnitRadio.setCallBack(Dvintage.createFeatureString);
		Dvintage.measurementUnitRadio.setValue('cm');
	}

}