	
	/*
		-- PHOTO GALLERY FUNCTIONALITY  --
	*/
	function image_nav(pos) {
		if (pos < 0) {
			if (current_pos > 0) pos = current_pos - 1;
			else pos = $$('#gallery_thumbs img').length - 1;
		} else {
			if (current_pos < $$('#gallery_thumbs img').length - 1) pos = parseInt(current_pos) + 1;
			else pos = 0;
		}
		switch_image($('thumb_' + pos));
	}
	
	var current_pos = 0;
	function switch_image(element) {
		element = $(element);
		var id = element.readAttribute('id');
		var pos = id.split('_')[1];
		var new_img = $('image_' + pos);
		
		// update selected square
		$$('#gallery_thumbs img').each(function(x) { x.removeClassName('selected'); });
		$('thumb_' + pos).addClassName('selected');

		// is the image after the current one (on top)
		if ($('image_' + current_pos).next('#image_' + pos)) {
			new Effect.Appear('image_' + pos, { duration: .5 });
		} else {
			// update visible image
			new_img.show();
			new_img.nextSiblings().each(function(x) {
				if (x != $('image_' + current_pos) && x.tagName == 'IMG') x.hide();
				else new Effect.Fade('image_' + current_pos, { duration: .5 });
			});
		}

		$('caption_' + current_pos).hide();
		$('caption_' + pos).show();
		current_pos = pos;
	}
	
	
	var timer;
	var down_button = false;
	var up_button = false;
	
	var top_pos = 0;
	var min_pos;
	
	function scroll_it() {
		if (up_button && top_pos < 0) {
			top_pos += 10;
			$('scrollable_content').style.top = top_pos + "px";
		} else if (down_button && top_pos > min_pos) {
			top_pos -= 10;
			$('scrollable_content').style.top = top_pos + "px";
		}
	}
	
	function update_scroll_height() { min_pos = 500 - $('scrollable_content').getHeight(); }
	
	Event.observe(window, 'load', function() {
		$$('#nav li').each(function(x) {
			x.onmouseover = function() { if (this.down('ul')) this.addClassName('selected'); }
			x.onmouseout = function() { this.removeClassName('selected'); }
		});
		
		if ($('gallery_photos')) {
			$$('#gallery_thumbs img').each(function(x) {
				x.onclick = function() { switch_image(this, true); }
			});
		}
		
		if ($('scrollable_buttons')) {
			timer = setInterval("scroll_it()", 1);
			update_scroll_height();
			Event.observe('scroll_up', 'mousedown', function() { up_button = true; });
			Event.observe('scroll_up', 'mouseup', function() { up_button = false; });
			Event.observe('scroll_down', 'mousedown', function() { down_button = true; });
			Event.observe('scroll_down', 'mouseup', function() { down_button = false; });
		}
	});