
	var current_pos = 0;
	var locked = false;
	var home_timer;
	var paused = false;
	var home_count = 0;
	
	Event.observe(document, 'dom:loaded', function() {
		if ($('home-slideshow')) {
			$$('#home-thumbs .image').each(function(x) {
				x.onclick = function() {
					clearTimeout(home_timer);
					paused = true;
					load_slide($(this).previousSiblings().length);
					return false;
				}
			});
			home_timer = setTimeout('next_slide()', 3500);
		}
			
		$$('#nav li').each(function(x) {
			x.observe('mouseenter', function() { if ($(this).down('ul')) $(this).addClassName('over'); });
			x.observe('mouseleave', function() { if ($(this).down('ul')) $(this).removeClassName('over'); });
		});
		
		$('search-text').onfocus = function() { if (this.value == 'search') this.value = ''; }
		$('search-text').onblur = function() { if (this.value == '') this.value = 'search'; }
		
		$('video-overlay').onclick = function() {
			$('video-container').hide();
			$('video-overlay').hide();
		}
		
		home_count = $$('#home-thumbs img').length;
	});
	
	function next_slide() {
		var pos = (current_pos < (home_count - 1)) ? current_pos + 1 : 0;
		load_slide(pos);
	}
	
	function load_slide(pos) {
		if (pos != current_pos && !locked) {
			locked = true;
			
			setTimeout(function() {
				$$('#home-descriptions p')[current_pos].hide();
				$$('#home-descriptions p')[pos].show();
				$$('.home-slideshow-more')[current_pos].hide();
				$$('.home-slideshow-more')[pos].show();
				$('logo').className = ['l','a','n','d'][pos];
			}, 200);
			
			new Effect.Parallel([
				// thumbnail bottom border
				new Effect.Fade($$('#home-thumbs .highlight')[current_pos], { sync: true }),
				new Effect.Appear($$('#home-thumbs .highlight')[pos], { sync: true }),
				// caption transition
				new Effect.Fade($$('#home-captions img')[current_pos], { sync: true }),
				new Effect.Appear($$('#home-captions img')[pos], { sync: true }),
				// thumbnail opaque overlay
				new Effect.Appear($$('#home-thumbs .overlay')[current_pos], { sync: true }),
				new Effect.Fade($$('#home-thumbs .overlay')[pos], { sync: true }),
				// left side fade
				new Effect.Fade($$('#home-slideshow-left img')[current_pos], { sync: true }),
				new Effect.Appear($$('#home-slideshow-left img')[pos], { sync: true }),
				// right side slide
				new Effect.Morph($('home-slideshow-right-slider'), { sync: true, style: 'left: ' + (pos * -509) + 'px;' }),
				// title shift
				new Effect.Morph($('home-titles-slider'), { sync: true, style: 'left: ' + (pos * -400) + 'px;' }),
			], {
				duration: .6,
				afterFinish: function() {
					current_pos = pos;
					locked = false;
					if (!paused) home_timer = setTimeout('next_slide()', 3500);
				}
			});
		}
	}
	
	function play_video() {
		$('video-overlay').setStyle({ height: get_window_height() + "px" });
		new Effect.Appear('video-overlay', {
			from: 0,
			to: .9,
			duration: .5,
			afterFinish: function() {
				$('video-container').setStyle({
					top: (document.viewport.getHeight() - $('video-container').getHeight()) / 2 - 45 + document.body.scrollTop + 'px'
				}).show();
			}
		});
	}
	
	function get_window_height() {
		// retrieve the height of the document including scrollable area
		var document_height, window_height;
		
		if (window.innerHeight && window.scrollMaxY) document_height = window.innerHeight + window.scrollMaxY;
		else if (document.body.scrollHeight > document.body.offsetHeight) document_height = document.body.scrollHeight;
		else document_height = document.body.offsetHeight;
		
		if (self.innerHeight) window_height = self.innerHeight;
		else if (document.documentElement && document.documentElement.clientHeight) window_height = document.documentElement.clientHeight;
		else if (document.body) window_height = document.body.clientHeight;
		
		return (document_height < window_height) ? window_height : document_height;
	}
