
document.observe("dom:loaded", function(){
	
	$$('#navlist li a').each(function(e){
		
		// Hide menus by default
		var nextul = $(e).next('ul'); 
		
		if ($(e).innerHTML == citetype) {
			$(e).addClassName('thispage'); 
		}
			
		// Is there a menu...
		if ($(nextul)) { 
			if ($(e).innerHTML != citeformat) {
				$(nextul).hide(); 
			} else {
				$(nextul).addClassName('on');
				$(e).addClassName('on');
			}
			
			
			Event.observe(e, 'click', function(event){
				// Hide all to begin with on this click
				$$('#navlist li ul').each(function(ee){
					if ($(ee).visible()){
						Effect.BlindUp(ee, { 
							duration: 0.3, 
							queue: {
								position:'end', 
								scope: 'menuxscope', 
								limit:2
							}, 
							afterUpdate: function(){
									$(ee).previous().removeClassName('on');
								}
							}
						);
					}
				});
				// Toggle
				if (!$(e).next('ul').visible()){
					Effect.BlindDown($(e).next('ul'), { 
						duration: 0.3, 
						queue: {
							position:'end', 
							scope: 'menuxscope', 
							limit:2
						}, 
						afterUpdate: function(){
								$(e).addClassName('on');
							}
						}
					);
				}
				// Stop click
				$(event).stop();
			});
		}
		
	});
	
	$$('#processform input').each(function(e){
		if ($(e).next('span')){
			Event.observe(e, 'focus', function(event){
				Effect.Appear($(e).next(), {duration:0.3, queue: {position:'end', scope: 'myqueue_'+$(e).next().identify(), limit:2}});
			});
			Event.observe(e, 'blur', function(event){
				Effect.Fade($(e).next(), {duration:0.3, queue: {position:'end', scope: 'myqueue_'+$(e).next().identify(), limit:2}});
			});
		}
	});
	
});
var scrolledonce;
scrolledonce = 0;
function showresultpart() {
	$('resultsection').show();
	$('result').update('<img src="/images/loading.gif" class="loading" />');
	scrolledonce++;
	if (scrolledonce < 2) {
		new Effect.ScrollTo('result', {offset: -24});
	}
}

function resultsreturned() {
	if ($('result').innerHTML.strip() == '') {
		$('resulterror').show();
		$('resulterror').update('No data entered or citationcreation may have returned an error. Please try again later or submit this to our blog.');
		$('resultsection').hide();
	} else {
		$('resulterror').hide();
	}
}

function processthisform(category, type) {
	var params = Form.serialize($('processform'));
	var options = {
					method: 'get',
					parameters: params,
					onCreate: function() {showresultpart();},
					onComplete: function(){resultsreturned();}
				};
	new Ajax.Updater('result', '/index.php?category='+category+'&type='+type+'&getresult=true', options);
}

function addtolist() {
	new Ajax.Updater('citationlist_data', '/createlist.php');
}

function deletecitation(id) {
	var options = {
					method: 'get',
					parameters: { 'delete': id }
				};
	new Ajax.Updater('citationlist_data', '/createlist.php', options);
}

function changevisible() {
	var numshow = Form.getInputs('processform','radio','authorsnum').find(function(radio) { return radio.checked; }).value;

	if (numshow == 1) {
		$('author_2').hide();
		$('author_3').hide();
		$('author_4').hide();
		$('author_5').hide();
	}
	if (numshow == 2) {
		$('author_2').show();
		$('author_3').hide();
		$('author_4').hide();
		$('author_5').hide();
	}
	if (numshow == 3) {
		$('author_2').show();
		$('author_3').show();
		$('author_4').hide();
		$('author_5').hide();
	}
	if (numshow == 4) {
		$('author_2').show();
		$('author_3').show();
		$('author_4').show();
		$('author_5').hide();
	}
	if (numshow == 5) {
		$('author_2').show();
		$('author_3').show();
		$('author_4').show();
		$('author_5').show();
	}
}
