

var menu = Class.create();
menu.prototype = {
	
	list:null,
	
	initialize: function (el) {
		this.list = el;
		Element.extend(this.list);
		for(var j=0;j<this.list.childNodes.length;j++) {
			if(this.list.childNodes[j].tagName && this.list.childNodes[j].tagName.toLowerCase() == 'li') {
				Element.extend(this.list.childNodes[j]);
				if(this.list.childNodes[j].down('img')) var btn = new menuButton(this.list.childNodes[j]);
			}
		}
	}
	
}

var menuButton = Class.create();
menuButton.prototype = {
	
	element:null,
	img:null,
	defaultSrc:null,
	rollSrc:null,
	overListener:null,
	outListener:null,
	
	initialize: function (el) {
		
		this.element = el;
		Element.extend(this.element);
		if(this.element.down('img')) {
			if(!this.element.hasClassName("selected")) {
				this.img = this.element.down('img');
				this.defaultSrc = this.img.src;
				this.rollSrc = (this.img.src.indexOf("over")>-1) ? this.img.src.replace("_over","") : this.img.src.replace(".gif","_over.gif");
				var preload = new Image();
				preload.src = this.rollSrc;
				this.overListener = this.over.bind(this);
				this.outListener = this.out.bind(this);
				this.out();
			} else {
				this.img = this.element.down('img');
				this.rollSrc = (this.img.src.indexOf("over")>-1) ? this.img.src.replace("_over","") : this.img.src.replace(".gif","_over.gif");
				var preload = new Image();
				preload.src = this.rollSrc;
				this.img.src = this.rollSrc;
			}
		}
	},
	
	over: function (e) { 
		if(this.element.down('ul')) this.element.down('ul').style.display = "block";
		Event.stopObserving(this.element, "mouseover", this.overListener);
		this.img.src = this.rollSrc;
		Event.observe(this.element, "mouseout", this.outListener);
	},
	
	out: function (e) {
		if(this.element.down('ul'))  this.element.down('ul').style.display = "none";
		Event.stopObserving(this.element, "mouseout", this.outListener);
		this.img.src = this.defaultSrc;
		Event.observe(this.element, "mouseover", this.overListener);
	}
	
}


function initNavigation() {
	var myMenu = new menu($('navigation').down('ul'));
}
Event.observe(window, 'load', initNavigation, false);