var zero_count = 0;

function wipe() {
	// alert('still wiping');
	var current_count = 0;
	var new_count = 0;
	$.getJSON('http://twitwipe.aalaap.com/wipe.php?jsoncallback=?', function(data) {
		if (data.error) {
			done("Error: "+data.error);
		} else {
			current_count = parseInt($('#count').html());
			new_count = current_count + data.deleted;
			$("#count").fadeOut('slow').html(new_count).fadeIn('slow');
			if (zero_count==5) {
				// it's done
			} else if (data.deleted==0) {
				zero_count++;
			}
		}
	});
}

function done(msg) {
	if (typeof msg == "undefined") {
		msg = 'All tweets deleted! Done!';
	}

	// stop
	// window.clearInterval(intervalId);
	
	if (typeof intervalId == "undefined" ) {
		// alert("intervalId is not defined??");
	} else {
		window.clearInterval(intervalId);
		// alert("intervalId has been cleared");
	}

	// alert(typeof intervalId);

	reset_start();

	$("#status").fadeOut('slow').html(msg).fadeIn('slow');
}

function reset_start() {
	$("#start").fadeOut('slow').html('<a href="#" id="wipe">Start Wiping</a>').fadeIn('slow');
}

$(document).ready(function() {
	reset_start();

	$("#wipe").click(function() {
		if (typeof intervalId == "undefined" ) {
			
			$("#start").fadeOut('slow').html('Started! <span id="stop"><a href="#" id="stopit">STOP IT!</a></span>').fadeIn('slow');

			$("#status").html('Number of tweets deleted: <span id="count">0</span>');
			var intervalId = window.setInterval("wipe()", 60000);

			$("#stopit").click(function() {
				done('Stopped!');
			});

		}
	});

	
	$('#wipe').confirm({
		msg: 'ARE YOU SURE??? ',
		buttons: {
			ok: 'YEAAAAHHHHHH!!!',
			cancel: 'NOOOOOOO!!!!!!',
			separator: ' or '
		}
	});
	
	// was ok = fuck yeah, cancel = 'shit no'
	
	ass();
	
});

function ass() {
	$('.fuck').html('hell');
	$('.fucking').html('bloody');
	$('.asshole').html('ass');
	$('.retarded').html('lame');
}

function asshole() {
	$('.fuck').html('fuck');
	$('.fucking').html('fucking');
	$('.asshole').html('asshole');
	$('.retarded').html('lame');
}
