var imgdir = "http://c.ancestry.com/offer/fhp/";
var posn = 0;
var thumbct = 3;
var	prefix = "projimg";

function Project(name,time,desc,lnk,pdflnk){
	this.name = name;
	this.time = time;	
	this.desc = desc;
	this.lnk = lnk;	
	this.pdflnk = pdflnk;		
}

var timeimages = new Array();
timeimages[0] = new Array("time_30mins.gif","Less than 30 minutes");
timeimages[1] = new Array("time_1hour.gif","Less than 1 hour");
timeimages[2] = new Array("time_1day.gif","Less than 1 day");
timeimages[3] = new Array("time_1week.gif","Less than 1 week");
timeimages[4] = new Array("time_30days.gif","Less than 30 days");
timeimages[5] = new Array("time_1weekend.gif","in a weekend");

var timeimagecache = new Array();

for (i = 0; i < timeimages.length; i++) {
	timeimagecache[i] = new Image();
	timeimagecache[i].src = imgdir + timeimages[i][0];
}

var itemimages = new Array();
itemimages[0] = new Array('historybook_img1.jpg','historybook_img2.jpg','historybook_img3.jpg');
itemimages[1] = new Array('recipebook_img1.jpg','recipebook_img2.jpg');
itemimages[2] = new Array('ptemplates_img1.jpg','ptemplates_img2.jpg','ptemplates_img3.jpg','ptemplates_img4.jpg');
itemimages[3] = new Array('poster-img1.jpg');
itemimages[4] = new Array('photobook_img1.jpg','photobook_img2.jpg');
//itemimages[5] = new Array('historycalendar_img1.jpg','historycalendar_img2.jpg');
//itemimages[6] = new Array('shirt_img1.jpg','shirt_img2.jpg');
//itemimages[7] = new Array('greetingcards_img1.jpg','greetingcards_img2.jpg');
//itemimages[8] = new Array('recordedstories_img1.jpg','recordedstories_img2.jpg','recordedstories_img3.jpg');

var itemthumbs = new Array();
itemthumbs[0] = new Array('historybook_tmb1.jpg','historybook_tmb2.jpg','historybook_tmb3.jpg');
itemthumbs[1] = new Array('recipebook_tmb1.jpg','recipebook_tmb2.jpg');
itemthumbs[2] = new Array('ptemplates_tmb1.jpg','ptemplates_tmb2.jpg','ptemplates_tmb3.jpg','ptemplates_tmb4.jpg');
itemthumbs[3] = new Array('poster-tmb1.jpg');
itemthumbs[4] = new Array('photobook_tmb1.jpg','photobook_tmb2.jpg');
//itemthumbs[5] = new Array('historycalendar_tmb1.jpg','historycalendar_tmb2.jpg');
//itemthumbs[6] = new Array('shirt_tmb1.jpg','shirt_tmb2.jpg');
//itemthumbs[7] = new Array('greetingcards_tmb1.jpg','greetingcards_tmb2.jpg');
//itemthumbs[8] = new Array('recordedstories_tmb1.jpg','recordedstories_tmb2.jpg','recordedstories_tmb3.jpg');

