window.addEvent('domready', function(e) {
	var customTips = $$('.tooltip');
	var toolTips = new Tips(customTips, {
		showDelay: 300,    //default is 100
		hideDelay: 100,   //default is 100
		className: 'anything', //default is null
		offsets: {
			'x': 16,       //default is 16
			'y': 16        //default is 16
		},
		fixed: false,      //default is false
		onShow: function(toolTipElement){
		    toolTipElement.fade(.9);
			$('show').highlight('#FFF504');
		},
		onHide: function(toolTipElement){
    		toolTipElement.fade(0);
			$('hide').highlight('#FFF504');
		}
	});
	var menuhorlists = $$('ul#menu li li ul');
	var menuhorfx = new Fx.Elements(menuhorlists, {
		'link': 'cancel',
		'duration': 500,
		transition: Fx.Transitions.Sine.easeOut,
		onComplete: function() {
			var keepopen = null;
			menuhorlists.each(function(el) {
				if (el.getStyle('height').toInt() > 0) {
					keepopen = el;
					el.setStyle('overflow', 'visible');
				}
			});
			menuhorlists.setStyle('width', 0);
			if (keepopen) {
				keepopen.setStyle('width', 'auto');
			}
		}
	});
	openmenuhor = function(e, idx) {
		var obj = {};
		menuhorlists.each(function(el, i) {
			if (i == idx) {
				obj[i] = {
					'height': el.getScrollSize().y
				};
				el.setStyle('width', 'auto');
			} else {
				obj[i] = {
					'height': 0
				};
				el.setStyle('overflow', 'hidden');
			}
		});
		menuhorfx.start(obj);
	}
	var ulcounter = 0;
	$$('ul#menu > li > ul > li').each(function(li) {
		var childul = li.getElement('ul');
		if (childul) {
			childul.setStyles({
				'overflow': 'hidden',
				'position': 'absolute',
				'height': 0
			});
			li.addEvent('mouseenter', openmenuhor.bindWithEvent(childul, ulcounter));
			ulcounter++;
		} else {
			li.addEvent('mouseenter', openmenuhor.bindWithEvent(childul, -1));
		}
	});

	// Level 1
	var menulists = $$('ul#menu > li > ul');
	var menufx = new Fx.Elements(menulists, {
		'link': 'cancel',
		'duration': 500,
		transition: Fx.Transitions.Sine.easeOut,
		onStart: openmenuhor.bindWithEvent(menufx, -1),
		onComplete: function() {
			menulists.each(function(el) {
				if (el.getStyle('height').toInt() > 0) {
					el.setStyle('overflow', 'visible');
				}
			});
		}
	});
	openmenu = function(e, idx) {
		var obj = {};
		menulists.each(function(el, i) {
			if (i == idx) {
				obj[i] = {
					'height': el.getScrollSize().y
				};
			} else {
				obj[i] = {
					'height': 0
				};
				el.setStyle('overflow', 'hidden');
			}
		});
		menufx.start(obj);
	}
	var ulcounter = 0;
	$('menu').getChildren('li').each(function(li) {
		var childul = li.getElement('ul');
		if (childul) {
			childul.setStyles({
				'overflow': 'hidden',
				'position': 'absolute',
				'height': '0',
				'width': '200px'
			});
			li.addEvent('mouseenter', openmenu.bindWithEvent(childul, ulcounter));
			ulcounter++;
		} else {
			li.addEvent('mouseenter', openmenu.bindWithEvent(childul, -1));
		}
	});
	$('menu').addEvent('mouseleave', openmenu.bindWithEvent($('menu'), -1));
	
	var accordion = new Accordion('h5.atStart', 'div.atStart', {
    	opacity: false,
    	onActive: function(toggler, element){
    		toggler.setStyle('color', '#eaeaea');
    	},
    	
    	onBackground: function(toggler, element){
    		toggler.setStyle('color', '#666666');
    	}
    }, $('accordion'));
});

	