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

	if($chk($('drop_down_menu')))
	{
		var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);

		$('drop_down_menu').getElements('li.menu').each( function( ddelem ){
			var list = ddelem.getElement('ul.links');
			var menuFx = new Fx.Slide(list);
			menuFx.hide();
			ddelem.addEvents({
				'mouseenter' : function(){
					menuFx.cancel();
					menuFx.show();
					var children = this.getChildren();
					// IE6
					if(isIE6)
					{
						children[1].setStyles({'width':'142px', 'background-color':'#1D4657', 'position': 'absolute', 'z-index': '100000'});
					} else {
					// Everything else
						children[1].setStyles({'width':'142px', 'background-color':'#1D4657', 'position': 'relative'});
					}
				},
				'mouseleave' : function(){
					menuFx.cancel();
					menuFx.hide();
					var children = this.getChildren();
					children[1].setStyles({'width':'126px', 'position':'relative'});
				}
			});
			
		});

	}

	if($chk($('emailsignupdiv')))
	{
		var inputs	= $$('input.textinput');

		inputs.each(function(e){
			e.addEvent('focus', function(){
				if(e.get('value')==e.getProperty('rel'))
				{
					e.set('value','');
				}
			});
		});

		inputs.each(function(e){
			e.addEvent('blur', function(){
				if(e.getProperty('name')=="email"&&e.get('value').length>1)
				{
					new Request({
						url: '/action/checkemail/',
						method: 'post',
						data: 'email=' + $('emsignupemail').get('value'),
						onComplete: function() {
							if(this.response.text!="true")
							{
								alert('Please enter a valid e-mail address.');
								e.focus();
							}
						}
					}).send();
				} else {
					if(e.get('value').length<1)
					{
						e.set('value', e.getProperty('rel'));
					}
				}
			});
		});
	}

	$('emailsubmit').addEvent('click', function()
	{
		var msg = '';
		var inputs	= $$('input.textinput');

		inputs.each(function(e){
			if(e.get('value').length<1||e.get('value')==e.getProperty('rel'))
			{
				msg += 'Please enter your ' + e.get('rel') + "\n";
			}
		});

		if(msg.length>0)
		{
			alert(msg);
		} else {
			new Request({
				url: '/action/signup/',
				method: 'post',
				data: 'email=' + $('emsignupemail').get('value') + "&zip=" + $('emsignupzip').get('value') + "&firstname=" + $('emsignupname').get('value'),
				onComplete: function() {
					window.open('http://eepurl.com/bGz-','_self');
				}
			}).send();
		}
	});

});