﻿if (typeof(FOH) == "undefined") FOH = {};





FOH.Gallery = Class.create({

	initialize: function(wrapper) {
		this.current = false;

		var thumbs = wrapper.getElementsBySelector('ul.nav li');
		thumbs.each(function(thumb) {
			thumb.observe('click', this.activate.bind(this, thumb));
		}.bind(this));
		
		if (thumbs.length>0) {
			this.createImg(wrapper);
			this.activate(thumbs[0]);
		}
	},

	createImg: function(wrapper) {
		this.image = Builder.node('img', { className:'swapimage', border:0 });
		wrapper.appendChild(this.image);
	},

	activate: function(item, evt) {
		if (evt) {
			var target = evt.findElement('a[href]');
			if (target && !target.href.match('#')) Event.stop(evt);
		}
		
		if (this.current) this.deactivate(this.current);

		var url = item.down('a').href;
		this.image.src = url;

		var title = item.down('a').innerHTML.stripTags().strip();
		this.image.alt = title;

		item.addClassName('active');
		
		this.current = item;
	},
	
	deactivate: function(item) {
		item.removeClassName('active');
	}

});
