var headerHeight;
var flashFooterHeight;
var flashFooterHeightOrig;
var flashHeight;
var flashWidth;
var player;
var playlist = null;
function playerReady(obj) {
	player = document.getElementById(obj['id']);
	addListeners();
};
function addListeners() {
	playlist = player.getPlaylist();
	if(playlist.length > 0) {
		player.addModelListener('STATE', 'stateMonitor');
	}
	else {
		setTimeout("addListeners();", 100);
	}
}
var previousState;
var currentState;
function stateMonitor(obj) {
	previousState = obj.oldstate;
	currentState = obj.newstate;
	if ((previousState != currentState) && (currentState == "COMPLETED")) {
		skipVideo();		
	}
}
function hideVideo() {
	if(player) {player.sendEvent("PLAY", "false");}
	$("#flashFooter").slideToggle("slow", function() {
		$("#flash").slideToggle("slow", function() {
			$("#banner").slideToggle("slow", function() {
				$("#page").slideToggle("slow", function() {
					$("#footer").slideToggle("slow");
				});
			});
		});
	});
}
function showVideo() {
	$("#footer").slideToggle("fast", function() {
		$("#page").slideToggle("slow", function() {
			$("#banner").slideToggle("slow", function() {
				$("#flash").slideToggle("slow", function() {
					$("#flashFooter").slideToggle("slow", function() {
						//player.sendEvent("ITEM", "0");
						//player.sendEvent("PLAY", "true");
					});
				});
			});
		});
	});
}
function skipVideo() {
	if(player) {player.sendEvent("PLAY", "false");}
	$(".gridsFlash").slideToggle("slow", function() {
		$(".grids").slideToggle("slow", function() {
			$("#page").slideToggle("slow", function() {
				$("#footer").slideToggle("slow");
			});
		});
	});
}
function showVideoSmall() {
	$("#footer").slideToggle("fast", function() {
		$("#page").slideToggle("slow", function() {
			$(".grids").slideToggle("slow", function() {
				$(".gridsFlash").slideToggle("slow", function() {
					//player.sendEvent("ITEM", "0");
					//player.sendEvent("PLAY", "true");
				});
			});
		});
	});
}
function skipVideoAlt() {
	if(player) {player.sendEvent("PLAY", "false");}
	$(".gridsFlash").slideToggle("slow", function() {
		$(".grids").fadeIn("slow", function() {
			$("#page").fadeIn("slow", function() {
				$("#footer").fadeIn("slow");
			});
		});
	});
}
function showVideoSmallAlt() {
	$("#footer").fadeOut("fast", function() {
		$("#page").fadeOut("slow", function() {
			$(".grids").fadeOut("slow", function() {
				$(".gridsFlash").slideToggle("slow", function() {
					//player.sendEvent("ITEM", "0");
					//player.sendEvent("PLAY", "true");
				});
			});
		});
	});
}
function skipVideoAltAgain() {
	if(player) {player.sendEvent("PLAY", "false");}
	$(".gridsFlash").animate({width: 'toggle'}, 'slow', function() {
		$(".grids").animate({width: 'toggle'}, 'slow', function() {
			$("#page").slideToggle("slow", function() {
				$("#footer").slideToggle("slow");
			});
		});
	});
}
function showVideoSmallAltAgain() {
	$("#footer").slideToggle("fast", function() {
		$("#page").slideToggle("slow", function() {
			$(".grids").animate({width: 'toggle'}, 'slow', function() {
				$(".gridsFlash").animate({width: 'toggle'}, 'slow', function() {
					//player.sendEvent("ITEM", "0");
					//player.sendEvent("PLAY", "true");
				});
			});
		});
	});
}
function resizeVideo() {
	var vidOrigWidth = 1280;
	var vidOrigHeight = 720;
	var vidOrigRatio = vidOrigWidth/vidOrigHeight;

	headerHeight = $("#header").outerHeight();
	flashFooterHeight = $("#flashFooter").outerHeight();
	var flashFooterBorder = flashFooterHeight - $("#flashFooter").innerHeight();
	flashHeight = $(window).height() - headerHeight - flashFooterHeight;
	flashWidth = $(window).width();

	if (flashWidth < vidOrigWidth) {
		flashHeight = Math.floor(flashWidth/vidOrigRatio);
		var maxFlashHeight = $(window).height() - headerHeight - flashFooterHeightOrig;
		if (flashHeight > maxFlashHeight) {
			flashHeight = maxFlashHeight;
		}
		flashFooterHeight = $(window).height() - headerHeight - flashHeight - flashFooterBorder;
		$("#flashFooter").css("height", flashFooterHeight+"px");
		$("#flash").css("height", flashHeight+"px");
	}
	else {
		flashFooterHeight = flashFooterHeightOrig - flashFooterBorder;
		$("#flashFooter").css("height", flashFooterHeight+"px");
		flashFooterHeight = $("#flashFooter").outerHeight();
		flashHeight = $(window).height() - headerHeight - flashFooterHeight;
		$("#flash").css("height", flashHeight+"px");
	}
}
