var totalCols = 3;
var totalRows = 3;
var photoContainerDiv = null;
var storyContainerDiv = null;
var photoGalleryType = null;
var pageNumber = 1;
var html = "";
var Citydata = "";
var Statedata = "";
var noResponses = 0;
var populateCityGallery = 0;
var populateStateGallery = 0;

function SiteLifeDisplay() {
	this.GetGalleries = function (photoContainerDivId, galleryType, letter) {
		photoContainerDiv = photoContainerDivId;
		photoGalleryType = galleryType;
		pageNumber = 1;
		noResponses = 0;
		html = "";
		// send gallery type (city/state), letter of city to get, page wanted, callback method, total to retrieve
		if (populateCityGallery == 0 || populateStateGallery == 0) {
			pgp.LoadPage(galleryType, letter, pageNumber, this.DrawGalleriesData, (totalCols * totalRows));
		} else {
			var sld = new SiteLifeDisplay();
			displayStoriesPhotoArray(photoGalleryType);
		}
	};
	this.DrawGalleriesData = function () {
		tools.DebugDir(pgp);
		var count = 0;
		if (populateCityGallery == 0 || populateStateGallery == 0) {
			while (count < pgp.GalleryArray.length && pgp.GalleryArray.length > 0) {
				if (photoGalleryType == 0) {
					Citydata = Citydata + pgp.GalleryArray[count].ImgSrc + "~" + pgp.GalleryArray[count].Title + "~" + pgp.GalleryArray[count].Permalink + "||";
				} else if (photoGalleryType == 1) {
					Statedata = Statedata + pgp.GalleryArray[count].ImgSrc + "~" + pgp.GalleryArray[count].Title + "~" + pgp.GalleryArray[count].Permalink + "||";
				}
				count++;
			}
			noResponses++;
		}
		if (noResponses == noRequest) {
			if (photoGalleryType == 0) {
				populateCityGallery = 1;
				displayStoriesPhotoArray(photoGalleryType);
			} else if (photoGalleryType == 1) {
				populateStateGallery = 1;
				displayStoriesPhotoArray(photoGalleryType);
			}
		}
	};
	this.FeaturedStories = function (containerDiv) {
		storyContainerDiv = containerDiv;
		fsp.LoadPage(this.DrawFeaturedStories);
	};
	this.DrawFeaturedStories = function () {
		// redefine out of scope
		var sld = new SiteLifeDisplay();
		tools.DebugDir(fsp);
		var container = document.getElementById(storyContainerDiv);
		var stories = fsp.Stories;
		var html = "<span class='featured_stories'>";
		for (var i = 0; i < stories.length; i++) {
			html += sld.DrawFeaturedStory(stories[i]);
		}
		html += "</span>";
		container.innerHTML = html;
	};
	this.DrawFeaturedStory = function (story) {
		var html = "<span class='featured_story'>";
		html += "<div class='featured_story_user'>";
		html += "<div class='featured_story_user_avatar'>";
		html += "<img src='" + story.Author.AvatarPhotoUrl + "' />";
		html += "</div>";
		html += "<div class='featured_story_user_info'>";
		html += story.Author.DisplayName + " wrote:";
		html += "<div class='featured_story_time'>";
		html += story.PostedAtTime;
		html += "</div>";
		html += "</div>";
		html += "</div>";
		html += "<div class='featured_story_body'>";
		html += story.CommentBody;
		html += "</div>";
		html += "</div>";
		return html;
	};
}
var slDisplay = new SiteLifeDisplay();
