jQuery(function($){
		//IE6...
		$.ifixpng('data/graphics/template.blank.gif');
		$('#logo img, #pageBorderLeft, #pageBorderRight, #pageBorderBottom, #topMenu a.hasSubMenu, #articleLead .content').ifixpng();
		//General...
		$('a.targetBlank').attr({target:'_blank'});
		$('img.closeThis').click(function(){ $(this).closest('div.closeMe').slideUp(function(){$(this).remove();}); });
		//Superfish...
		$('#topNav ul.sf-menu')
			.find('ul').each(function(){
					var el = $(this).css({width:'auto', whiteSpace:'nowrap'}), w = el.width();
					el.width(w+2);//...include a small safety margin!
				}).end()
			.superfish({delay:200, speed:0, dropShadows:false,autoArrows:false});
		//Site Search...
		$('#siteSearcher_form').bind('submit', function(){
				var f = $('#searchFor');
				if(f.length){
					if(f.val()){ $(this).ajaxSubmit({url:'index.php'
							, success:function(response, status){
									if(response){
										var sr = $('#searchResults');
										if(sr.length){
											sr.replaceWith(response);
											$('#searchResults').show();
										}else{
											$('#content').after(response).slideUp();
											$('#searchResults').slideDown();
										}
									}
								}
							}); }
					else{ f.get(0).focus(); }
				}
				return false;
			});
		$('#searchResultsClear').live('click', function(){
				$('#searchFor').val('');
				$('#searchResults').slideUp(function(){ $(this).remove(); });
				$('#content').slideDown();
				return false;
			});
		//Subscription...
		$('#subscriptionBox').submit(function(){
				var n = $('#subscribeName'), e = $('#subscribeEmail'), u = $('#subscribeUnsubscribe:checked'), m = '';
				if(!e.val()){
					e.addClass('reqdField').get(0).focus();
					m = u.length ? 'To unsubscribe, please provide your registered Email address' : 'To register for our newsletter, please provide both Email and Name';
				}else{
					e.removeClass('reqdField');
					if(!n.val() && !u.length){
						n.addClass('reqdField').get(0).focus();
						m = 'To register for our newsletter, please provide both Email and Name';
					}else{
						n.removeClass('reqdField');
					}
				}
				if(m){
					$('#subscribeError .errorMsg').text(m).parent().slideDown();
				}else{
					$('#subscribeError').hide();
				}
				return !m;
			}).find(':text').val('').end().find(':checkbox').each(function(){ this.checked = false; });
		$('#subscribeError .errorMsg').click(function(){ $(this).parent().slideUp(); }).hover(function(ev){
				$(this)[ev.type == 'mouseenter' ? 'addClass' : 'removeClass']('errorMsgHover');
			});
		//Contact Us...
		$('#contactUs').bind('submit', function(){
				var sub = $(':submit', this).enable(false).addClass('formSubmitDisabled'); //enable() is part of the form plugin
				if($('.requiredField').removeClass('missingField').find(':input')
						.filter(function(){ return !$(this).val(); }).closest('.requiredField').addClass('missingField').length){
					$('#contactUsIncomplete:hidden').slideDown('fast');
					sub.removeClass('formSubmitDisabled').enable();
				}else{
					$('div.contactUsFeedback:visible').hide();
					$(this).ajaxSubmit({
							success:function(response, status){
									if(response){
										$('#contactUsProblem:hidden').slideDown();
										sub.removeClass('formSubmitDisabled').enable();
									}else{
										$('#contactUsSent:hidden').slideDown();
									}
								}
						});
				}
				return false;
			}).find(':submit').enable().removeClass('formSubmitDisabled');
		//Cycle...
		var cycleFadeDelay = 0; //stagger starts
		$('.cycleFade').each(function(){ $(this).cycle({timeout:6000, speed:1000, delay:(1000 * cycleFadeDelay++), pause:1}); });
		//News Slider
		var newsBox = {
				el: $('#newsBoxSlider')
			, speed: 1000 //milliseconds for the slide transition
			, interval: 6000 //milliseconds before next transition (after completion of slide)
			, step: 0 //max height of the items, and therefore the amount that top needs to change by
			, ct: 0 //number of items
			, dir: 1 //=down the list, ie scrolling up
			, indx: 0 //into item array, indicating item currently in view
			, hold: false //set by onHover - true on mouseenter, false on mouseleave
			, pause: false //set by play/pause buttons - true on pause clicked
			, timer: null //timer id
			, next: function(next){ //clears timer and sets up new timer if required...
					if(newsBox.timer !== null){
						window.clearTimeout(newsBox.timer);
						newsBox.timer = null;
					}
					if(next){
						newsBox.timer = window.setTimeout(newsBox.onTimeout, newsBox.interval + newsBox.speed);
					}
				}
			, slide: function(next){ //animate to next item...
					newsBox.next(next);
					newsBox.indx += newsBox.dir;
					if(newsBox.indx >= newsBox.ct){ newsBox.indx -= 2; newsBox.dir *= -1; }
					else if(newsBox.indx < 0){ newsBox.indx = 1; newsBox.dir *= -1; }
					newsBox.el.stop().animate({top: newsBox.indx * newsBox.step * -1}, newsBox.speed);
				}
			, onClick: function(){ //click handler for control buttons...
					this.blur();
					switch(this.id){
						case 'newsBoxControlNext':
							if(newsBox.indx < newsBox.ct - 1){
								newsBox.dir = 1;
								newsBox.slide(!newsBox.pause);
							}
							break;
						case 'newsBoxControlPause':
							newsBox.pause = true;
							$('#newsBoxControl').addClass('newsPaused');
							break;
						case 'newsBoxControlPlay':
							newsBox.pause = false;
							$('#newsBoxControl').removeClass('newsPaused');
							if(newsBox.timer == null){ newsBox.slide(true); }
							break;
						case 'newsBoxControlPrev':
							if(newsBox.indx > 0){
								newsBox.dir = -1;
								newsBox.slide(!newsBox.pause);
							}
							break;
						default:
					}
					return false;
				}
			, onHover: function(ev){ //hover handler for mouse over/off the slider...
					newsBox.hold = ev.type == 'mouseenter';
					$('#newsBoxControlPause').toggleClass('newsPaused');
					if(!newsBox.hold && !newsBox.pause && newsBox.timer === null){
						newsBox.slide(true);
					}
					return false;
				}
			, onShow: function(){ //set up controls, and set up all handlers...
					var ctrl = $('#newsBoxControl'), offset = (ctrl.prev().get(0)||{}).offsetTop||0;
					if(newsBox.ct > 1){ //if only one item, don't need any handlers!
						newsBox.next(true);
						if(ctrl.length){
							offset = offset - ctrl.find('a').click(newsBox.onClick).first().height();
							ctrl.hide().css({top:offset, visibility:'visible'}).fadeIn();
							$(this).hover(newsBox.onHover); //'this' is #newsBoxWindow
						}
					}else{
						ctrl.hide();
					}
				}
			, onTimeout: function(){ //timer handler...
					newsBox.timer = null;
					if(!newsBox.hold && !newsBox.pause){ newsBox.slide(true); }
				}
			};
		if(newsBox.el.length){
			newsBox.el.find('div.newsSnippets').each(function(i){
					var h1 = $(this).find('.articleContent h1:first')
						, t = h1.length ? h1.html() : ''
						, h = $(this).height();
					if(t){
						h1.empty().append($(this).find('a.newsSnippets').show().html(t));
					}
					newsBox.ct++;
					if(h > newsBox.step){ newsBox.step = h; }
				}).height(newsBox.step);
			$('#newsBoxWindow').animate({height:newsBox.step}, 'slow', newsBox.onShow);
		}
		//Gallery...
		if($('#articleLeadGallery').length){
			var hoverGal = {
					full: $('#articleLeadGallery img')
				, thumbs: $('ul.galleryThumbnails img')
				, title: $('#articleLeadGalleryTitle')
				, indx: 0 //current
				, over: -1 //hovering
				, loaded: []
				, swap: function(){
						hoverGal.setTitle(hoverGal.full.eq(hoverGal.over).css({visibility:'visible', zIndex:hoverGal.full.length + 1}).attr('title'));
						hoverGal.full.eq(hoverGal.indx).css({zIndex:hoverGal.full.length - hoverGal.indx, visibility:'hidden'});
						hoverGal.indx = hoverGal.over;
					}
				, setTitle: function(ttl){
						hoverGal.title.text(ttl || '&nbsp;')[ttl ? 'show' : 'hide']();
					}
				, onLoad: function(data){
						hoverGal.full.eq(data.index).attr({src:data.image});
						hoverGal.loaded[data.index] = 1;
						if(hoverGal.over == data.index){
							hoverGal.swap();
						}
					}
				, onOver: function(){
						hoverGal.over = hoverGal.thumbs.index(this);
						if(hoverGal.indx != hoverGal.over && hoverGal.loaded[hoverGal.over]){
							hoverGal.swap();
						}
						return false;
					}
				, onOut: function(){
						hoverGal.over = -1;
						return false;
					}
				};
			if(hoverGal.thumbs.length){
				hoverGal.setTitle(hoverGal.full.eq(0).attr('title'));
				if(hoverGalPreloads && hoverGalPreloads.length){
					$.preload(hoverGalPreloads, {onComplete:hoverGal.onLoad});
					hoverGal.thumbs.hoverIntent({over:hoverGal.onOver, out:hoverGal.onOut});
				}
			}
		}
		//IE6 (again)...
		$('#articleLead .content').css({zoom:1});
	});
