var VineBounce = new Class({
	initialize:function(vine, sign){
		this.myVine = $(vine);
		this.mySign = $(sign);
		this.attach();
	},
	attach:function(){
		this.myVine.set('morph', {duration:1200, transition: 'elastic:out'});
		this.mySign.set('morph', {duration:200});
		this.mySign.addEvent('mouseenter', function(event){
			this.myVine.morph({
			top: -50
			});
			this.mySign.morph({
			top:-10
			});
		}.bind(this));
		this.mySign.addEvent('mouseleave', function(event){
			this.myVine.morph({
			top: -150
			});
			this.mySign.morph({
			top:0
			});
		}.bind(this));
	}
});


window.addEvent('domready', function() {
									 

	
new VineBounce($('home-vine'),$('home-sign'));
new VineBounce($('the-doc-vine'),$('the-doc-sign'));
new VineBounce($('faqs-vine'),$('faqs-sign'));
new VineBounce($('tooth-tips-vine'),$('tooth-tips-sign'));
new VineBounce($('newbies-vine'),$('newbies-sign'));

var cButton = $('contact-button');
var cHolder = $('contact-holder');
cHolder.get('morph', {duration:200});
cButton.addEvent('mouseenter', function(event) {
	cHolder.morph({
		bottom: '-50px',
		paddingLeft:'603px'
	});
});

cButton.addEvent('mouseleave', function(event) {
	cHolder.morph({
		bottom: '-80px',
		paddingLeft:'600px'
	});
});
var centerWindowWidth = document.body.clientWidth/2;
var centerWindowHeight = document.body.clientHeight/2;
$('contact-box').setStyles({
	left: centerWindowWidth - 300,
	top: centerWindowHeight - 150
});
$('indicator').setStyles({
	left: centerWindowWidth - 150,
	top: centerWindowHeight - 75
});
$('contact-box').set('tween',{
					 duration:100
					 });
cButton.addEvent('click', function(event){
	$('content-blocker').setStyles({
		display:'block',
		opacity:0
	})
   $('contact-box').setStyles({
		display:'block',
		opacity:0
	});
   $('contact-box').tween('opacity',1);
   $('content-blocker').tween('opacity', .7);

});

$('close-contact-box').addEvent('click', function(event){
   
	$('contact-box').tween('opacity',0);
	$('content-blocker').tween('opacity',0);
});

//AJAX FORM SCRIPT
var myRequest = new Request({
	url: '/contactSend.php',
	method: 'get',
	onSuccess: function(responsText){
		alert(responseText);
	}
});


$('close-indicator-box').addEvent('click', function(){
				$('indicator').setStyles({
					display: 'none'
				});
				$('indicator-fill').set('html' , 'sending<br /><img src="images/contactBox/ajax-loader(5).gif"/>');
});

$('cForm').set('send',{
	onRequest: function(){
		$('indicator').setStyles({
			display: 'block'
		});
		$('contact-box').setStyles({
			opacity: .7
		});
	},
   onSuccess: function(response){
	   //If form is filled in
	   if (response == 1) {
		   $('indicator-fill').set('html', '<p>Thank you for your message!</p>');
		   $('contact-box').tween('opacity',0);
		   $('content-blocker').tween('opacity',0);
	   }
	   //otherwise
	   else {
		$('indicator-fill').set('html', '<p>You forgot to fill something out...</p><img src="images/contactBox/warning-sign.png" />');
		$('contact-box').setStyles({
			opacity: 1
		});
	   }
   }
   
   }).addEvent('submit', function(event){
	   event.preventDefault();
	   this.send();
});

});
