// JavaScript Document
/*
Title:		Fat Tire City Page Javascript page
Author:		Matt McCloskey, Kemso Design
Date:		2008
*/


loadJavascript(script_root+'/AC_RunActiveContent.js');

preloadImages('/images/buttons/tours_over.png', '/images/icons/golink_sm_red.png');

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

	/* add arrow */
	/*
var arrow = new Element('div', {
		'styles': {
			'position': 'absolute',
			'left': 8
		},
		'class': 'arrow'
	}).inject($('main').getElement('.header')).set('morph', {duration: 200});
*/

	$('navigation').getElements('a').each(function(el){
		el.set('morph', {duration: 200});
		el.addEvents({
			'mouseenter': function(){
				this.morph('.navover');
				
				/*
var thisY = this.getPosition().y;
				$('header').getElement('.arrow').morph({
					'opacity': 1,
					'top': thisY+11
				});
*/
			},
			'mouseleave': function(){
				this.morph('.navup');
				/*
$('header').getElement('.arrow').morph({
					'opacity': 0
				});
*/
			}
		});
	});
	
	
	
	/* Mailing list form */
	$('mailinglist').addEvent('submit', function(e){
		var e = new Event(e).stop();
		var email = $('mailing_email').get('value');
		if(email == "" || email == "Enter Your Email Address"){
			$('mailinglist_rsp').set('html', "Please enter your Email Address!");
		}
		else
		{
			$('mailinglist_rsp').set('html', "<em>Sending...</em>");
			var req = this.get('send')
			.addEvents({
				'success': function(rsp){
					if(rsp == "ok"){
						$('mailinglist_rsp').set('html', "Thanks! You have been added.");
						$('mailing_email').set('value', "Enter Your Email Address");
					}else{
						$('mailinglist_rsp').set('html', rsp);
					}
				}
			})
			.send();
		}
	});
	
	/* Mailing list form Field events */
	$('mailing_email').addEvents({
		'focus': function(){
			if(this.value == "Enter Your Email Address"){
				this.value = "";
			}
		},
		'blur': function(){
			if(this.value == ""){
				this.value = "Enter Your Email Address";
			}
		}
	});
	
	
	
	
	
	/* contact form */
	if($('contactform')){
	
		$('contactform').addEvent('submit', function(e){
			var e = new Event(e).stop();
			
			$('contactform').getElement('.alert').set('html', 'Sending...');
			
			var form = this.get('send');
			form.addEvent('success', function(text){
				$('contactform').getElement('.alert').set('html', text);
				
				if(text == 'Thanks! Your mail has been sent. We will get back with you as soon as possible.'){
					$('contactform').reset();
				}
			});
			form.send();
		});
	
	}

});