function animate_run() {
	animate_reset();
	animate_slideTextIn($("#text1"), 451, function () {
		setTimeout(function () {
			animate_swapBackground($("#slide1"), $("#slide2"), $("#flash"), function () {});
			animate_slideTextOut($("#text1"), 900, function () {
				animate_slideTextIn($("#text2").show(), 451, function () {
					setTimeout(function () {
						animate_swapBackground($("#slide2"), $("#slide3"), $("#flash"), function () {});
						animate_slideTextOut($("#text2"), 900, function () {
							animate_slideTextIn($("#text3").show(), 322, function () {
								setTimeout(function () {
									animate_swapBackground($("#slide3"), $("#slide4"), $("#flash"), function () {});
									/*animate_slideTextOut($("#text3"), 900, function () {
										animate_slideTextIn($("#text4").show(), 362, function () {
											setTimeout(function () {
												// end
											}, 2500);
										});
									});*/
								//}, 2500);
								}, 500);
							});
						});
					}, 2500);
				});
			});
		}, 2500);
	});
}

function animate_reset() {
	$(".topbg").hide();
	$(".toptext").hide();
	$("#text1").css('left','900px').css('top','30px'); // 451
	$("#text2").css('left','900px').css('top','30px'); // 451
	$("#text3").css('left','900px').css('top','10px'); // 451
	//$("#text4").css('left','900px').css('top','5px'); // 362
	$("#slide1,#text1").show();
}

function animate_slideTextIn(element, left, callback) {
	element.animate({
		left: '-='+((900-left)+20)
	}, 500, function () {
		element.animate({
			left: '+=20'
		}, 100, callback);
	});
}

function animate_slideTextOut(element, left, callback) {
	element.animate({
		left: '-=20'
	}, 100, function () {
		element.animate({
			left: '+='+(20+left)
		}, 600, callback);
	});
}

function animate_swapBackground(oldBg, newBg, flash, callback) {
	flash.fadeIn(250, function () {
		oldBg.hide();
		newBg.show();
		flash.fadeOut(250, callback);
	});
}

$(document).ready(function () {
	animate_reset();
	
});

$(window).load(function () {
	animate_run();
});
