var debugText = "";

window.addEvent('domready', function(){
	// Top menu
	initTopMenu();
	
	if($('subNav')){
		initSideMenu();
	}
	
	// Debug use only
	$('jsDebug').set('html', debugText);
	
	// History btn
	if($$('a.historyBackLink').length > 0){
		$$('a.historyBackLink').each(function(historyBtn){
			historyBtn.addEvent('click', function(e){
				e.stop();
				history.back();
			});
		});
	}
	
	// Print btn
	if($$('a.postPrint').length > 0){
		$$('a.postPrint').each(function(printBtn){
			printBtn.addEvent('click', function(e){
				e.stop();
				setActiveStyleSheet('print-content');
				window.print();
			});
		});
	}
});


function initTopMenu(){
	$$('#mainNav li.lvl1MenuItem').each(function(lvl1Item){
		if(lvl1Item.getElement('a').get('text') == topMostPage){
			lvl1Item.addClass('current');
		}
		
		lvl1Item.addEvents({
			'mouseenter' : function(){
				lvl1Item.addClass('hover');
				lvl1Item.getChildren('ul.lvl2Menu').addClass('hover');
			},
			'mouseleave' : function(){
				lvl1Item.removeClass('hover');
				lvl1Item.getChildren('ul.lvl2Menu').removeClass('hover');
			}
		});
	});
	
	$$('#mainNav ul.lvl2Menu li').each(function(lvl2Item){
		lvl2Item.addEvents({
			'mouseenter' : function(){
				lvl2Item.addClass('hover');
			},
			'mouseleave' : function(){
				lvl2Item.removeClass('hover');
			}
		});
	});
}


function initSideMenu(){
	$$('#subNav li').each(function(lvl2Item){
		lvl2Item.addEvents({
			'mouseenter' : function(){
				lvl2Item.addClass('hover');
			},
			'mouseleave' : function(){
				lvl2Item.removeClass('hover');
			}
		});
	});
}