/*
	HANDLER FOR DOMREADY EVENT
*/
window.addEvent("domready", function()
{

	// decorate and set up the tabs with tweens and whatnot //
	$$('a.menu').each(function(el) 
	{
  		if (el.hasClass(sectionName))
  		{
	  		// do this for the current page tab //
	  		el.addEvent('click', function()
	  		{
	  			return false;
	  		});
  		}
  		else
  		{	
	  		// do this for other tabs //
	  		el.addEvent('mouseover', function()
	  		{
	  			el.set('morph', {duration:200, transition:Fx.Transitions.Quart.easeOut});
	  			el.morph({'height':[el.getCoordinates().height, 40],'margin-top':[el.getStyle('margin-top'), 74]})
	  		});
	  		
	  		el.addEvent('mouseout', function()
	  		{
	    		el.set('morph', {duration:200, transition:Fx.Transitions.Quart.easeIn});
	    		el.morph({'height':[el.getCoordinates().height, 30],'margin-top':[el.getStyle('margin-top'), 84]})
	  		});
  		}
  
	});
	
	// sets starliner1 class to transparent //
	$$('.starliner1').each(function(el) 
	{
		el.setStyle('opacity', 0.4);
	});
	
	// bumps the titlebox up in the case of ie //
	if (Browser.Engine.trident)
	{
		var el = $(document.body).getElement('.titlebox');
		//el.setStyle('margin-top', -5);
	}
	
	window.emailHandler = new EmailHandler2();

});

window.addEvent('load', positionTheBox); 
window.addEvent('resize', positionTheBox);

function positionTheBox()
{
	// position background and fade in effect here //
	var tbox = $(document.body).getElement('.transparentbox');
	var cbox = $(document.body).getElement('.page_content');
	
	var coords = cbox.getCoordinates();
	tbox.setStyle('height', coords.height);
	tbox.setStyle('top', coords.top);
	tbox.setStyle('left', coords.left);
	if (tbox.getStyle('opacity') > getTranparencyValue()) 
	{
		tbox.setStyle('opacity', 0);
		tbox.setStyle('visibility','');
	}
	tbox.set('tween', {duration:1000});
	tbox.tween('opacity',getTranparencyValue());
}

function getTranparencyValue()
{
	var retval;
	if (sectionName == 'HowWeSeeIt' || sectionName == 'WhatWeFund')
		retval = 0.35;
	else
		retval = 0.35;
	
	return retval;
}

var EmailHandler2 = new Class(
{
	initialize: function()
	{
		this.canvas = $(document.body).getElement('div.email-form form');
		this.slider = new Fx.Slide(this.canvas,{duration:400});
		this.slider.hide();
		this.canvas.setStyle('visibility','visible');	
		
		this.btn = $('email_btn');
		this.btn.addEvent('click', this.onBtnClick.bind(this));
		
		this.signupBtn = $('signup-btn');
		this.signupBtn.addEvent('click', this.onSignupClick.bind(this));
		
		this.signupBtn.addEvent('mouseenter', (function(){ this.signupBtn.getFirst().setProperty('src', template_url + '/images/signup_btn_over.png'); }).bind(this));
		this.signupBtn.addEvent('mouseleave', (function(){ this.signupBtn.getFirst().setProperty('src', template_url + '/images/signup_btn.png'); }).bind(this));
		
		$('email_cancel').addEvent('click', (function(){ this.slider.slideOut(); }).bind(this));
		
		this.request = new Request.HTML({url:template_url + '/email_signup.php'});
		
		this.loadingscreen = new Element('div',{style:'position:absolute;top:0;background-color:#FFF;'});
		this.canvas.getParent().grab(this.loadingscreen);
		this.loadingscreen.setStyles({'width':this.canvas.getSize().x, 'height':this.canvas.getSize().y, 'opacity':0});
		
		new Element('div',{style:'text-align:center;margin-top:160px;color:#666;font-size:1.2em;',html:'&nbsp;'}).inject(this.loadingscreen);
		
	},
	
	onSignupClick: function()
	{
		//if (this.signupBtn.get('text') == 'THANK YOU.') return false;
		
		this.slider.slideIn();
		return false;	
	},
	
	onBtnClick: function()
	{
		if (!this.emailValidates())
		{
			this.loadingscreen.getFirst().set('text','please provide a valid email address.');
			this.loadingscreen.tween('opacity',1);
			this.loadingscreen.tween.delay(3000, this.loadingscreen, ['opacity', 0]);
			return;
		}
		
		if (this.canvas.firstName.value.length == 0)
		{
			this.loadingscreen.getFirst().set('text','please provide a first name so we may poperly contact you.');
			this.loadingscreen.tween('opacity',1);
			this.loadingscreen.tween.delay(3000, this.loadingscreen, ['opacity', 0]);
			return;
		}
		
		if (this.canvas.lastName.value.length == 0)
		{
			this.loadingscreen.getFirst().set('text','please provide a last name so we may poperly contact you.');
			this.loadingscreen.tween('opacity',1);
			this.loadingscreen.tween.delay(3000, this.loadingscreen, ['opacity', 0]);
			return;
		}
		
		this.loadingscreen.getFirst().set('text','Thank You.');
		this.loadingscreen.tween('opacity',1);
		
		(function()
		{
			this.loadingscreen.tween('opacity',0);
			this.slider.slideOut();
			this.request.post(this.canvas);
		}).delay(3000, this);
	},
	
	emailValidates: function()
	{
		var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		return this.canvas.email.value.match(emailRegEx);
	}
});


/** 
* @depracated
*/ /*
var EmailHandler = new Class(
{
	initialize: function()
	{
		this.msg = 'YOUR EMAIL HERE';
		
		this.input = $('email_input');
		this.input.value = this.msg;
		this.input.setStyles({'color':'#AAAAAA','font-weight':'bold'});
		this.input.addEvent('focus', this.onInputFocus.bind(this));
		this.input.addEvent('blur', this.onInputBlur.bind(this));
		
		this.btn = $('email_btn');
		this.btn.addEvent('click', this.onBtnClick.bind(this));
		
		this.slider = new Fx.Slide($('email_table'));
		this.slider.hide();
		this.slider.slideIn();
		
		this.request = new Request.HTML({url:template_url + '/email_signup.php'});
		this.request.addEvent('success', this.onEmailSent.bind(this));
		this.request.addEvent('failure', this.onEmailSent.bind(this));
	},
	
	onInputFocus: function()
	{
		if (this.input.value == this.msg) 
		{
			this.input.value = '';
			this.input.setStyle('color','#000000');
		}
	},
	
	onInputBlur: function()
	{
		if (this.input.value == '') 
		{
			this.input.value = this.msg;
			this.input.setStyle('color','#AAAAAA');
		}
	},
	
	onBtnClick: function()
	{
		//if (this.input.value == this.msg || this.input.value == 'THANK YOU!') return;
		
		if (!this.emailValidates())
		{
			this.input.set('tween',{duration:1250,transition:Fx.Transitions.Bounce.easeOut});
			this.input.tween('background-color',['#FF0000','#FFFFFF']);
			return;
		}
		
		this.slider.slideOut();
		
		// send the request //
		this.request.get({'email': this.input.value});
	},
	
	onEmailSent: function(responseTree, responseElements, responseHTML, responseJavaScript)
	{
		this.input.value = this.msg;
		this.slider.slideIn.delay(1500, this.slider);
		this.input.value = 'THANK YOU!';
	},
	
	emailValidates: function()
	{
		var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		return this.input.value.match(emailRegEx);
	}
});
*/
