// Number of touts
ToutCount = 4;

// Set initial variables
toutLink = 1;

speed = 4000;
timer = "off";

ToutTitle = new Array(ToutCount);
ToutBy = new Array(ToutCount);
ToutImages = new MakeImageArray(ToutCount);
ToutLinks = new Array(ToutCount);
ToutSample = new Array(ToutCount);
ToutSampleType = new Array(ToutCount);
ToutSampleLink = new Array(ToutCount);

ToutTabs = new MakeImageArray(ToutCount);
TabLinks = new Array(ToutCount);

// This function loads the images once the rest of the page has loaded and starts the cycling function.
// When new images are put in, change the file names here

function kickstart() {
	
	document.getElementById("aha").innerHTML = toutLink + " of " + ToutCount;

	if (document.images)
	{
// This is the first tout.
// It retrieves it from the src attribute of the img tag.


// These are the preceeding links


		ToutTitle[1] = '<a href="http://librarypublishing.scholastic.com/webapp/wcs/stores/servlet/ProductDisplayView?storeId=10001&returnID=&returnURL=SearchView%3FlangId%3D-1%26storeId%3D10001%26searchTerm%3Dmain%2Bstreet&productId=24045">Main Street # 1: Welcome to Camden Falls</a>';
		ToutBy[1] = "<br>By Ann M. Martin ";
		ToutImages[1].src = "http://shop.scholastic.com/content/stores/media/products/93/0439868793_lg.jpg";
		ToutLinks[1] = "http://librarypublishing.scholastic.com/webapp/wcs/stores/servlet/ProductDisplayView?storeId=10001&returnID=&returnURL=SearchView%3FlangId%3D-1%26storeId%3D10001%26searchTerm%3Dmain%2Bstreet&productId=24045";
		ToutSampleType[1] = "";
		ToutSampleLink[1] = "";


		ToutTitle[2] = '<a href="http://catalog.lectorum.com/cgi-bin/detail.cgi?thums=Y&sku=20910">José</a><br>';
		ToutBy[2] = "by Georgina Lazaro Maria Sanchez";
		ToutImages[2].src = "/librarians/ab/images/may07/jose.jpg";
		ToutLinks[2] = "http://catalog.lectorum.com/cgi-bin/detail.cgi?thums=Y&sku=20910";
		ToutSampleType[2] = "/images/common/icon_sample_pages.gif";
		ToutSampleLink[2] = "<a href='/librarians/ab/popups/jose.htm' onclick='window.open(this.href,\"libPop\",\"width=536,height=580\"); return false;'>See a Sample Page</a>.";

		ToutTitle[3] = '<a href="http://librarypublishing.scholastic.com/webapp/wcs/stores/servlet/ProductDisplayView?storeId=10001&returnID=&returnURL=SearchView%3FlangId%3D-1%26storeId%3D10001%26searchTerm%3Dlet%2527s%2Bfind%2Bout&productId=22398">Lets Find Out™ Early Learning Books</a>';
		ToutBy[3] = "";
		ToutImages[3].src = "/librarians/ab/images/may07/LFO_MornNight_Sm.gif";
		ToutLinks[3] = "http://librarypublishing.scholastic.com/webapp/wcs/stores/servlet/ProductDisplayView?storeId=10001&returnID=&returnURL=SearchView%3FlangId%3D-1%26storeId%3D10001%26searchTerm%3Dlet%2527s%2Bfind%2Bout&productId=22398";
		ToutSampleType[3] = "/images/common/icon_sample_pages.gif";
		ToutSampleLink[3] = "<a href='/librarians/ab/popups/lfo_opposites.htm' onClick='window.open(this.href,\"books\",\"width=536,height=450,scrollbars=yes\");return false;'>See a Sample Page</a>.";



		ToutTitle[4] = '<a href="http://teacher.scholastic.com/products/westonwoods/catalog/product.asp?cid=686&fid=22">Diary of a Spider</a>';
		ToutBy[4] = "<br>By Leo Lionni";
		ToutImages[4].src = "http://teacher.scholastic.com/products/westonwoods/images/coverimages_xsm/DiaryofaSpider_vi_xsm.gif";
		ToutLinks[4] = "http://teacher.scholastic.com/products/westonwoods/catalog/product.asp?cid=686&fid=22";
		ToutSampleType[4] = "/images/common/icon_play_audio_vidio.gif";
		
		ToutSampleLink[4] = "<a href='#' onClick=G_pop('http://teacher.scholastic.com/products/westonwoods/videopop.asp?lang=english&Size=L&cid=686','video','width=330,height=360')>See a Video Clip</a>.";



	} //end if document.images
	document.images["toutImage"].src = ToutImages[1].src;

	output = createTitle(ToutTitle[1], ToutLinks[1]);
	output += createTitle(ToutBy[1], '');
	output += createSample(ToutSampleType[1], ToutSampleLink[1]);
	document.getElementById("toutText").innerHTML = output;

} // end function kickstart


function MakeImageArray(n) {
	this.length = n;
	if (document.images)
	{
		for (var i = 1; i<=n; i++) {
			this[i] = new Image();
		}
	}
	return this;
}

function getNextTout() {

  if (document.images){
		toutNext = toutLink + 1;
		if (toutNext > ToutCount)
		{
			toutNext = 1;
		}
		toutLink = toutNext;
		
		output = createTitle(ToutTitle[toutNext], ToutLinks[toutNext]);
		output += createTitle(ToutBy[toutNext], '');
		output += createSample(ToutSampleType[toutNext], ToutSampleLink[toutNext]);
		document.getElementById("toutText").innerHTML = output;
	
	//	document.getElementById("toutText").innerHTML = ToutTitle[toutNext];
		document.images["toutImage"].src = ToutImages[toutNext].src;
		document.getElementById("aha").innerHTML = toutLink + " of " + ToutCount;
  }
  return false;
}
function getPrevTout() {

  if (document.images){
		toutPrev = toutLink - 1;
		if (toutPrev < 1)
		{
			toutPrev = ToutCount;
		}
		toutLink = toutPrev;
		
		output = createTitle(ToutTitle[toutPrev], ToutLinks[toutPrev]);
		output += createTitle(ToutBy[toutPrev], '');
		output += createSample(ToutSampleType[toutPrev], ToutSampleLink[toutPrev]);
		document.getElementById("toutText").innerHTML = output;
	
	//	document.getElementById("toutText").innerHTML = ToutTitle[toutPrev];
		document.images["toutImage"].src = ToutImages[toutPrev].src;
		document.getElementById("aha").innerHTML = toutLink + " of " + ToutCount;
  }
  return false;
}

function getToutLink() {

 if (toutLink == 1)
 {
	window.location.href=ToutLinks[toutLink];
	return false;
 }

 else if (toutLink == 2 )
 {
	 window.location.href=ToutLinks[toutLink];
	//window.open(ToutLinks[toutLink],'video2','width=536,height=425');
 }
  else if ( toutLink==3)
 {
	 window.location.href=ToutLinks[toutLink];
//	window.open(ToutLinks[toutLink],'video2','width=242,height=370');
 }
 else if (toutLink == 4)
 {
	 window.location.href=ToutLinks[toutLink];
 }
 else {
	window.open(ToutLinks[toutLink]);
 }
}

function createTitle(text, link) {
	if (link != "")
		return ("<a href=" + link + ">" + text + "</a>");
	else
		return text;
}

function createSample(type, link) {
	if (link != "")
		return ("<br><br><img src=" + type + " align=left border=0>" + link);
	else
		return "";
}

kickstart();