window.addEvent('domready', function(){

	if ($('large-feature-container')) {
		/* settings */
		var showDuration = 14000;
		var container = $('large-feature-container');
		var slides = container.getChildren();
		var currentIndex = 0;
		var interval;
		/* opacity and fade */
		slides.each(function(slide,i){ 
			if(i > 0) {
				slide.set('opacity',0);
			}
		});
		/* worker */
		var Slideshow = function() {
			slides[currentIndex].fade('out');
			slides[currentIndex = currentIndex < slides.length - 1 ? currentIndex+1 : 0].fade('in');
		};
		/* start once the page is finished loading */
		window.addEvent('load',function(){
			interval = Slideshow.periodical(showDuration);
		});
	}


	// feature image
	// large image rotater feature
	/*if ($('large-feature') && large_feature_images && large_feature_images.length > 1) {
		(function(){
			var animDuration = 1200;
			var slideDelay = 3500;

			var currentSlide = 0;

			var slideShow = $('large-feature');

			var showSlide = function(whichSlide){
				$clear(timer);

				if (whichSlide === undefined || isNaN(whichSlide)) whichSlide = currentSlide + 1;
				if (whichSlide >= large_feature_images.length) whichSlide = 0;

				currentSlide = whichSlide;

				var imageOverlayLoad = function(){
					imageOverlay.set({
						styles: {
							opacity: 0
						},
						tween: {
							duration: animDuration,
							onComplete: function(){
								slideShow.setStyle('background-image', 'url(' + imageOverlay.get('src') + ')');
								imageOverlay.destroy();
								timer = showSlide.delay(slideDelay);
							}
						}
					}).inject(slideShow, 'top');

					imageOverlay.fade('in');
				}

				var imageOverlay = new Asset.image(large_feature_images[whichSlide].image, {
					id: 'large-feature-image',
					onload: imageOverlayLoad
				});
			}

			var timer = showSlide.delay(slideDelay - animDuration);
		})();
	}*/

	// homepage services list
	if (document.getElement('.services-list')) {
		(function(){
			$$('.services-list').each(function(list){
				var expanders = list.getElements('li div.description');
				var maxheight = 0;

				expanders.each(function(el){
					maxheight = Math.max(maxheight, el.getSize().y);
				});

				var instrument = new Fx.Accordion(list.getElements('li a'), expanders, {
					trigger: 'mouseenter',
					opacity: false,
					fixedHeight: maxheight
				});

			});
		})();
	}

	// the tree
	if ($('the-tree')) {
		(function(){
			$$('#the-tree li').each(function(li){
				var paragraph = li.getElement('div');
				var oldheight = paragraph.getSize().y;
				paragraph.setStyle('height', 10);

				li.addEvents({
					mouseenter: function(){
						paragraph.tween('height', oldheight);
					},
					mouseleave: function(){
						paragraph.tween('height', 10);
					}
				});
			});
		})();
	}
});

// contact page map
window.addEvent('load', function(){
	if ($('map')) {
		if (GBrowserIsCompatible()) {
			var map = new GMap2($('map'));
			var location = new GLatLng(53.483641, -2.236919);
			map.setCenter(location, 14);
			map.addOverlay(new GMarker(location));
			map.setUIToDefault();
		}
	}
});
