var Filter = {
	filter:false,
	categories:{
		"Hand Made":{},
		"Wear":{
			"Baby 0-24":{
				"Boys":"",
				"Girls":""
			},
			"Toddler 2-4":{
				"Boys":"",
				"Girls":""
			},
			"Shoes":{
				"Boys":{
					"0-24":"",
					"2-5":""
				},
				"Girls":{
					"0-24":"",
					"2-5":""						
				}
			}
		},
		"Decor":{
			"Bedding":"",
			"Wall Art":{
				"Wall Stickers":"",
				"Wall Paper":"",
				"Canvas Art":"",
				"Frames":""
			},
			"Lighting":"",
			"Mobiles":"",
			"Storage":"",
			"Growth Charts":""
		},
		"Play":{
			"Baby":"",
			"Toddler":{
				"Dolls":"",
				"Arts + Crafts":"",
				"Pretend Play":"",
				"Games + Puzzles":"",
				"Musical Instruments":"",
				"Ride on":"",
				"Wood":"",
				"Bath":""
			},
			"Big Kid":{
				"Arts + Crafts":"",
				"Pretend Play":"",
				"Games + Puzzles":"",
				"Science":""				
			}
		},
		"Books":{
			"Board":"",
			"Soft":"",
			"Hard Cover":""
		},
		"Gear":{
			"Blankets":"",
			"Wash":"",
			"Diaper bags":"",
			"Carriers":"",
			"Feeding":{
				"Bottles":"",
				"Bibs":"",
				"Cups":"",
				"Dishes":"",
				"Utensils":""
			},
			"Accessories":"",
			"Maternity":""
		}
	},
	
	Menu:{
		// variables
		
		// methods
		Build:function(list, depth, upper)
		{

			var nodes	= list.slice(17, list.length)
			regex = /\[|\]/g
			nodes = nodes.replace(regex, "");
			
			regex = /\'\'/g
			nodes = nodes.replace(regex, "|");
			
			regex = /\'/g
			nodes = nodes.replace(regex, "");
			
			nodes = nodes.split("|");
			nodes[0] = nodes[0].toUpperCase();
			nodes = nodes.join("|");
			
			for(prop in eval(list))
			{
				var text	= !upper ? prop : prop.toUpperCase();
				var data	= nodes.length < 1 ? text : nodes + "|" + text;
				var parent 	= $("#Menu li[data='" + data + "']");
				var href	= depth == 0 ? $(parent).children(0).attr("href") + "?Filter=" + Filter.Safe(prop) : $(parent).children(0).attr("href");
				parent.find("a").bind('click', function(){Filter.Menu.Toggle(this);return false;})
				var items	= list;
				items		+= "['" + prop + "']";

				// add to list
				parent.append(this.Sub(prop, eval(items), href, data));				
								
				// check for children
				if(Filter.Type(eval(items)))
				{
					Filter.Menu.Build(items, (depth + 1), false, parent.html());
					var all		= $(parent.find("a").get(0));
					var text	= all.text();
					var href	= all.attr("href")
					var ul		= all.parent().find("ul");
					ul 			= ul.get(0);
					$(ul).prepend("<li><a href=\"" + href + "\">All " + text + "</a></li>");
				}
			}
		},
		
		Sub:function(parent, children, href, data)
		{
			var ul	= $(document.createElement("ul"));
			for(prop in children)
			{
				url = href + "|" + Filter.Safe(prop);
				ul.append(this.Item(prop, url, data));
			}
			return ul;
		},
		
		Item:function(text, href, data)
		{
			var li	= $(document.createElement("li"));
			li.attr({data:(data + "|" + text)})
			var a	= $(document.createElement("a"));
			a.attr({href:href})
			li.append(a.append(text));
			return li;
		},
		
		Toggle:function(obj)
		{
			if($(obj).parent().find("ul").length > 1)
			{
				var ul = $(obj).parent().find("ul").get(0);
				$(ul).css("display") == "none" ? $(ul).slideDown() : $(ul).slideUp();				
			}
			else
			{
				window.location = $(obj).attr("href");
			}
		}
	},
	
	Highlight:function(filter)
	{
		filter 		= filter.split("|");
		var data	= "";
		for(prop in filter)
		{
			data += prop == 0 ? filter[prop].toUpperCase() : filter[prop];
			var a	= $("#Menu li[data='" + data + "'] a").get(0);
			$(a).addClass("on");
			var text	= $(a).text();
			data += "|";
			
			$(a).next().css({"display":"block"})
		}
		$(a).parent().find("a:contains('All " + text + "')").addClass("on");		
	},
	
	Safe:function(string)
	{
		regex = /\+/g
		string = string.replace(regex, "%2B");
		
		regex = /\s/g
		string = string.replace(regex, "+");
		
		return string;		
	},
	
	Type:function(o)
	{
		return !!o && Object.prototype.toString.call(o).match(/(\w+)\]/)[1];
	}	
}