var projects = new Array();
projects[0] = new Project("Family History Book",5,"Chronicle memorable details about multiple generations of your family in a precious heirloom-quality book you can share with all your relatives.","products.aspx?html=fhbook","http://c.ancestry.com/offer/fhp/pdf/famhist_book.pdf");
projects[1] = new Project("Family Recipe Book",5,"Mom's chocolate cookies. Grandpa's barbecue sauce. Your aunt's mashed potatoes. Capture your favorite family recipes for all time in this beautiful book.","products.aspx?html=frbook","http://c.ancestry.com/offer/fhp/pdf/FamRecip_book.pdf");
projects[2] = new Project("Portrait Templates",0,"Choose the perfect themed backgrounds for your family photos and historical records. Then add comments that tell the story of everyone featured.","products.aspx?html=port","http://c.ancestry.com/offer/fhp/pdf/famhist_portrait.pdf");
projects[3] = new Project("Family History Poster",0,"Show friends and family all you've discovered about your roots with a poster-sized family tree you can easily frame and display in any room.","products.aspx?html=poster","http://c.ancestry.com/offer/fhp/pdf/family-history-poster.pdf");
projects[4] = new Project("Family Photo Book",3,"Hold on to memories from your favorite vacation and your sister's wedding or preserve images from generations past in a custom scrapbook.","products.aspx?html=photo","http://c.ancestry.com/offer/fhp/pdf/Photo_book.pdf");
//projects[5] = new Project("Family History Calendar",1,"Upload historical images and family photos for each month to create a custom wall calendar that tells a little more of your family story every day.","products.aspx?html=fhcal","http://c.ancestry.com/offer/fhp/pdf/famhist_calendar.pdf");
//projects[6] = new Project("Hoodie/T-shirt",0,"Wear your family history proudly on your shirt. Display fun family photos or memorialize ancestors in your choice of styles.","products.aspx?html=shirts","http://c.ancestry.com/offer/fhp/pdf/hoodie_shirt.pdf");
//projects[7] = new Project("Greeting Cards",0,"Create birthday cards, invitations and other cards featuring your treasured memories on the front and your personalized words inside.","products.aspx?html=cards","http://c.ancestry.com/offer/fhp/pdf/greetcard.pdf");
//projects[8] = new Project("Recorded Stories",2,"Record your grandfather telling war stories, your child's first words or your mom's version of the day you learned to ride a bike — online or by phone using the Ancestry Storytelling Service. Then save your audio file and share it with family.","recorded_stories.html","pdf/");

function pselect(idx) {
	document.getElementById("b"+posn).style.backgroundColor = "#fcfbf3";
	document.getElementById("b"+idx).style.backgroundColor = "#d0ccc0";
	document.getElementById("pttl").childNodes[0].nodeValue = projects[idx].name;
	document.getElementById("pdesc").childNodes[0].nodeValue = projects[idx].desc;
	document.getElementById("morelink").setAttribute("href",projects[idx].lnk);
	document.getElementById("btnlink").setAttribute("href",projects[idx].lnk);
	document.getElementById("pdflink").setAttribute("href",projects[idx].pdflnk);
	document.getElementById("projtime").src = timeimagecache[projects[idx].time].src;
	document.getElementById("projtime").setAttribute("alt",timeimages[projects[idx].time][1]);	
	posn = idx;
	imagejuicer(idx)
}

function slatewiper() {
	for(i = 1; i <= thumbct; i++){
		imgid = prefix + (i + 1);
		timg = document.getElementById(imgid);
		timg.style.backgroundImage = "none";
	}
}

function imagejuicer(idx){
	slatewiper();
	imgct = itemimages[idx].length;
	document.getElementById("projimg1").style.backgroundImage = "url(" + imgdir + itemimages[idx][0] + ")";
	if(imgct > 1) {
		for(i = 2; i <= imgct; i++){
			imgid = prefix + i;
			timg = document.getElementById(imgid);
			timg.style.backgroundImage = "url(" + imgdir + itemthumbs[idx][i - 1] + ")";
		}
	} 
}

function thumbjuicer(flg){
	if(itemimages[posn].length > 1){
		imgid = prefix + flg;
		mimg = document.getElementById("projimg1").style.backgroundImage;
		timg = document.getElementById(imgid).style.backgroundImage;	
		var mval;
		var tval;
		for(i = 1; i <= thumbct + 1; i++){
			if(mimg.indexOf(i) != -1) {mval = i;}
			if(timg.indexOf(i) != -1) {tval = i;}		
		}
		document.getElementById("projimg1").style.backgroundImage = "url(" + imgdir + itemimages[posn][tval - 1] + ")";
		document.getElementById(imgid).style.backgroundImage  = "url(" + imgdir + itemthumbs[posn][mval -1] + ")"; 
	}
}

function advancer(direction) {
	if(direction == "down"){
		if(posn == 0){
			pselect(projects.length - 1);
		} else {
			pselect(posn - 1)
		}
	} else {
		if(posn == projects.length - 1){
			pselect(0);
		} else {
			pselect(posn + 1)
		}
	}
}

pselect(0);

playon = setInterval("advancer('up')", 5000);
var interrupt = document.getElementById("pbar");
var interrupt2 = document.getElementById("imgbox");
function stopauto() {if(playon){clearInterval(playon);}}   
YAHOO.util.Event.addListener(interrupt, "click", stopauto);
YAHOO.util.Event.addListener(interrupt2, "click", stopauto);