/* Theme Pack 3.1.1+ DO NOT modify */

CS.v3.CloseNavsX = Class.create(CS.v3.Base.prototype, {
	initialize: function(target) {
		this.hasNavX = CS.v3.up(target,'DIV.csNav-x');
		
		if (this.hasNavX) {
		
				if (target.hasClassName('csNavToggle')) {
				
					this.li = CS.v3.up(target,'LI.csNavToggle-0');
					this.li.addClassName('csNavFocus');
					this.navs = $$('.csNav-x li.csNavShow:not(.csNavFocus)');
				
					this._close();
				}
		
		} else {
		
			this.navs = $$('.csNav-x li.csNavShow:not(.csNavFocus)');
			this._close();
		}
	},
	_close: function() {
	
		this.navs.each(function(nav) {
		
			nav.removeClassName('csNavShow');
			
			var toggleTarget = CS.v3.down(nav,'.csNavContent');
			toggleTarget.style.display = 'none';
			toggleTarget.style.height = '';
			
		}.bind(this));
		
		if (this.li) {this.li.removeClassName('csNavFocus')}
	}
});


CS.v3.Tabs = Class.create(CS.v3.Base.prototype, {
	initialize: function(el) { 
		
		this.el = el;
		this.wrap = CS.v3.getParentElementWithClass(this.el,'.csTabs-x') || CS.v3.getParentElementWithClass(this.el,'.csTabs-y');
		var attr = new CS.v3.ComponentAttributes(this.wrap);
		
		this.item = this.el.up(1);
		
		var s = new CS.v3.getSelected(this.item,'li');
		this.selectedItem = s.selectedIndex;
		
		//modes
		if (this.wrap.hasClassName('csAjax')) {
		
			this.mode = 'ajax'
		} else {this.mode = 'dhtml'}
		
		
		if (this.mode == 'csAjax') {
		
			this.navStatus(s.collection,this.item);
			this.ajax();
		}
		
		if (this.mode == 'dhtml') {
		
			this.contentModulesX = $$('.' + this.targetClass);

			attr.toggleContent.each(function(module) {
			
				module.removeClassName('csShow');
			}.bind(this));
			
			this.removedItem = this.navStatus(s.collection,this.item);
			
			this.show(attr)
		}
	},
	show: function(attr) {
		
		// no targetClass attribute
		if (attr.toggleContent.length == 0) {
			
			this.wrap.next(this.removedItem).removeClassName('csShow');
			this.module = this.wrap.next(this.selectedItem,'.csContentModule');
		}
		
		else { //targetClass attribute
		
			this.module = attr.toggleContent[this.selectedItem];
		}
		
		this.module.addClassName('csShow');
	},
	ajax: function() {
		
		this.targets.each(function(value,index) {
		
			var updateTarget = $(this.targets[index]);
			new CS.v3.AjaxNav(this.el,updateTarget,{bind:true});
		}.bind(this));
	}
});


CS.v3.Components.MenuMouseOut = function(section,options) {new CS.v3.MenuMouseOut(section,options)};
CS.v3.MenuMouseOut = Class.create(CS.v3.Base.prototype, {
	initialize: function(section) {
		
		this.observeNodes = $$('.csOver');
		this._bindOver();
	},
	_bindOver: function() {
	
		this.observeNodes.each(function(node) {

			Event.observe(node, 'mouseout', function(event) {
			
				var m = new CS.v3.MenuNewMouseOut(event);
				
				if (CS.v3.MenuState == 'active') {return;}
				CS.v3.Menu.prototype._closeXMenus(event,m);
			
			}.bind(this));
			
		}.bind(this));
	}
});

CS.v3.MenuNewMouseOut = Class.create(CS.v3.Base.prototype, {
	initialize: function(event) {
		
		this.target = $(Event.element(event));
		this.item = CS.v3.getParentElement(this.target,'LI');
	}
});


