///////////////////// rabbleandrouser.com JavaScript /////////////////

document.observe("dom:loaded", function() {
  
  if($$('.white-paper-submit')){	 
  	 $$('.white-paper-submit').invoke('observe', 'click', getWhitePaper);
  }

});

//show comments form

function showForm(){
	Effect.SlideDown('commentsForm', { duration: 1.0 });
	new Effect.Opacity('postCommentLink', { from: 1.0, to: 0, duration: 0.5, afterFinish: function() { Element.addClassName('postCommentLink', 'closed'); }});
}

function showSignup(){
	Effect.SlideDown('signupForm', { duration: 1.0 });
	$('hideSignupLink').style.display="block";
	$('signupLink').style.display="none";
}

function showRouser(){
	Effect.SlideDown('rouserList', { duration: 1.0 });
	$('hideRouserLink').style.display="block";
	$('rouserLink').style.display="none";
}

function scrollForm(){
	Effect.SlideDown('commentsForm', { duration: 1.0 });
	new Effect.Opacity('postCommentLink', { from: 1.0, to: 0, duration: 0.5, afterFinish: function() { }});
	new Effect.ScrollTo('postCommentLink');
}

function hideForm(){
	Effect.SlideUp('commentsForm', { duration: 1.0 }); return false;
	new Effect.Opacity('postCommentLink', { from: 1.0, to: 0, duration: 0.5 });
}

function hideSignup(){
	Effect.SlideUp('signupForm', { duration: 1.0 }); 
	$('hideSignupLink').style.display="none";
	$('signupLink').style.display="block";
}

function hideRouser(){
	Effect.SlideUp('rouserList', { duration: 1.0 }); 
	$('hideRouserLink').style.display="none";
	$('rouserLink').style.display="block";
}

Effect.hideLink = function(element) {
     element = $(element);
     new Effect.Opacity(element, arguments[1] || {});
}



$('person-example').request({
  onComplete: function(){ alert('Form data saved!') }
})


function getWhitePaper(event){
	event.stop();
	
	if($('email').value != "" && $('name').value != ""){
		
		//fade out 
		new Effect.Fade('white-paper-form-shown', { from: 1.0, to: 0, duration: 0.25, afterFinish:function() {
			$('white-paper-ajax-loader').show();
			$('white_paper_form').request({ 
				onComplete: function(transport){
					$('white-paper-ajax-loader').hide();
					new Effect.Appear('white-paper-form-hidden', { from: 0, to: 1.0, duration: 0.5});
				}
		
			});
		
		} });
	
	}else{
		
		alert("Please Enter Required Fields");
		
	}
	
}

function suggestTopic(event){
	event.stop();
	element = Event.element(event);
	var question = $('ask-input').value;
	
	if(question == null || question == '' || question == $('ask-input').readAttribute('title')){
		alert("Please Enter a Valid Topic"); 
		return false;
	}
	
	
	//fade out calendar
	new Effect.Opacity('main-post', { from: 1.0, to: 0, duration: 0.25, afterFinish:function() {
	
		new Ajax.Request('/meetings/suggest', {
			method: 'post',
			parameters: {topic: question}, 
			onComplete: function(transport){
				$('main-post').update(transport.responseText);
				new Effect.Opacity('main-post', { from: 0, to: 1.0, duration: 0.5});
			}
	
		});
	
	} });
	
}