$(document).ready(function() {
	/**
	* 'Jump Menu'
	* Redirects based on the select value.
	*
	* Note: Andy, I would do the following instead of this:
	*       Firstly, add a submit button, this can them be hidden with JavaScript
	*       Write a little script which takes the submitted data, and redirects the page based on the value.
	*       If there is a submit button on this form, the script assumes you've done this.
	*       If there is a submit button, it will submit the form when select is changed, thus redirecting.
	*       This means the script works without JavaScript too.
	*       If you don't do this, then it will still work, but only in JavaScript
	*
	*/
	var $jump_form = $('#nav-tools');
	var $jump_form_submit = $(':submit, :button', $jump_form).hide();
	$('select', $jump_form).change(function(){
		var val = $(this).val();
		if(val !== '' && val !== '0') {
			if($jump_form_submit.length>0) {
				$(this).parents('form:first').submit();
			}
			else {
				window.location.href = val;
			}
		}
	});
	
	/**
	* Accordion Menu
	* @uses jquery.ui()
	* @uses accordion()
	*
	* Note: This works for the menu items which have an href of # only.
	*       If you add correct anchors to these (you should), then you'll need to change this slightly
	*       Give the anchors you want accordion a class and change a[href^='] to a.your-class
	*
	*/
	if($.ui && $.ui.accordion) {
		$('#nav-sub').accordion({
			navigation : true,
			alwaysOpen : false,
			autoHeight : false,
			selectedClass : 'selected',
			active : 0,
			header : 'a.trigger'
		}).bind('accordionchange', function(event, ui) {
			$(ui.newHeader).blur();
		}).end().find('li ol, li ul').accordion({
			navigation : true,
			alwaysOpen : false,
			autoHeight : false,
			selectedClass : 'selected',
			active : false,
			header : 'a.sub-trigger'
		}).bind('accordionchange', function(event, ui) {
			$(ui.newHeader).blur();
		});
		/*children('li:has(a)').find('a').click(function(){
			$a = $(this);
			$a.blur();
		})*/
	}
	
	/**
	* Tabs
	* @uses jquery.ui()
	* @uses tabs()
	* @url http://docs.jquery.com/UI/Tabs
	*
	* Note: This fades in and out as well as closing completely then reopening the boxes
	*       I have added a selected class to the first item.
	*       You can change this, along with the class name.
	*
	*/
	if($.ui && $.ui.tabs) {
		var $tabs = $('div.tabs');
		var panel_height = $tabs.height();
		$('ul', $tabs).tabs({
			'select' : function(e, ui) {
				new_panel_height = $(ui.panel).height() + 73;
				if(new_panel_height>panel_height || new_panel_height<panel_height) {
					$tabs.animate({'height' : new_panel_height + 'px'});
					panel_height = new_panel_height;
				}
			},
			'fx' : {opacity: 'toggle', duration: 'slow'},
			'cache' : true,
			'selectedClass' : 'selected'
		}).bind('tabsselect', function(event, ui) {
			$(ui.tab).blur();
		});
	}
	
	/**
	* Slideshow
	* @uses cycle()
	*/
	if($.fn.cycle) {
		$('.slideshow-images').cycle();
	}
	
	/**
	* Services
	* Add Person & Courses
	* @see extraBooking.js for Options
	* @see serviceHeadings.js for Options
	*/
	$book = $('div#services.group.services');
	$courses = $('div#about-you.group');
	if($.fn.serviceHeadings) {
		$book.serviceHeadings();
	}
	if($.fn.extraBooking) {
		$book.extraBooking();
	}
	if($.fn.newService) {
		$courses.newService({
			copy: $('#new-service')
		}).next().next().extraBooking();
	}
	
	/**
	* Fancybox
	*/
	if($.fn.fancybox) {
		$('ul.group a').fancybox({
			'zoomSpeedIn' : 0,
			'zoomSpeedOut' : 0,
			'overlayShow' : true
		});
	}
	
});