$(function() {
	
	/* VIEW: INDEX.ERB */
	
	//Enable form if JS 
	//$("form.remote").show();
	
	// Enable form ajax
	$("form.remote").livequery(function(){
		$("form.remote").ajaxForm(function(html) {
			$("div#magicBox").html(html);
		});
	});
	
	// Launch the spy if #status object is detected
	$('#status').livequery(function(){ 
		$('#status > div:gt(4)').fadeEachDown();
		$('#status').spy({
			'ajax': $("form#manual_check").attr('action'),
		 	'fadeInSpeed': '500', // crawl
			'push': custom_push,
			'timeout': 5000
		});
	});
	
	function custom_push(response) {
		$('#status').html(response);
	}
	
	// Pause the Spy if an element with id="completed" shows up
	$('a#completed').livequery(function(){
		if($('#status').length>0) {
			pauseSpy();
		};
	});
	// Pause the Spy if an element with id="failed" shows up
	$('p#failed').livequery(function(){
		if($('#status').length>0) {
			pauseSpy();
		};
	});
	
	// after ajax Cufonization
	$('#magicBox h2').livequery(function(){ Cufon.replace('#magicBox h2'); });
	$('#magicBox h3').livequery(function(){	Cufon.replace('#magicBox h3'); });
});