var tasks = [];

function hide(el) {
	el.setStyle('display', 'none');
}

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

	$(document.body).getElements('.hot').addEvents({
		'mouseenter': function(){
			var sms = $(document.body).getElements('.submenu');
			for(var i = 0; i < sms.length; ++i)
				hide(sms[i]);
				
			var sm = $(document.body).getElements('ul.' + this.id);
			sm[0].setStyle('display', 'block');
			sm[0].getElements('a').addEvents({
				'mouseout': function() {
					tasks.push(hide.delay(2000, this, sm[0]));
				},
				'mouseenter': function() {
					for(var i = 0; i < tasks.length; ++i)
						$clear(tasks[i]);
					
				}
			});
		}
	});


	if($('submit')) {
		// Listen for click events on the submit button.
		$('submit').addEvent( 'click', function(evt){
			// Stops the submission of the form.
			new Event(evt).stop();

			var e = new Fx.Morph('progress');
			e.start({'display': 'block', 'height': 60,'opacity': 100});
			this.fade(0).setStyle('display', 'none');
			
			$('msgform').set('send',{
				onRequest: function(){
				},
				onSuccess: function(){
					var e = new Fx.Morph('progress');
					e.start({'display': 'none', 'height': 0,'opacity': 0});
					e = new Fx.Morph('fail');
					e.start({'display': 'none', 'height': 0,'opacity': 0});
					e = new Fx.Morph('success');
					e.start({'display': 'block', 'height': 60,'opacity': 100});
				},
				onFailure: function(){
					// Hide loading and show fail for 3 seconds.
					var e = new Fx.Morph('progress');
					e.start({'display': 'none', 'height': 0,'opacity': 0});
					e = new Fx.Morph('fail');
					e.start({'display': 'block', 'height': 60,'opacity': 100});
					
					var fx = function() { $('submit').setStyle('display', 'block').fade('in');  };
					fx.delay(1000);
				}
			});

			setTimeout(function() { $('msgform').send(); }, 1000);
		} );
	}
});

function show_hide(el1, el2, el3, el4, l1, l2, l3, l4) {
	$(el1).setStyle('display', 'block');
	$(el2).setStyle('display', 'none');
	$(el3).setStyle('display', 'none');
	$(el4).setStyle('display', 'none');

	$(l1).className = 'active';
	$(l2).className = '';
	$(l3).className = '';
	$(l4).className = '';
}

function show_hide2(el1, el2, l1, l2) {
	$(el1).setStyle('display', 'block');
	$(el2).setStyle('display', 'none');
	
	$(l1).className = 'active';
	$(l2).className = '';
}


