var menu = Class.create();


menu.prototype = {

	active: '',
	
	timer: '',
	hrefOne: '',
	hrefTwo: '',
	menuThree: '',
	menuTwo: '',
	activeOne: '',
	activeTwo: '',
	
	initialize: function() {
		this.setEvents();
	},
	
	setEvents: function() {
		var self = this;
	
		this.hrefOne = $A($$('.href_one'));
		this.hrefTwo = $A($$('.href_two'));
		this.menuThree = $A($$('.menu_three'));
		this.menuTwo   = $A($$('.menu_two'));
		
		
		this.hrefOne.each(function(div) {
			
			div.onmouseover = function() {
				
				self.activeOneSc(this.id);
				self.showSubMenu1(this.id);
				window.clearTimeout(self.timer);
			}
			
			div.onmouseout = function() { 
				self.timer = window.setTimeout(function() {self.hideAll()}, 300);
			}
								
		});
		
		$A($$('div.bg')).each(function(div) {
			
			div.onmouseover = function() {
				window.clearTimeout(self.timer);
				self.hideThreeMenu();
				self.activeTwoSc();
			}
			div.onmouseout = function() { 
				self.timer = window.setTimeout(function() {self.hideAll()}, 300);
			}
			
		});
		
		this.hrefTwo.each(function(div) {
			
			div.onmouseover = function() {
				self.activeTwoSc(this.id);
				
				div.className  = 'href_two active';
				self.showSubMenu2(this.id);
				window.clearTimeout(self.timer);
				
			}
			
			div.onmouseout = function() { 
				self.timer = window.setTimeout(function() {self.hideAll()}, 300);
			}
			
		});
		
		this.menuThree.each(function(div) {
			
			div.onmouseover = function() {
				window.clearTimeout(self.timer);
			}
			
			div.onmouseout = function() { 
				self.timer = window.setTimeout(function() {self.hideAll()}, 300);
			}
			
		});
				
		$A($$('div.menu_second')).each(function(div) {
			
			div.onmouseover = function() {
				div.className  = 'active href_three';
				
			}
			
			div.onmouseout = function() { 
				div.className  = 'no_active href_three';

			}
		});
		
		
	},
	
	activeOneSc: function(id) {
		if (this.activeOne) {
			$(this.activeOne).className  = 'href_one';
		}
		this.activeOne = id;
		$(id).className  = 'href_one black';
	},
	
	activeTwoSc: function(id) {
		if (this.activeTwo) {
			$(this.activeTwo).className  = 'href_two no_active';
		}
		if (id) {
			this.activeTwo = id;
			$(id).className  = 'href_two active';
		}	
	},
	
	showSubMenu1: function(id) {
		this.hideThreeMenu();
		this.hideTwoMenu();
		$('menu'+parseInt(id)).show();
		
	},
	
	showSubMenu2: function(id) {
		
		this.hideThreeMenu();
		$('menu'+(id)).show();
		
	},
	hideTwoMenu: function() {
			
		this.menuTwo.each(function(div) {
			div.style.display = 'none';
		});
		this.menuThree.each(function(div) {
			div.style.display = 'none';
		});
		
	},
	
	hideAll: function() {
		this.hideTwoMenu();
		if (this.activeTwo) {
			$(this.activeTwo).className  = 'href_two no_active';
		}
		if (this.activeOne) {
			$(this.activeOne).className  = 'href_one';
		}
	},
	
	hideThreeMenu: function() {
		
		this.menuThree.each(function(div) {
			div.style.display = 'none';
		});
		
	}
}


Event.observe(window, 'load', function() {
	new menu;
});
