var qu = String.fromCharCode(32);

function fillThumbs() {
	content = "";
	for (i=1; i<title.length; i++) {
		content += "<a href=" + qu + "javascript:fillInfo(" + i + ",1)" + qu + ">";
		content += "<img src='homes/";
		if (i<10) { content += "0" }
		content += i + "_t.jpg'";
		content += " width='100' height='100' border='0'></a>&nbsp;&nbsp;";
	}
	document.getElementById("thumbs").innerHTML = content;
	document.getElementById("thumbs").style.width = (hMax.length-1) * 110;
	if (getHouse()>0) { fillInfo(getHouse(),getPic()) }
}

function changeImg(value) {
	house = getHouse();
	hm = hMax[house];
	pic = getPic() + value;
	if (pic > hm) { pic = 1; }
	if (pic < 1) { pic = hm; }
	if (pic > 9) {
		i = "0" + pic.toString();
	} else {
		i = "00" + pic.toString();
	}
	if (house > 9) {
		house = house.toString();
	} else {
		house = "0" + house.toString();
	}
	document.getElementById("housePic").src = "homes/" + house + "_" + i + ".jpg";
	c = "homes=" + getHouse() + "h*" + pic.toString() + "h*";
	document.cookie = c;
}

function fillInfo(house,pic) {
	if (house > 0) {
		img = "homes/";
		if (house < 10) { img += "0" }
		img += house + "_0";
		if (pic < 10) { img += "0" }
		img += pic + ".jpg";
		content = "<br><b>" + title[house] + "</b><br><br>";
		content += descrip[house] + "<br><br>";
		content += "<i>" + hMax[house] + " images total</i></p>";
	} else {
		content = "";
	}
	document.getElementById("housePic").src = img;
	document.getElementById("homeInfo").innerHTML = content;
	c = "homes=" + house + "h*" + pic + "h*";
	document.cookie = c;
}

function getHouse() {
	c=document.cookie;
	if (c.lastIndexOf("homes") == -1) {	// homes cookie does not exist
		cook = "homes=0h*0h*";
		document.cookie = cook;
	}
	start = c.lastIndexOf("=") + 1;
	end = c.indexOf("h*");
	house = parseInt(c.slice(start,end),10);
	return house;
}

function getPic() {
	c=document.cookie;
	if (c.lastIndexOf("homes") == -1) {	// homes cookie does not exist
		cook = "homes=0h*0h*";
		document.cookie = cook;
	}
	start = c.indexOf("h*") + 2;
	end = c.lastIndexOf("h*");
	pic = parseInt(c.slice(start,end),10);
	return pic;
}