<!--

function onPageLoaded() { 
/*
	var userNum = sbCookieData.usernum;
	StoriesAccess.getAllAuthorsAndTitles(userNum, authorsTitlesCallback);
*/
	setupAds("reading.exercise");
}

var authorsTitlesCallback = function(data)
{
	var authorsWithTitles = data.authorsWithTitles;

	var alist_content = "";
	var userNum = sbCookieData.usernum;
		// runs through authors:
	for (var j=0; j<authorsWithTitles.length; j++)
	{
	
		var authorLN = authorsWithTitles[j].authorLN;
		var authorFN = authorsWithTitles[j].authorFN;
		var stories = authorsWithTitles[j].authorStories;
		
		alist_content += '&nbsp;<p><h5>'+authorLN+', '+authorFN+'</h5>';
	
		for (k=0; k< stories.length; k++)
		{
			var storyName = stories[k].title;
			var storyNum = stories[k].storyNum;
			var fn = stories[k].filename;
	//		var userHasRead = stories[j].userHasRead;
				// hack until db fixed:
			var fnparts = fn.split(".");
			if (fnparts.length > 1){
				fn = fnparts[0];
			}
			var reflbl = "";
	//		if (userHasRead){ reflbl += acceptGreenHTML; }	
	
			reflbl += '<a href="#" onclick="chooseToRead(\'/Reading/Texts/' + fn +'\','+ userNum+','+storyNum
									+');">'  + storyName + '</a><br>';			
			alist_content += reflbl;
		}
		
		
		
	}
	var list_containerdiv = document.getElementById("list_container");
	list_containerdiv.innerHTML=alist_content;
	
//	StoriesAccess.getAuthorAds(theAuthorNum, authorAdsCallback);
	setupAds("reading.exercise");
}

function chooseToRead(storyPath, userNum, storyNum)
{
//	alert("chooseToRead: "+storyPath+"  --"+ userNum+" - "+storyNum);
	window.location=storyPath;
	StoriesAccess.recordReading(userNum, storyNum, recordReadingCallback);
}
var recordReadingCallback = function(data) { }

var authorAdsCallback = function(data){	
	
	var ads = data;
	var left_ads_region = document.getElementById("amazon_items");
	var ad_content = "";
	for (var i=0; i<ads.length; i++){
		ad_content += "<div class=\"amazon_pick\"/>" + ads[i] + "</div>" + "<br>";
	}
	left_ads_region.innerHTML=ad_content;
}

// -->
