/* Omines Corporate Site
	(c) 2006-2008 Omines - www.omines.com
	
	All rights explicitly reserved - unauthorized reproduction strictly prohibited
*/

// Site class - main active content wrapper
var Site = {
	start: function()
	{
		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($('home-header'))
			Homepage.start();
	},
	ajaxClick: function(e)
	{
		e.stop();
		Lightbox.showPage(e.target.href);
	}
};

// Homepage class - runs interactive content on the homepage
var Homepage = {
		start: function()
		{
			this.slogans = $$('.slogan');
			this.current = 0;
			this.baseline = this.slogans[0].offsetLeft;
			this.doNext.delay(2500, this);
		},
		doNext: function()
		{
			var next = (this.current + 1) % this.slogans.length;
			this.fadeOut = this.slogans[this.current].effects({duration:600, transition: Fx.Transitions.Sine.easeOut});
			this.fadeOut.start({'left':[this.baseline, this.baseline+60], 'opacity':[1,0]});
			this.slogans[next].setStyle('opacity', '0');
			this.fadeIn = this.slogans[next].effects({duration:600, transition: Fx.Transitions.Sine.easeOut});
			this.fadeIn.start.delay(50, this.fadeIn, {'left':[this.baseline-60, this.baseline], 'opacity':[0,1]});
			this.slogans[next].removeClass('hidden');
			this.current = next;
			this.doNext.delay(5500, this);
		}
}

// Lightbox class - allows floating popups with detailed information
var Lightbox = {
	initialize: function()
	{
		var closer = this.close.bind(this);
		this.overlay = new Element('div', {'id':'lb-overlay'}).injectInside(document.body).addEvent('click', closer);
		this.box = new Element('div', {'id':'lb-box'}).injectInside(document.body);
		this.closelink = new Element('a', {'id':'lb-closer'}).injectInside(this.box).addEvent('click', closer);
		this.content = new Element('div', {'id':'lb-content'}).injectInside(this.box);
		this.fx = {
			overlay: this.overlay.effect('opacity', {duration: 500,wait:false}).hide(),
			box: this.box.effect('opacity', {duration: 500,wait:false}).hide()
		};
		$$('.lightbox').each(function(el, idx) {
			el.addEvent('click', this.clickLink.bindWithEvent(this));		
		}, this);
	},
	position: function()
	{
		this.overlay.setStyles({top:0,left:0,width:window.getScrollWidth(),height:window.getScrollHeight()});
		this.box.setStyles({display: '',top:(window.getScrollTop()+75)+'px'});
	},
	clickLink: function(e)
	{
    this.showPage(e.target.href);
    e.stop();
	},
	showPage: function(url)
	{
		this.position();
		new Ajax(url, {
			method: 'get',
			update: $('lb-content'),
			onComplete: function() {
				this.fx.box.start(1);
			}.bind(this)
		}).request();		
		this.fx.overlay.start(0.5);
	},
	close: function()
	{
		this.fx.overlay.start(0);
		this.fx.box.start(0);
	}
};

// Set vent to start running active content when DOM is loaded
window.addEvent('domready', function() { Site.start(); });
