//var Class = {
//  create: function() {return function() {this.initialize.apply(this, arguments);}}
//}

//Function.prototype.bind = function(object) {
//  var __method = this;
//  return function() {__method.apply(object, arguments);}
//}

//function $(objectName) {return document.getElementById(objectName);}

// --------------------------------
// SPECIAL EFFECTS

var Fx = new Class.create();
Fx.prototype = {
	initialize: function(o) {	
		this.o = o;	
		this.reset(); 
	},
	
	reset: function() {
		this.opa = 0;
		this.setOpacity(this.opa);
		if (this.timer) clearInterval(this.timer);
	},
	
	fade: function(){
		if (this.timer) clearInterval(this.timer);
		if (this.opa >= 1) {return;}
		this.opa += 0.04;
		this.setOpacity(this.opa);
		this.timer = setInterval(this.fade.bind(this), 8);
	},
	
	setOpacity: function(opa) {
		this.o.style.opacity = this.o.style.MozOpacity = this.o.style.KhtmlOpacity = opa; 
		this.o.style.filter = 'alpha(opacity=' + opa*100 + ')';
	}
}

var Menu = new Class.create();
Menu.prototype = {
	initialize: function(hook, oName) {
		this.a = $(hook); this.o = $(oName); this.a.appendChild(this.o); // Rearrange elements
		el = this.o.getElementsByTagName('img'); this.el = new Array(el.length);
		for (i=0; i<el.length; i++) {this.el[i] = new Fx(el[i]);}
		this.t = new Array(el.length);
		
		this.a.onmouseover = function(){
			if (this.a.className == '') 
				for(i=0; i<this.el.length; i++) { this.t[i] = setTimeout(this.el[i].fade.bind(this.el[i]), i*64); }
			this.a.className = 'hover';
		}.bind(this);

		this.a.onmouseout =  function(){
			this.a.className = '';
			for(i=0; i<this.el.length; i++) { if (this.t[i]) clearTimeout(this.t[i]); }
			setTimeout(function(){
				if (this.a.className == '') for(i=0; i<this.el.length; i++) { this.el[i].reset(); }
			}.bind(this), 2);
		}.bind(this);
	}
}

// --------------------------------
// MAIN FUNCTION

window.onload = function() {
	 var navBar = new Menu('item1', 'box1');
	 var navBar = new Menu('item2', 'box2');
	 var navBar = new Menu('item3', 'box3');
	 var navBar = new Menu('item4', 'box4');
	 var navBar = new Menu('item5', 'box5');


}
