/**
 * Catharina Bloom
 * (c) 2006-2009 Omines - www.omines.com
 * 
 * All rights explicitly reserved - unauthorized reproduction strictly prohibited
 */

// Site class - main active content wrapper
var Site = {
	start: function()
	{
		// Load additional assets as required by JS
		new Asset.css('/static/styles/js-supported.css');
		new Asset.css('/static/styles/lightbox.css');
		
		new SmoothScroll({duration:300, transition:Fx.Transitions.Expo.easeOut});
		$$('a.ajax').each(function(el, idx) {
			el.setStyle('display', 'inline');
			el.addEvent('click', this.ajaxClick.bindWithEvent(this));
			el.href = el.title;
			el.title = '';
			if(idx == 0) Lightbox.initialize();
		}, this);
		if ($$('body.home'))
			Homepage.start();
		if ($('contact-subject'))
		{
			$('contact-subject').addEvent('change', function() {
				this.toggleContactForm($('contact-subject').getSelected());
			}.bind(this));
		}
		$('leaderblock').getFirst('.leader').setStyle('height', $('leaderblock').getFirst().getFirst('.leader-text').getHeight());
	},
	ajaxClick: function(e)
	{
		e.stop();
		Lightbox.showPage(e.target.href);
	},
	toggleContactForm: function(selected)
	{
		$('contact-bloomparty').addClass('hidden');
		$('contact-complaint').addClass('hidden');
		$('contact-consultant').addClass('hidden');
		var	selectedId	= parseInt(selected.get('value'));
		switch (selectedId)
		{
			case 2: $('contact-bloomparty').removeClass('hidden'); break;
			case 3: $('contact-complaint').removeClass('hidden'); break;
			case 4: $('contact-consultant').removeClass('hidden'); break;
		}
	}
};

// Homepage class - runs interactive content on the homepage
var Homepage = {
	start: function()
	{
		// Run slogan animations
		this.slogans = $$('.slogan');
		this.current = 0;
		this.baseline = this.slogans[0].offsetTop;
		this.nextSlogan.delay(5000, this);	
	},
	nextSlogan: function()
	{
		var next = (this.current + 1) % this.slogans.length;
		this.slogans[this.current].set('morph', {duration:600, transition: Fx.Transitions.Sine.easeOut}).morph({top:[this.baseline, this.baseline+30], opacity:[1,0]});
		this.slogans[next].setStyle('opacity', 0).set('morph', {duration:600, transition: Fx.Transitions.Sine.easeOut}).morph.delay(50, this.slogans[next], {top:[this.baseline-30, this.baseline], opacity:[0,1]});	
		this.slogans[next].removeClass('hidden');
		this.current = next;
		this.nextSlogan.delay(5000, this);
	}
}

// Set event to start running active content when DOM is loaded
window.addEvent('domready', function() { Site.start(); });
