window.addEvent('domready', function() {
	/******************/
	/* Gallery Thumbs */
	/******************/
	
	var morphElements = $(document.body).getElements('.thumbanchor');
	var images = $('bigImages').getElements('img');
	var captions = $('bigImages').getElements('p');
	
	var lastImage = 0;
	
	// function to set initial values
	morphElements.each(function(item) {
		item.setStyles({
			'width': 55,
			'height': 55,
			'top': 0,
			'left': 0
		});
	});
	
	//function to morph to rollover state
	morphElements.each(function(item) {
		item.addEvent('mouseover', function() {
			var morphIn = new Fx.Morph(this, {
				duration: 100,
				transition: 'sine:out',
				link: 'ignore'
			}).start({
				'width': 75,
				'height': 75,
				'top': -10,
				'left': -10
			});
		});
	});

	//function to morph back to original state
	morphElements.each(function(item) {
		item.addEvent('mouseout', function() {
			var morphIn = new Fx.Morph(this, {
				duration: 500,
				transition: 'bounce:out',
				link: 'ignore'
			}).start({
				'width': 55,
				'height': 55,
				'top': 0,
				'left': 0
			});
		});
	});
	
	/******************/
	/* Gallery Images */
	/******************/
	
	var myFx = new Fx.Tween;
	
	//hide all images and captions
	images.each(function(item) {
		item.setStyle('opacity', 0);
	});
	captions.each(function(item) {
		item.setStyle('opacity', 0);
	});
	
	//fade image in
	function showImage(number){
		myFx = new Fx.Tween(images[number], 'opacity', {duration:500}).start('opacity', 0,1);
		myFx = new Fx.Tween(captions[number], 'opacity', {duration:500}).start('opacity', 0,1);
		return number;
	}
	

	function hideImage(number){
		myFx = new Fx.Tween(images[number], 'opacity', {duration:500}).start('opacity', 1,0);
		myFx = new Fx.Tween(captions[number], 'opacity', {duration:500}).start('opacity', 1,0);
	}
	
	function hideandshow(hide, show){
		if (hide != show) {
			hideImage(hide);
			number = showImage(show);
			return number;
		}
	}
	
	function addclicklistener(item, index, array){
		element.addEvent('click', function() {hideandshow(number, index);return false;});
	}
	
	morphElements.each(function(item, index) {
		item.addEvent('click', function() {
			hideandshow(number, index);
			return false;
		});
	});
	
	number = showImage(0);
	
	/* end */
});