var currentLoadImage1 = 0;
var currentLoadImage2 = 30;
var currentLoadImage3 = 60;
var currentLoadImage4 = 90;
var currentLoadImage5 = 120;
var currentLoadImage6 = 150;
var currentLoadImage7 = 180;
var currentLoadImage8 = 210;
var currentLoadImage9 = 240;
var currentLoadImage10 = 270;
var currentLoadImage11 = 300;

$(document).ready(function(){
	setTimeout("appendTweet()",800);
	loadImage1();
	loadImage2();
	loadImage3();
	loadImage4();
	loadImage5();
	loadImage6();
	loadImage7();
	loadImage8();
	loadImage9();
	loadImage10();
	loadImage11();
});

function appendTweet(){
	$.get("php/censor_tweet.php?" + new Date().getTime(), function(data){
		if(tweetCount < MAX_TWEETS){
			$("#tweetDiv").append(" " + data + " ");
			tweetCount++;
			setTimeout("appendTweet()",800);
		}
	});
}

function loadImage1(){
	var img = new Image();
	$(img).load(function () {
		$(this).hide();
		$('#imgDiv' + currentLoadImage1).append(this);
		$(this).fadeIn("fast");
		currentLoadImage1++;
		if(currentLoadImage1 != 30)
			setTimeout("loadImage1();",1);
	}).error(function () {
		alert("err1");
	}).attr('src', imageLocations[currentLoadImage1]).css('height','25px').css('width','25px').css('display','inline');
}

function loadImage2(){
	var img = new Image();
	$(img).load(function () {
		$(this).hide();
		$('#imgDiv' + currentLoadImage2).append(this);
		$(this).fadeIn("fast");
		currentLoadImage2++;
		if(currentLoadImage2 != 60)
			setTimeout("loadImage2();",1);
	}).error(function () {
		alert("err2");
	}).attr('src', imageLocations[currentLoadImage2]).css('height','25px').css('width','25px').css('display','inline');
}

function loadImage3(){
	var img = new Image();
	$(img).load(function () {
		$(this).hide();
		$('#imgDiv' + currentLoadImage3).append(this);
		$(this).fadeIn("fast");
		currentLoadImage3++;
		if(currentLoadImage3 != 90)
			setTimeout("loadImage3();",1);
	}).error(function () {
		alert("err3");
	}).attr('src', imageLocations[currentLoadImage3]).css('height','25px').css('width','25px').css('display','inline');
}

function loadImage4(){
	var img = new Image();
	$(img).load(function () {
		$(this).hide();
		$('#imgDiv' + currentLoadImage4).append(this);
		$(this).fadeIn("fast");
		currentLoadImage4++;
		if(currentLoadImage4 != 120)
			setTimeout("loadImage4();",1);
	}).error(function () {
		alert("err4");
	}).attr('src', imageLocations[currentLoadImage4]).css('height','25px').css('width','25px').css('display','inline');
}

function loadImage5(){
	var img = new Image();
	$(img).load(function () {
		$(this).hide();
		$('#imgDiv' + currentLoadImage5).append(this);
		$(this).fadeIn("fast");
		currentLoadImage5++;
		if(currentLoadImage5 != 150)
			setTimeout("loadImage5();",1);
	}).error(function () {
		alert("err5");
	}).attr('src', imageLocations[currentLoadImage5]).css('height','25px').css('width','25px').css('display','inline');
}

function loadImage6(){
	var img = new Image();
	$(img).load(function () {
		$(this).hide();
		$('#imgDiv' + currentLoadImage6).append(this);
		$(this).fadeIn("fast");
		currentLoadImage6++;
		if(currentLoadImage6 != 180)
			setTimeout("loadImage6();",1);
	}).error(function () {
		alert("err6");
	}).attr('src', imageLocations[currentLoadImage6]).css('height','25px').css('width','25px').css('display','inline');
}

function loadImage7(){
	var img = new Image();
	$(img).load(function () {
		$(this).hide();
		$('#imgDiv' + currentLoadImage7).append(this);
		$(this).fadeIn("fast");
		currentLoadImage7++;
		if(currentLoadImage7 != 210)
			setTimeout("loadImage7();",1);
	}).error(function () {
		alert("err7");
	}).attr('src', imageLocations[currentLoadImage7]).css('height','25px').css('width','25px').css('display','inline');
}

function loadImage8(){
	var img = new Image();
	$(img).load(function () {
		$(this).hide();
		$('#imgDiv' + currentLoadImage8).append(this);
		$(this).fadeIn("fast");
		currentLoadImage8++;
		if(currentLoadImage8 != 240)
			setTimeout("loadImage8();",1);
	}).error(function () {
		alert("err8");
	}).attr('src', imageLocations[currentLoadImage8]).css('height','25px').css('width','25px').css('display','inline');
}

function loadImage9(){
	var img = new Image();
	$(img).load(function () {
		$(this).hide();
		$('#imgDiv' + currentLoadImage9).append(this);
		$(this).fadeIn("fast");
		currentLoadImage9++;
		if(currentLoadImage9 != 270)
			setTimeout("loadImage9();",1);
	}).error(function () {
		alert("err9");
	}).attr('src', imageLocations[currentLoadImage9]).css('height','25px').css('width','25px').css('display','inline');
}

function loadImage10(){
	var img = new Image();
	$(img).load(function () {
		$(this).hide();
		$('#imgDiv' + currentLoadImage10).append(this);
		$(this).fadeIn("fast");
		currentLoadImage10++;
		if(currentLoadImage10 != 300)
			setTimeout("loadImage10();",1);
	}).error(function () {
		alert("err10");
	}).attr('src', imageLocations[currentLoadImage10]).css('height','25px').css('width','25px').css('display','inline');
}

function loadImage11(){
	var img = new Image();
	$(img).load(function () {
		$(this).hide();
		$('#imgDiv' + currentLoadImage11).append(this);
		$(this).fadeIn("fast");
		currentLoadImage11++;
		if(currentLoadImage11 != 324)
			setTimeout("loadImage11();",1);
	}).error(function () {
		alert("err11");
	}).attr('src', imageLocations[currentLoadImage11]).css('height','25px').css('width','25px').css('display','inline');
}

function submitWorkURL(){
	if(isValidURL("http://" + $("#work_url").val())){
		var workURL = $("#work_url").val();
		//	load the ajax loading image
		alert("http://" + escape(workURL));
		
		$("#submitWorkURLDiv").empty();
		$("#submitWorkURLDiv").load("php/saveWorkURL.php",{ 'work_url' : "http://" + escape(workURL)});
	}else{
		$("#URLErrorSpan").html("'http://" + $("#work_url").val() + "' is not a valid url!");
	}
}

function isValidURL(url){
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
} 