document.observe('dom:loaded', function(){
	
	var flash_target = $('homepage-flash');
	if (flash_target) {
		if (typeof(swfobject) == 'object') {
			swfobject.embedSWF("/swf/fsh.swf", "homepage-flash", "910", "400", "9", "/swf/express_install.swf", { wmode : "opaque" }, { base : "/swf/" });
		}
	}
	
	var homepage_carousel = $('homepage-columns');
	if (homepage_carousel) {
		new Carousel(homepage_carousel);
	}
	
	var bios = $$('.BioLink');
	if (bios) {
		bios.each(function(bio){
			new BioWrapper(bio);
		});
	}
	
});

var Carousel = Class.create({
	initialize : function(wrapper){
		this.node = wrapper;
		this.carousel = $('homepage-carousel');
		this.targets = this.node.select('.Target');
		if (!this.carousel || this.targets.length < 3) { return; }
		this.tabs = this.carousel.select('LI A');
		if (this.tabs.length < 3) { return; }
		this.tabs.each(function(t){
			t.observe('click', this.switchTab.bindAsEventListener(this));
			t.removeAttribute('href');
		}, this);
	},
	switchTab : function(e){
		var title = e.element().title || 'notitle';
		var tab = e.element().up('LI');
		var target = $(title);
		if (target && tab) {
			this.targets.each(function(t){
				t.setStyle({ display : 'none'});
			});
			target.setStyle({ display : 'block' });
			this.tabs.each(function(t){ t.up().removeClassName('Active'); });
			tab.addClassName('Active');
		}
	}
});

var BioWrapper = Class.create({
	initialize : function(link){
		this.node = link;
		this.target = $(link.id.sub("show-", ""));
		if (!this.node || !this.target) { return; }
		this.closer = this.target.down(".Close");
		if (!this.closer) { return; }
		this.node.setStyle({ display : "block" });
		this.node.observe('click', this.toggleWrapper.bindAsEventListener(this));
		this.closer.observe('click', this.toggleWrapper.bindAsEventListener(this));
	},
	toggleWrapper : function(){
		this.target.toggle();
	}
});