var blog_url='';

function start_analysis(){
	new Effect.Fade('screen1', {duration: 0.3}); 
	window.setTimeout("$('screen2').style.display='block';",500);
	
	blog_url = $('blog_url').value;
	
	$('progress_log').innerHTML='';
	
	element = Builder.node('p',{className:'log_message'},'Connecting to the blog...');
	$('progress_log').appendChild(element);
	
	new Ajax.Request('connect.php', {parameters:'url='+escape(blog_url), 
		onSuccess:function(t) {
			if(t.responseText=='ok') {
				processing(0);
			} else {
				alert('The URL you entered doesn\'t work! Try again.');
				$('screen2').hide();
				$('screen1').style.display='block';
			}; 
		}, 
		onFailure:function(t){
			alert('Oops! My server isn\'t working for some reason! Error - ' + t.status + ' -- ' + t.statusText);
			$('screen2').hide();
			$('screen1').style.display='block';
		}
		});
	
}

function processing(this_step){
	var messages = [
		'Counting exclamation marks in posts...',
		'Looking for mentions of MySpace...',
		'Analyzing buzzword usage...',
		'Running spell-check...',
		'Reluctantly performing full semantic analysis...',
		'Compiling the report...'
	];
	
	element = Builder.node('p',{className:'log_message'}, messages[this_step]);
	$('progress_log').appendChild(element);
	
	if (this_step >= messages.length-1) {
		new Ajax.Request('connect.php', {parameters:'action=get_report&url='+escape(blog_url), 
		onSuccess:function(t) {
			element = Builder.node('p',{className:'log_message'}, 'Done!');
			$('progress_log').appendChild(element);
			$('progress_desc').style.display='none';
			$('progress_done').style.display='block';
			$('report').innerHTML=t.responseText;
		}, 
		onFailure:function(t){
			alert('Oops! My server isn\'t working for some reason! Error - ' + t.status + ' -- ' + t.statusText);
			$('screen2').hide();
			$('screen1').style.display='block';
		}
		});
		
	} else {
		this_step++;
		window.setTimeout('processing('+this_step+')',2000);
	}
}

function show_report(){
	new Effect.Fade('screen2', {duration: 0.3}); 
	window.setTimeout("$('screen3').style.display='block';",500);
}

function final_page(){
	new Effect.Fade('screen3', {duration: 0.3}); 
	window.setTimeout("$('screen4').style.display='block';",500);
}