// -------------------------------------------------------------------------
// JSON representation of the entire site
// 
// Using this to build/test frontend of the site until the CMS is integrated.
// -------------------------------------------------------------------------
GYRO.SiteData = {
	"dir": "/",
	"content": {
		"backgrounds": [
			"/images/backgrounds/001.jpg",
			"/images/backgrounds/002.jpg",
			"/images/backgrounds/003.jpg",
			"/images/backgrounds/004.jpg",
			"/images/backgrounds/005.jpg",
			"/images/backgrounds/006.jpg",
			"/images/backgrounds/007.jpg",
			"/images/backgrounds/008.jpg",
			"/images/backgrounds/009.jpg",
			"/images/backgrounds/010.jpg",
			"/images/backgrounds/011.jpg",
			"/images/backgrounds/012.jpg",
			"/images/backgrounds/013.jpg",
			"/images/backgrounds/014.jpg",
			"/images/backgrounds/015.jpg",
			"/images/backgrounds/016.jpg",
			"/images/backgrounds/017.jpg",
			"/images/backgrounds/018.jpg",
			"/images/backgrounds/019.jpg",
			"/images/backgrounds/020.jpg",
			"/images/backgrounds/021.jpg",
			"/images/backgrounds/022.jpg",
			"/images/backgrounds/023.jpg"
		],
		"autoplay": true
	},
	"sections": [
		{
			"label": "Showcase",
			"dir": "/showcase/",
			"content": {
				"backgrounds": [
					"/images/work1.jpg", 
					"/images/work2.jpg", 
					"/images/work3.jpg", 
					"/images/work4.jpg"
				],
				"autoplay": true,
				"galleryNav": false,
				"header": "Showcase",
				"copy": "Our best work from the & last few years hand-picked for your pleasure.",
				"list": [
					{
						"label": "Clek",
						"dir": "/showcase/clek/",
						"content": {
							"backgrounds": [
								"/images/casestudy.jpg", 
								"/images/casestudy1.jpg", 
								"/images/casestudy2.jpg", 
								"/images/casestudy3.jpg", 
								"/images/casestudy4.jpg"
							],
							"captions": [
								"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
								"", 
								"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.", 
								"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
								"Sunt in culpa qui officia deserunt mollit anim id est laborum excepteur sint occaecat cupidatat non proident."
							],
							"autoplay": false,
							"galleryNav": true,
							"header": "Clek & Stuff",
							"copy": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
						}
					},
					{
						"label": "DaimlerChrysler",
						"dir": "/showcase/daimlerchrysler/",
						"content": {
							"backgrounds": [
								"/images/casestudy2.jpg", 
								"/images/casestudy4.jpg",
								"/images/casestudy3.jpg", 
								"/images/casestudy1.jpg" 
							],
							"captions": [
								{ "p": "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." },
								{ "p": "Sunt in culpa qui officia deserunt mollit anim id est laborum excepteur sint occaecat cupidatat non proident." },
								{ "p": "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur." }, 
								{ "p": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." }
							],
							"autoplay": false,
							"galleryNav": true,
							"header": "DaimlerChrysler",
							"copy": "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
						}
					}
				]
			}
		},
		{
			"label": "Clients",
			"dir": "/clients/",
			"content": {
				"backgrounds": [
					"/images/general-bg-00.jpg", 
					"/images/general-bg-01.jpg", 
					"/images/general-bg-02.jpg"
				],
				"autoplay": true,
				"galleryNav": false,
				"header": "Clients",
				"copy": "As a business celebrating over 10 years in Detroit, we bring a wealth of experience working with both private companies and public agencies in the city.",
				"list": [
					{ "label": "ABN AMRO"},
					{ "label": "Akebono"},
					{ "label": "ArvinMeritor"},
					{ "label": "ATX Group"},
					{ "label": "Avalon"},
					{ "label": "International Breads"},
					{ "label": "BBDO"},
					{ "label": "Blue Water Automotive Systems"},
					{ "label": "Campbell-Ewald"},
					{ "label": "Clek Inc"},
					{ "label": "Comerica Bank"},
					{ "label": "Cranbrook Institute of Science"},
					{ "label": "Crypton"},
					{ "label": "DaimlerChrysler"},
					{ "label": "Detroit Artists Market"},
					{ "label": "Detroit Historical Museum"},
					{ "label": "Detroit Institute of Arts"},
					{ "label": "Detroit Lions"},
					{ "label": "Detroit Public Television"},
					{ "label": "Detroit Science Center"},
					{ "label": "Detroit Zoological Institute"},
					{ "label": "Dow Automotive"},
					{ "label": "Ford Field"},
					{ "label": "General Motors"},
					{ "label": "Henry Ford Museum + Greenfield Village"},
					{ "label": "Lola&rsquo;s"},
					{ "label": "Magna Aftermarket"},
					{ "label": "Magna International"},
					{ "label": "Masco Corporation"},
					{ "label": "Mercedes-Benz USA"},
					{ "label": "Michigan Opera Theatre"},
					{ "label": "Motown Museum"},
					{ "label": "Museum of Contemporary Art Detroit"},
					{ "label": "Next Energy"},
					{ "label": "Paxahau Entertainment"},
					{ "label": "Pentamark"},
					{ "label": "Plowshares Theatre Company"},
					{ "label": "Resistance Wear"},
					{ "label": "Solutia"},
					{ "label": "Somerset Collection"},
					{ "label": "Sportstat"},
					{ "label": "Triangle Foundation"},
					{ "label": "Tower Automotive"},
					{ "label": "Toyoda Gosei Automotive"},
					{ "label": "Tropical Squeeze Franchise"},
					{ "label": "Volkswagen North America"},
					{ "label": "Wayne County Edge"},
					{ "label": "Wayne RESA"},
					{ "label": "Wayne State University"}
				]
			}
		},
		{	
			"label": "Contact",
			"dir": "/contact/",
			"content": {
				"backgrounds": [
					"/images/general-bg-00.jpg", 
					"/images/general-bg-01.jpg", 
					"/images/general-bg-02.jpg"
				],
				"autoplay": true,
				"galleryNav": false,
				"header": "Contact",
				"hcard": {
					"fn": "Gyro Creative Group",
					"email": "info@gyrocreative.com",
					"tel": [
						{
							"type": "main",
							"value": "313 964 0100"
						},
						{
							"type": "fax",
							"value": "313 964 0101"
						}
					],
					"adr": {
						"street-address": "400 Grand River Ave. Suite 200",
						"locality": "Detroit",
						"region": "Michigan",
						"postal-code": "48226"
					}
				}
			}
		}
	]
};

GYRO.NotFoundData = {
	"content": {
		"backgrounds": [
			"/images/general-bg-00.jpg", 
			"/images/general-bg-01.jpg", 
			"/images/general-bg-02.jpg"
		],
		"autoplay": true,
		"galleryNav": false,
		"header": "404 Not Found",
		"copy": "The page you have requested does not exist. Please check the URL and try again."
	}
};

// ---------------------------------------------------------
// !GYRO.getSiteData()
//
// get the entire site data - rewrite for AJAX
// ---------------------------------------------------------
GYRO.getSiteData = function() {

	// just return the data inline for now
	// later on this may be gotten via AJAX
	return GYRO.SiteData;
};


// ---------------------------------------------------------
// !GYRO.getPageData()
//
// get the page data based on url directory input
// ---------------------------------------------------------
GYRO.getPageData = function(urlDir) {

	// remove any / from front and end
	urlDir = GYRO.trimChar(urlDir, "/");	
	var urlSegments = urlDir.split("/");
	
	var sectionData = undefined;
	var undefindedData = undefined;
	var pageData = undefined;
	var data = undefined;
	
	var siteData = GYRO.getSiteData();
	
	// if section in url
	if (urlSegments[0] !== undefined && urlSegments[0] !== "") {

		var sectionDir = "/" + urlSegments[0] + "/";

		var numberOfSections = siteData.sections.length;
		for (var sectionIndex = 0; sectionIndex < numberOfSections; sectionIndex++) {
		
			if (siteData.sections[sectionIndex].dir === sectionDir) {
				sectionData = GYRO.SiteData.sections[sectionIndex];
			}
		}
		
		// if page in url
		if (sectionData && urlSegments[1] !== undefined) {

			var pageDir = sectionDir + urlSegments[1] + "/";

			var numberOfListItems = sectionData.content.list.length
			for (var pageIndex = 0; pageIndex < numberOfListItems; pageIndex++) {
			
				if (sectionData.content.list[pageIndex].dir === pageDir) {
					pageData = sectionData.content.list[pageIndex];
					break;
				}
			}

			data = pageData;
		
		// else just section
		} else {		
			data = sectionData;
		}
	
	// else we're home
	} else {
		data = siteData; 
	}

	// if data is found then return it, if not return undefined data	
	if (data) {
		return data;	
	} else {
		return GYRO.NotFoundData;
	}
			
};


GYRO.trimChar = function(stringToTrim, charToTrim) {

	// split stringToTrim with charToTrim
	var stringSegments = stringToTrim.split(charToTrim);
	
	var newString = "";
	
	// concat non-empty string with charToTrim in between
	var numberOfSegments = stringSegments.length; 
	for (var i = 0; i < numberOfSegments; i++) {	
		if (stringSegments[i] !== "") {
			newString = newString + charToTrim + stringSegments[i];
		}
	}
	
	// return without first char (excess charToTrim) from new string 
	return newString.substring(1);
};