CS.v3.Menu = Class.create(CS.v3.Base.prototype, {
	initialize: function(event,eventType) {
	
		this.target = $(Event.element(event));
		
		if (this.target.tagName != 'A') {return}
		
		this.wrap = CS.v3.getParentElementWithClass(this.target,'.csClick') || CS.v3.getParentElementWithClass(this.target,'.csOver');
		this.item = CS.v3.getParentElement(this.target,'LI');
		
		this.shown = this.wrap.select('li.csNavShow');
		this.tier = '.csNavToggle-0';
		if (!this.item.match('.csNavToggle-0')) {this.tier = '.csNavToggle-1'}
		
		if (this.target.match('.csNavToggle')) {
			
			this.toggleTarget = CS.v3.down(this.item,'.csNavContent');
		}
			
		if (this.wrap.match('.csNav-x')) {

			if (CS.v3.Base.prototype.coverIE) {CS.v3.Base.prototype.coverIE(this.item);}
		}
		
		this._handle();
	},
	_handle: function(m) {
	
		if (CS.v3.MenuState == 'active') {return;}
		
		//toggle
		if (this.target.match('.csNavToggle')) {
		
			if (!this.wrap.match('.csShowHide')) {CS.v3.MenuState = 'active';}
			
			// Vertical Menu
			if (this.wrap.match('.csNav-y')) {
				
				// blind
				if (this.wrap.match('.csBlind')) {
				
					new CS.v3.ToggleDisplayEffect(this.target,this.item,this.toggleTarget,this.wrap,'csNavShow','hidden');
					
				}
				
				if (this.wrap.match('.csAccordian')) {
					
					this._hideShown(this.target,this.shown,this.wrap);
					
					if (!this.item.match('.csNavShow')) {
						
						new CS.v3.ToggleDisplayEffect(this.target,this.item,this.toggleTarget,this.wrap,'csNavShow','hidden');
					}
				}
			}
			
			// Horizontal Menu
			if (this.wrap.match('.csNav-x')) {
				
				if (this.wrap.match('.csAccordian')) {
						
					this._hideShown(this.target,this.shown,this.wrap);
					
					if (!this.item.match('.csNavShow')) {
						
						new CS.v3.ToggleDisplayEffect(this.target,this.item,this.toggleTarget,this.wrap,'csNavShow','hidden');
					}
				}
				
				if (this.wrap.match('.csShowHide')) {
					
					this.item.addClassName('csNavShow');
					this.toggleTarget.style.display = 'block';
					this.toggleTarget.style.height = 'auto';
				}
			}
		}
		
		//ajax
		if (this.target.match('.csAjax')) {this._ajaxRequest(this.target);}
	},
	_ajaxRequest: function(target) {
		
		var updateTarget = this.getCustomAttribute(target,'csTargetID-').toString();
		var updateTarget = $(updateTarget);
		new CS.v3.AjaxNav(target,updateTarget,{bind:true});
	},
	_hideShown: function(target,shown,wrap) {
		
		if (wrap.match('.csAccordian')) {
			
			shown.each(function(value,index) {
				var obj = shown[index];
				var toggleTarget = CS.v3.down(obj,'.csNavContent');
				new CS.v3.ToggleDisplayEffect(target,obj,toggleTarget,wrap,'csNavShow','hidden');
			});
		}
	},
	_closeXMenus: function(event,m) {
	
		var target = $(Event.element(event));
				
		// Find element that mouseout goes to.
		var toEl;
		if (Prototype.Browser.IE) {
			toEl = event.toElement;
		} else {
			toEl = $(event.relatedTarget);
		}
		if (toEl) {
		
			var show = CS.v3.up(toEl,'LI.csNavShow');
			
			if (!show) {
				
				var item = CS.v3.up(target,'LI.csNavToggle-0');
				if (item) {
					
					item.removeClassName('csNavShow');
					
					var toggleTarget = CS.v3.down(item,'.csNavContent');
					
					if (toggleTarget) {
						toggleTarget.style.display = 'none';
						toggleTarget.style.height = '';
					}
				}
			}
		}
	}
});

