// JavaScript Document

$(document).ready(function() {
	
	//var headerBG = $("#header").css("background-color");
	
	//var pages = new Array("tellers","prime","h2o","verace","beachtree");
	var pages = new Array();
	function buildPageArray() {
		for (i = 1; i <= $("#more>ul>li>a").length; i++) {
			pages.push($("#more>ul>li:nth-child("+i+")>a").attr("id").split("_")[1]);
		}
	}
	buildPageArray();
	
	$("#more").click(function () {
		$("#more>ul").slideToggle(300);
		return false;
	});
	
	$("#homeB").click(function () {
		if (!$("#home").is(":visible")) {
			for (i = 0; i < pages.length; i++) {
				if ($("#"+pages[i]).is(":visible")) {
					$("#"+pages[i]).hide("slide", { direction: "right", distance: $("#container").width() }, 300);
				}
			}
			$("#home").show("slide", { direction: "left", distance: $("#container").width() }, 300);
			//$("#header").animate( { backgroundColor: headerBG }, 1000)
			//$("#nav").animate( { backgroundColor: headerBG }, 1000)
		}
		if ($("#more>ul").is(":visible")) {
			$("#more>ul").slideToggle(300);
		}
		return false;
	});
	
	$("#more>ul>li>a").click(function () {
		if ($("#home").is(':visible')) {
			$("#home").hide("slide", { direction: "left", distance: $("#container").width() }, 300);
		}
		var thePage = $(this).attr("id").split("_")[1];
		if (!$("#"+thePage).is(":visible") ) {
			for (i = 0; i < pages.length; i++) {
				if ($("#"+pages[i]).is(":visible")) {
					$("#"+pages[i]).hide("slide", { direction: "left", distance: $("#container").width() }, 300);
				}
			}
			$("#"+thePage).show("slide", { direction: "right", distance: $("#container").width() }, 300);
			//$("#header").animate( { backgroundColor: $("#"+thePage+">h2").css("background-color") }, 1000)
			//$("#nav").animate( { backgroundColor: $("#"+thePage+">h2").css("background-color") }, 1000)
		}
		//$("#tellers").show("slide", { direction: "right", distance: $("#container").width() }, 300);
		$("#more>ul").slideToggle(300);//,sncc(thePage));
		return false;
	});
	
	function sncc(thePage) {
		$("#nav>ul>li>ul").css("background-color", $("#"+thePage+">h2").css("background-color"))
	}
	
	/*$('a[href=#top]').click(function(){
        $('html').animate({scrollTop:0}, 300);
        return false;
    });*/
	
	$("#app").click(function () {
		$("#instructions").slideToggle(300);
		return false;
	});
	
});

// Hide the iPhone toolbars by scrolling 1px
window.addEventListener('load', function() {
	setTimeout(scrollTo, 0, 0, 1);
}, false);
