﻿$(document).ready(function() {
	$.preloadCssImages();

	if ($.browser.msie) {
		$(document).pngFix();
	} else {
		start();
	}
});

function start() {
	$("#content, .screen, .textbox, .location, .city, .address").hide();

	$(".location").css("height", "116px");
	
	clear();
	queue(function() {
		if ($("#content").length) {
			$("#content").fadeIn("slow", function() {
				advance();
			});
		} else {
			advance();
		}
	});

	queue(function() {
		if ($(".screen").length) {
			$(".screen").fadeIn("normal", function() {
				advance();
			});
		} else {
			advance();
		}
	});
	
	queue(function() {
		if ($(".textbox").length) {
			$(".textbox").fadeIn("normal", function() {
				advance();
			});
		} else {
			advance();
		}
	});

	queue(function() {
		if ($(".location").length) {
			$(".location").show("normal", function() {
				advance();
			});
		} else {
			advance();
		}
	});
	
	queue(function() {
		if ($(".city").length) {
			$(".city").slideDown("normal", function() {
				advance();
			});
		} else {
			advance();
		}
	});
	
	queue(function() {
		if ($(".address").length) {
			$(".address").fadeIn("normal", function() {
			$(".location").css("height", "auto");
				advance();
			});
		} else {
			advance();
		}
	});

	advance();
}

var q = [];

function queue() {
	for (var i = 0; i < arguments.length; i++)
		q.push(arguments[i]);
}

function advance() {
	if (q.length == 0) return; //check that we have something in the queue
	q.shift()(); // the same as var func = q.shift(); func();
}

function clear() {
	q = [];
}
