
window.addEvent('domready', function() {
    
	/* ---- Drop down menu ---- */
	
	var menuItem = $('menu2');
	
	// Mouse over
	menuItem.addEvent('mouseover', function() {	
		if (!menuItem.hasClass("selected")) {
			menuItem.getChildren('ul')[0].style.display="block";
		}
	});
	
	// Mouse out
	menuItem.addEvent('mouseout', function() {	
		menuItem.getChildren('ul')[0].style.display="none";
	});
	
	
	/* ---- Search box - remove default text on click ---- */
	
	// Get the search box form, input field & submit button
	var searchForm = $('search');
	var searchBox = searchForm.getChildren('input');
	var searchButton;
	searchBox.each(function(item) {
			// Check if it's definitely the 'text' field, 
			// rather than assuming it'll be the first child!
			if (item.getAttribute('type') == "text") {
				searchBox = item;	
			} else if (item.getAttribute('type') == "image") {
				searchButton = item;	
			}
	});
	
	// Get original value text
	var firstValue = searchBox.getAttribute('value');
	
	// Get the "No search term entered" validation alert
	var validation = $('search-validation');
	validation.style.display = 'block';
	validation.fade('hide');
	
	// Replace and return the original value text on focus and blur
	searchBox.addEvent('focus', function() {
		if (searchBox.value == firstValue) {
			searchBox.value = '';
		}
	});
	searchBox.addEvent('blur', function() {
		if (searchBox.value.trim() == '') {
			searchBox.value = firstValue;
		}
	});
	
	// Don't let the form get submitted with either no entry or the original text
	searchButton.addEvent('click', function() {
		if (searchBox.value.trim() == '' || searchBox.value == firstValue) {
			validation.fade('0.9');
			return false;
		}
	});
	
	// Remove the search validation box when they click away from the submit button
	searchButton.addEvent('blur', function() {
		validation.fade('out');
	});
	
	/* ---- Q&A Topics Accordian ---- */
	
		// Set up JavaScript styles
	var contentBoxes = $$('#left-nav div.topic-qs-nav');
	
	contentBoxes.each(function(item) {
			item.style.display='none';	
			item.getChildren()[0].style.overflow='hidden';
	});

		// Set up accordian
	var togglers = $$('#left-nav a.toggler');
	var elements = $$('#left-nav div.topic-qs-nav').getChildren('div');
	
		// Hijack the links
	togglers.each(function(link) {
		link.setAttribute('href', '#');					   
	});
	
	var qaAccordian = new Accordion(togglers, elements, {
		show: listOffset,
		opacity: false,
		alwaysHide: true,
		
		// When content starts opening...
		onActive: function(toggler, element) {
			toggler.addClass('selected');
			toggler.getParent().addClass('selected');
			toggler.getChildren('img')[0].setAttribute('src', imageBase+'images/active-arrow.png');
			element.getParent().style.display='block';
			tweenAccordian(toggler, element, '250');	
		},
		
		// When content starts closing...
		onBackground: function(toggler, element) {
			tweenAccordian(toggler, element, '0');
		}
	});
	
	togglers[listOffset].addClass('selected');

});

function tweenAccordian(toggler, element, target) {
	var tween = new Fx.Tween(element.getParent(), {
			onComplete: function() {
				if (element.getParent().getStyle('height').toInt() == 0) { // Closing accordian
					toggler.style.border='0';
					toggler.removeClass('selected');
					toggler.getChildren('img')[0].setAttribute('src', imageBase+'images/nor-arrow.png');
					element.getParent().style.display='none';
				}
			}
		});
	
	tween.start('height', target);
}