/* CategoryPopUp
----------------------------------------------------------------------------------------*/
var CategoryPopUp = Class.create(CenteredPop, {
	initialize: function($super, trigger, popup){
		this.trigger = trigger;
		this.popup   = popup;
		this.container = this.trigger.up(".product");

		this.options = {
			onOpen:  this._open.bind(this),
			onClose: this._close.bind(this),
			modal: false
		};
		
		this.bound_close = this._close.bind(this);
		
		$super(this.trigger, this.popup, this.options);
	},
	_open: function() {
		this.popup.down(".hdr_common").update(this.trigger.title);
		this.popup.down(".overlay_content").update(this.container.innerHTML);
		this.popup.down(".overlay_content").down(".hidden").removeClassName("hidden");
		this.popup.down(".overlay_content").down("h4").remove();
		
		var view = this.popup.down(".overlay_content").down(".view")
		view.setAttribute("href", this.trigger.href);
		view.innerHTML = "View Category &raquo;";
		this.container.addClassName("on");
	},
	_close: function() {
		this.container.removeClassName("on");
	}
});

/*----------------------------------------------------------------------------------------*/

document.observe('dom:loaded', function(){
	if ($('brands')) {
		new ShowAll($('brands'), {
			viewableItems:  5,
			rowSelector:    'li',
			toggleSel:      '.toggle',
			heightSelector: '.overflow ul'
		});
	}
	
	if ($('show_more')) {
		new ShowMore($('show_more'), "Read More", "Show Less");
	}
	
	if ($('tabs')) {
		var sel = (document.location.hash == "#topbrands") ? 1 : 0;
		new Tabs($('tabs'), $$('.togglers li'), $$('.tab_content'), sel);
	}
	
	if($('tabs_help')) {
		new HelpMeChoose('tabs_help');
	}
	
	$$('.categories .product').each(function(el) {
		new HoverDelay(el, { delay: 0 });
		
		var viewLink = el.down(".view");
		if (viewLink) {
		    new CategoryPopUp(viewLink, $('overlay_category'));
		}
	});
	
	if ($('faqs')) {
		$$('#faqs ul li').each(function(el) {
			new SimpleToggler(el.down('a'), el.down('div'));
		});
	}
});
