window.addEvent('domready', function(){
//	if (window.ie6)	ie6_nav_behavior($('nav'));
	top_nav();
	left_nav();
	bottom_nav();

	init_forms();	
});

/**
 *	Add ".last" class to top navigation
 *
 */
function top_nav() {
	$$('#top ul li').getLast().addClass('last');
}

/**
 * Initialize main navigation(left), mootools Accordion
 *
 */
function left_nav()
{
	// Find active element
	var togglers = $$('#left ul li.depth_1');
	var elements = $$('#left ul li.depth_1 ul');
		
	var left_accordion = new Accordion(togglers, elements, {
		opacity: false,
		duration: 300,
		transition: Fx.Transitions.Quad.easeIn
	}, $E('#left'));
	
	togglers.each(function(element,number)
	{
		element.removeEvents('click');		
	});	
	
	var active_li = $E('li.active', 'left');
	if (active_li) {
		if (active_li.hasClass('depth_1')) {
			var active_ul = $E('ul', active_li);
		} else {
			var active_ul = active_li.getParent();
		}
		if (active_ul) {
			left_accordion.display(active_ul);
		}
	}
}

/**
 * Initialize bottom left navigation, mootools Accordion
 *
 */
function bottom_nav()
{
	try {
		var bottom_accordion = new Accordion($$('#bottom .left ul li'), $$('#bottom .right div'),
		{
			opacity: false,
			duration: 0
		}, $E('#bottom'));		
	
		// Get active item
		var active_item = $E('.left li.active', 'bottom');
		var the_index = $$('#bottom .left ul li').indexOf(active_item);
		if (the_index)
		{
			bottom_accordion.display(the_index);
		}
		
		// Attach event handlers
		bottom_accordion.setOptions({
			onActive: function(toggler, element)
			{
				toggler.addClass('active');
			},
			onBackground: function(toggler, element)
			{
				toggler.removeClass('active');
			}	
		});
	}catch(e){}
		

	
	// Prevent browser from following links
	$$('#bottom .left ul li a').addEvent('click', function(evt) {
		evt = new Event(evt);
		evt.preventDefault();
	});
}

/**
 * Forms
 *
 */
function input_empty(evt) {
	evt = new Event(evt);
	evt.target.value = '';
}

function init_forms() 
{
	if($E('input[type=text]', 'newsletter'))
	{
		$E('input[type=text]', 'newsletter').addEvent('focus', input_empty);
		$E('input[type=text]', 'left').addEvent('focus', input_empty);
	}
} 
