$(document).ready(function(){
	$('#right_col').hide();
	frontFadeInit();
	cur_win = "#first";
	$('#second').hide();
	$('#third').hide();
	$('#first_tx').hide();
	$("a").click(function(event) {
		switch(event.target.id) {
			case "bio" :
				switch(cur_win) {
					case "#third" :
						$(cur_win).fadeOut("slow", function () {
							$('#third').html('');
							$('#first').fadeIn("fast", function() {
								$('#first_tx').fadeIn();
							});
						});
					break;
					case "#first" :
						$('#first_tx').fadeIn();
					break;
				}
				cur_win = "#first_tx";
				event.preventDefault();
			break;
			case "clip1" :
				switch(cur_win) {
					case "#first_tx" :
						$('#first').fadeOut();
						$(cur_win).fadeOut("slow", function () {
							$('#third').fadeIn("slow", function () {
								$('#third').flash({
									swf: 'vid/roth_vid1.swf', height: 500, width: 649
								});
							});
						});
						cur_win="#third";
						event.preventDefault();
					break;
					case "#first" :
						$(cur_win).fadeOut("slow", function () {
							$('#third').fadeIn("slow", function () {
								$('#third').flash({
									swf: 'vid/roth_vid1.swf', height: 500, width: 649
								});
							});
						});
						cur_win="#third";
						event.preventDefault();					
					break;
					case "#third" :
						$('#third').html('');
						$('#third').flash({
							swf: 'vid/roth_vid1.swf', height: 500, width: 649
						});
						event.preventDefault();	
					break;
				}
			break;
			case "clip2" :
				switch(cur_win) {
					case "#third" :
						$('#third').html('');
						$('#third').flash({
							swf: 'vid/roth_rescue_outro.swf', height: 420, width: 649
						});
					break;
					case "#first" :
						$(cur_win).fadeOut("slow", function () {
							$('#third').fadeIn("slow", function () {
								$('#third').flash({
									swf: 'vid/roth_rescue_outro.swf', height: 420, width: 649
								});
							});
						});
						cur_win="#third";
						event.preventDefault();					
					break;
					case "#first_tx" :
						$('#first').fadeOut();
						$(cur_win).fadeOut("slow", function () {
							$('#third').fadeIn("slow", function () {
								$('#third').flash({
									swf: 'vid/roth_rescue_outro.swf', height: 420, width: 649
								});
							});
						});
						cur_win="#third";
						event.preventDefault();
					break;
				}
				cur_win="#third";
				event.preventDefault();		
			break;
		}
	});
});

function frontFadeInit() {
	$('#right_col').html('').hide();
	img = new Image();
	$(img).load(function() {
		$('#right_col').append(this);
		$('#right_col').fadeIn();
		queue.push(this);
		cnt = 0;
	})
	.attr('src', 'img/'+fimgs[0]);
	preloadStart();
}
function preloadStart() {
	for(var i=1;i<fimgs.length;i++) {
		mg = new Image();
		$(mg).load(function() {
			queue.push(this);
		})
		.attr('src', 'img/'+fimgs[i]);
	}
	window.setInterval(function(){fadeImg();},11000);
}
function fadeImg() {
	if(cnt >= fimgs.length) {
		cnt = 0;
	}
	$('#right_col').fadeOut("slow", function() { 	
		$('#right_col').html('');
		$('#right_col').append(queue[cnt]);
		$('#right_col').fadeIn();
		cnt++;
	});
}


var cnt;
var queue = new Array();
var fimgs = ["adam_stage_red.jpg", "Adam_rescue_2.jpg"];
