
// Sitemap Dropdown //

var showSiteMap = true;
    function toggleMenu() {
      if (showSiteMap) {
        Element.toggleClassName($('sitemap-button'), 'open');
        Element.toggleClassName($('sitemap-button'), 'closed');
        Effect.BlindDown('sitemap-top', {duration: 0.5});
        showSiteMap = false;
      } else {
        Element.toggleClassName($('sitemap-button'), 'closed');
        Element.toggleClassName($('sitemap-button'), 'open');
        Effect.BlindUp('sitemap-top', {duration: 0.5});
        showSiteMap = true;
      }
      return false;
    }


// Tabs - sitewide //

var salonTabs = Class.create();

salonTabs.prototype = {
	initialize : function(element) {
		this.element = $(element);
		var options = Object.extend({}, arguments[1] || {});
		this.menu = $A(this.element.getElementsByTagName('a'));
		this.show(this.getInitialTab());
		this.menu.each(this.setupTab.bind(this));
	},
	setupTab : function(elm) {
		Event.observe(elm,'click',this.activate.bindAsEventListener(this),false);
	},
	activate : function(ev) {
		var elm = Event.findElement(ev, "a");
		Event.stop(ev);
		this.show(elm);
		this.menu.without(elm).each(this.hide.bind(this));
	},
	hide : function(elm) {
		$(elm).removeClassName('selectedTab');
		//$(this.tabID(elm)).addClassName('tabBody');
		$(this.tabID(elm)).setStyle({display:'none'});
	},
	show : function(elm) {
		$(elm).addClassName('selectedTab');
		//$(this.tabID(elm)).addClassName('selectedBody');
		$(this.tabID(elm)).setStyle({display:'block'});
	},
	tabID : function(elm) {
		return elm.rel.match(/#(\w.+)/)[1];
	},
	getInitialTab : function() {
		if(document.location.href.match(/#(\w.+)/)) {
			var loc = RegExp.$1;
			var elm = this.menu.find(function(value) { return value.rel.match(/#(\w.+)/)[1] == loc; });
			return elm || this.menu.first();
		} else {
			return this.menu.first();
		}
	}
}

Event.observe(window,'load',function() { 
	$$('.section_tabs').each(function(tab_group) {
		new salonTabs(tab_group);
	});
});


// Margins //


document.observe("dom:loaded", function() {
	
	// Promo Boxes Sitewide //
	
	$$('.promo ul.content li:nth-child(odd)').invoke('addClassName','oddRow');
	
	
	// Food Cover //
	
	$$('.foodRecipes ul li:nth-child(odd)','.foodSection ul li:nth-child(odd)').invoke(
		'setStyle',{marginRight: '20px'}
	);
	
	$$('.kitchenCabinet ul li:nth-child(odd)').invoke(
		'setStyle',{marginRight: '20px'}
	);
	
	//Recipes Nav //
	
	var recipeTopic = $('col12_overhead').down(0).next('h1').down(0).innerHTML;
	
	$$('#recipes_index .relateds li a').each(function(ev) {
		this.element = $(ev);
		var elmt = this.element.innerHTML;
		
		if (elmt==recipeTopic) {
			this.element.addClassName('active');
		};
		
	});
	
});

