// Standard functions throught b4k4.co.uk photography
// (C) Phil Moore 2007

// opacity ratings for fade elements
var id2opacity = { 'prev' : 1, 'next' : 1, 'caption' : .8 };

window.addEvent('domready', function() {
	/* HEAD NAVIGATION ETC */
	var head = $('header'); 
	navSlide = $('header_nav').effect('height', {'duration':300});
	navSlide.toHeight = parseFloat($('header_nav').getStyle('height'));
	navSlide.hide();
	
	head.addEvent('mouseenter', function() {
		navSlide.stop();
		navSlide.start(parseFloat($('header_nav').getStyle('height')),navSlide.toHeight);
		head.addClass('over');
	});
	head.addEvent('mouseleave', function() {
		(function() { 
			navSlide.stop();
			navSlide.start(parseFloat($('header_nav').getStyle('height')), 0);
			head.removeClass('over') 
		}).delay(500);
	});
	/* END: HEAD NAVIGATION ETC */
	
	/* SINGLE IMAGE VIEW */
	var image = $('image');
	if (image) {
		image.addClass('fancy');
		fades = image.getElements('.image-meta');
		fades.each(function(fade) { 
			fade.fx = fade.effect('opacity', {'duration':300});
			fade.fx.fadeTo = id2opacity[fade.getProperty('id')];
			fade.fx.set(0);
		} );
		image.addEvent('mouseenter', function() {
			fades.each(function(fade) { fade.fx.stop(); fade.fx.start(fade.getStyle('opacity'), fade.fx.fadeTo) } );
		});
		image.addEvent('mouseleave', function() {
			fades.each(function(fade) { fade.fx.stop(); fade.fx.start(fade.getStyle('opacity'), 0) } );
		});
	}
	/* END: SINGLE IMAGE VIEW */	
	
	/* CATEGORY IMAGES */
	// add the 'hover arrow' div in (mouseover functionality already set from '.add-over' class)
	setThumbs = $('set-thumbs');
	if (setThumbs) {
		setThumbs.getElements('a.cat').each(function(cat) { cat.innerHTML += '<div class="cat-arrow"></div>'; });
		
	}
	/* END CATEGORY IMAGES */
	
	/* SMALL THUMBS */
	if ($('thumbs')) $('thumbs').getElements('a.thumb').each(function(thumb) { 
		thumb.setStyle('opacity', 1);	// needed for wierd IE rendering
		thumb.addEvent('mouseover', function() { thumb.setStyle('opacity', .8); });
		thumb.addEvent('mouseout', function() { thumb.setStyle('opacity', 1); });
	});
	/* END SMALL THUMBS */
			
});