var bmfCommon = {
	_name: 'bmfCommon',
	_version: '0.1',
	$: function(itm)
	{
		return document.getElementById(itm);
	},
	hide: function(itm)
	{
		if(this.$(itm))
			this.$(itm).style.display = 'none';
	},
	show: function(itm)
	{
		if(this.$(itm))
			this.$(itm).style.display = 'block';
	}
}

var bmfMenu = {
		_name: 'bmfMenu',
		_version: '0.1',
		safeLimit: 20,
		staticUrlOpens: 'gemstones#show-all_investment_all|pairs-sets_statement_rarities_pairs-sets_collector#rings#gemstone|18k-platinum|14k|show-all_pearl|18k-platinum|14k|show-all_metal-fashion|18k-platinum|14k|show-all_show-all#pendants-pins#gemstone-pendants|18k-platinum|14k|show-all_metal-fashion_|18k-platinum|14k|show-all_pins-brooches_enhancers_show-all#earrings#gemstone|18k-platinum|14k|show-all_stud_metal-fashion|18k-platinum|14k|show-all_show-all#necklaces#gemstone|18k-platinum|14k|show-all_pearl_metal-fashion|18k-platinum|14k|show-all_show-all#bracelets-more#gemstone|18k-platinum|14k|show-all_metal-fashion|18k-platinum|14k|show-all_anklets_show-all#faith-patriotic#crosses-crucifixes_symbols-of-faith_medals_patriotic_lapel-pins_show-all#24k-jewelry#[blank]#special-collections#oromurano-by-leslies_chocolatoro-by-leslies_show-all#mens-jewelry#rings_|18k-platinum|14k|show-all_chains_bracelets_earrings_accessories_show-all#objets-dart#boxes_carvings_show-all#design-studio',
		setOpen: function(t0, t1, t2)
		{
			var base = this.staticUrlOpens.split('#');
			var namedBase = new Array();
			var namedSubBase = new Array();
			var cat = '';
			for(var i=0; i<base.length; i++)
			{
				if(i%2 == 0)
				{
					cat = base[i];
					namedBase[base[i]] = i/2;
				}
				base[i] = base[i].split('_');
				for(var x=0; x<base[i].length; x++)
				{
					base[i][x] = base[i][x].split('|');
					namedSubBase[cat + '.' + base[i][x][0]] = x;
				}
			}
			
			if(!t2)
				this.process('bmf-'+namedBase[t0]+'-'+namedSubBase[t0 + '.' + t1]);
			else if(!t1)
				this.process('bmf-'+namedBase[t0]);
			else if(!t0)
				this.process('bmf-0');
			else
				this.process('bmf-'+namedBase[t0]+'-'+namedSubBase[t0 + '.' + t1]+'-0');
				
				
		},
	process: function(itm)
	{
		var subs = itm.substring(4,itm.length);
		subs = subs.split('-');
			
		this.hideTop(subs);
		this.showTop(subs);
	},
	hideTop: function(sbs)
	{
		var i = 0;
		while(i < this.safeLimit && bmfCommon.$('bmf-'+i))
		{
			var x = 0;
			while(x < this.safeLimit && bmfCommon.$('bmf-'+i+'-'+x))
			{
				if(sbs[0] == i)
					this.toggle('bmf-'+i+'-'+x);
				else
					bmfCommon.hide('bmf-'+i+'-'+x);
				
				var y = 0;
				while(y < this.safeLimit && bmfCommon.$('bmf-'+i+'-'+x+'-'+y))
				{
					if(sbs[1] == x)
						this.toggle('bmf-'+i+'-'+x+'-'+y);
					else
						bmfCommon.hide('bmf-'+i+'-'+x+'-'+y);
					
					y++;
				}
				x++;
			}
			i++;
		}
	},
	showSubset: function(sb)
	{
		var i = 0;
		while(i < this.safeLimit && bmfCommon.$('bmf-'+sb[0]+'-'+i))
		{
			bmfCommon.show('bmf-'+sb[0]+'-'+i);
			i++;
		}
	},
	showSubsetInner: function(sb)
	{
		var i = 0;
		while(i < this.safeLimit && bmfCommon.$('bmf-'+sb[0]+'-'+sb[1]+'-'+i))
		{
			bmfCommon.show('bmf-'+sb[0]+'-'+sb[1]+'-'+i);
			i++;
		}
	},
	showTop: function(sb)
	{
		if(bmfCommon.$('bmf-'+sb[0]))
		{
			bmfCommon.show('bmf-'+sb[0]);
		}
		if(bmfCommon.$('bmf-'+sb[0]+'-'+sb[1]))
		{
			bmfCommon.show('bmf-'+sb[0]+'-'+sb[1]);
			this.showSubset(sb);
		}
		if(bmfCommon.$('bmf-'+sb[0]+'-'+sb[1]+'-'+sb[2]))
		{
			bmfCommon.show('bmf-'+sb[0]+'-'+sb[1]+'-'+sb[2]);
		}
		bmfCommon.show('bmf-'+sb[0]);
		bmfCommon.show('bmf-'+sb[0]+'-'+sb[1]);
		bmfCommon.show('bmf-'+sb[0]+'-'+sb[1]+'-'+sb[2]);
	},
	toggle: function(itm)
	{
		if(bmfCommon.$(itm).style.display != 'none')
			bmfCommon.hide(itm);
		else
			bmfCommon.show(itm);
	}
}


