/*	Initialization function  */

	window.addEvent('domready',function(){
			
		/*	Set panel icons */
		
			$$('div#panels h4').each(function(M, N){
			
				var config = M.get('text').split('|');
				M.set('text', config[0].trim());
				M.setStyle('background-image', 'url(/wp-content/uploads/' + config[1].trim() + ')');
			
			});
			
		/*	Replicate footer menu to main menu */
		
			$('mm').set('html', $('ft').get('html'));
			
		/*	Remove sub menu from welcome */
		
			new Element('li', {'html': '<a href="/" class="mainItem">Welcome</a>'}).injectBefore($$('#mm li')[0]);
			
		/*	Dropdown menu */
		
			initializeMainMenu();
			
		/*	A */
		
			if(Browser.Engine.trident && Browser.Engine.version <= 5){
			
				$$('ul#ft li.first')[0].setStyle('margin-left', 40);
				$$('ul#ft li ul').each(function(M, N){
				
					var maxWidth = 0;
					M.getElements('a').each(function(X, Y){
					
						var D = X.getCoordinates();
						if(D.width.toInt() > maxWidth) maxWidth = D.width.toInt();
					
					});
					M.setStyle('width', maxWidth);
				
				});
				
			}
			
		/*	Homepage slideshow */
		
			if($('homepageSlideshow')) new Slideshow('homepageSlideshow', slideshowData, {'height': 340, 'width': 610});

	});
	
/*	Main menu */

	var lastAnchor = null;
	function initializeMainMenu(){
	
		$$('ul#mm a.mainItem').each(function(M, N){
			
			M.addEvent('mouseover', function(){
			
				if($('subMenu')) $('subMenu').destroy();
				if(lastAnchor) lastAnchor.setStyle('opacity', 1);
				
				lastAnchor = M;
				lastAnchor.setStyle('opacity', 0.01);
				var D = M.getCoordinates();
				
				var B = new Element('div', {
				
					'id'		: 'subMenu',
					'styles'	: {
					
						'position'	: 'absolute',
						'top'		: D.top,
						'left'		: D.left,
						'z-index'	: 9
						
					},
					'events'	: {
					
						'mouseleave': function(e){
						
							this.destroy();
							if(lastAnchor) lastAnchor.setStyle('opacity', 1);
						
						}
					
					}
				
				}).inject(document.body);
				
				new Element('a', {
				
					'text'		: M.get('text'),
					'href'		: M.getProperty('href'),
					'class'		: 'mainMenuReplacement',
					'styles'	: {
					
						'width'	: D.width - 5
	
					}
					
				}).inject(B);
				
				var C = M.getParent().getElements('li');
				var maxWidth = 0;
				if(C.length > 0){
				
					var A = new Element('ul', {
					
						'class': 'submenu'
						
					}).inject(B);
				
					C.each(function(X, Y){
					
						var D = new Element('a', {'text': X.get('text'), 'href': X.getElements('a')[0].getProperty('href')}).inject(new Element('li').inject(A));
						var E = D.getCoordinates();
						if(E.width.toInt() > maxWidth) maxWidth = E.width.toInt();
					
					})
					
					if(Browser.Engine.trident && Browser.Engine.version <= 5) B.setStyle('width', maxWidth + 10);
					
				};
			
			});		

		});
	
	}
