/* Foundation v2.1.1 http://foundation.zurb.com */
function persist (key, value) {
	if ((typeof value !== "undefined") && (typeof window.localStorage !== "undefined")) {
		try {
			window.localStorage[key] = value;
		} catch (e) {
		}
	} else if (typeof window.localStorage !== "undefined") {
		try {
			return window.localStorage[key];
		} catch (e) { 
			return null;
		}
	}
}
$(document).ready(function() {
	/* BINDS -------------------------------- */
	var firstRun = persist("firstrun");
	if (typeof firstRun === "undefined"){
		$("#welcomeSplash").show();
		$("#welcomeBackground").show();
		persist("firstrun", "false");
	}
	$("#welcomeSplash").bind("tap click", function(e){
		$("#welcomeSplash").hide();
		$("#welcomeBackground").hide();
	});
	$("#welcomeImage").bind("tap click", function(e){
		$("#welcomeSplash").hide();
		$("#welcomeBackground").hide();
	});
	
	var restorationToggle = 1;
	$("#restorationLink").bind("tap click", function(e){
		if (restorationToggle === 1){
			$("#restoration1").hide();
			$("#restoration2").show();
			$("#restorationLink").html("<center>Click here to see the rejuvenation of a 19th century sideboard.</center>");
			$("#restorationHeader").html("Art Deco Desk ca 1929");
			restorationToggle = 2;
		} else {
			$("#restoration2").hide();
			$("#restoration1").show();
			$("#restorationLink").html("<center>Click here to walk through the restoration of a valuable Art Deco desk circa 1929.</center>");
			$("#restorationHeader").html("19th Century Sideboard")
			restorationToggle = 1;
		}
		e.preventDefault();
		e.stopPropagation();
	});
	$("#cabinetsLink").bind("tap click", function(e){
		$("#desks").hide();
		$("#ecclesiastical").hide();
		$("#tables").hide();
		$("#walls").hide();
		$("#cabinets").show();
		e.preventDefault();
		e.stopPropagation();
	});
	$("#desksLink").bind("tap click", function(e){
		$("#cabinets").hide();
		$("#ecclesiastical").hide();
		$("#tables").hide();
		$("#walls").hide();
		$("#desks").show();
		e.preventDefault();
		e.stopPropagation();
	});
	$("#ecclesiasticalLink").bind("tap click", function(e){
		$("#desks").hide();
		$("#cabinets").hide();
		$("#tables").hide();
		$("#walls").hide();
		$("#ecclesiastical").show();
		e.preventDefault();
		e.stopPropagation();
	});
	$("#tablesLink").bind("tap click", function(e){
		$("#desks").hide();
		$("#ecclesiastical").hide();
		$("#cabinets").hide();
		$("#walls").hide();
		$("#tables").show();
		e.preventDefault();
		e.stopPropagation();
	});
	$("#wallsLink").bind("tap click", function(e){
		$("#desks").hide();
		$("#ecclesiastical").hide();
		$("#tables").hide();
		$("#cabinets").hide();
		$("#walls").show();
		e.preventDefault();
		e.stopPropagation();
	});
	/* TABS --------------------------------- */
	var tabs = $('dl.tabs');
		tabsContent = $('ul.tabs-content')
	tabs.each(function(i) {
		//Get all tabs
		var tab = $(this).children('dd').children('a');
		tab.click(function(e) {
			//Get Location of tab's content
			var contentLocation = $(this).attr("href")
			contentLocation = contentLocation + "Tab";
			//Let go if not a hashed one
			if(contentLocation.charAt(0)=="#") {
				e.preventDefault();
				//Make Tab Active
				tab.removeClass('active');
				$(this).addClass('active');
				//Show Tab Content
				$(contentLocation).parent('.tabs-content').children('li').css({"display":"none"});
				$(contentLocation).css({"display":"block"});
			}
		});
	});
});

