/**
* Drop Navigation
* @author Beau Bishop beau [at] webteks [dot] com
* @date 2007-09-15
*
* Extends Element.js.
* Needs work, but eh.. works for now.
*/
Element.extend({
	initBackgroundPosition: function() {
		switch (this.getParent().getFirst().className) {
		  case 'nav1': this.getParent().getFirst().setStyle('background-position','0px 0px'); break;
		  case 'nav2': this.getParent().getFirst().setStyle('background-position','-65px 0px'); break;
		  case 'nav3': this.getParent().getFirst().setStyle('background-position','-165px 0px'); break;
		}
		return this.hide();
	},
	setBackgroundPosition: function(property, value){
		if (property == 'background-position-h') {
			property = 'background-position';
			value = value + ' ' + this.style.backgroundPosition.split(' ')[1];
		}
		if (property == 'background-position-v') {
			property = 'background-position';
			value = this.style.backgroundPosition.split(' ')[0] + ' ' + value;
		}
		this.style[property.camelCase()] = (value.push) ? 'rgb('+value.join(',')+')' : value;
		return this;
	},
	hide: function() {
		$(this.getParent().getFirst()).setBackgroundPosition('background-position-v','0px');	
		return this.setStyle('display', 'none');
	},
	show: function() {
		$(this.getParent().getFirst()).setBackgroundPosition('background-position-v','-22px');	
		return this.setStyle('display', '');
	}
});
var DropNavigation = new Class({
	initialize: function (navigation) {
		$A($(navigation).childNodes).each(function(navItem) {
			if (navItem.nodeName.toLowerCase() == 'li') {
				$A($(navItem).childNodes).each(function(subNav) {
					if(subNav.nodeName.toLowerCase() == 'ul') {
						$(subNav).initBackgroundPosition();
						navItem.addEvent('mouseover',function() {
							subNav.show();
							return false;
						});
						navItem.addEvent('mouseout',function() {
							subNav.hide();
						});
						new DropNavigation(subNav);
					}
				});
			}
		});
		return this;
	}
});